由 Max Kellerman[2] 于 2022 年 3 月 7 日披露的 CVE-2022-0847 是 Linux 内核(5.8 至 5.16.11 版本之间)中的一个漏洞,它允许攻击者覆盖只读或不可变文件,并在受害者系统上提升其权限。CVE-2022-0847 被命名为 Dirty Pipe,其 CVSS 评分为 7.8(被认为是高危险)。
Dirty Pipe 漏洞被描述为 Linux 内核中 copy_page_to_iter_pipe 和 push_pipe 函数对 struct pipe_buffer[7] 的 flags 属性缺乏正确初始化,因此可能包含过时值。struct pipe_buffer 的 flags 属性中可设置的标志之一名为 PIPE_BUF_FLAG_CAN_MERGE。它表示是否允许将更多数据合并到 pipe_buffer 中。这样,当数据被复制到 pipe_buffer 时,如果被复制的页面小于 4096 字节,则可以向 pipe_buffer 添加更多数据。
通过将 PIPE_BUF_FLAG_CAN_MERGE 注入页缓存引用,就可以仅通过向特殊准备的 pipe 写入新数据来覆盖页缓存中的数据(该过程将在以下段落中描述)。这样一来,没有特权的本地用户可以利用此漏洞覆盖/写入由只读文件支持的页缓存中的页面,从而提升其在系统上的权限。
话虽如此,要利用此漏洞,必须遵循以下步骤:
使用以下命令编译所有内容:
make
./exploit-1
仓库中 exploit-1.c 文件中的漏洞利用 1 包括覆盖 /etc/passwd 文件中 root 用户的密码(该文件包含用户账户信息,例如加密后的密码),并最终提供一个具有 root 访问权限的终端。为此,需要:
/etc/passwd 文件进行备份。/etc/passwd 文件传输到 pipe,并用一个新的已知 root 密码覆盖该文件的内容(如上文步骤 4 和 5 所示)。find / -perm -4000 2>/dev/null
./exploit-2 <path-of-suid-binary>
仓库中 exploit-2.c 文件中的漏洞利用 2 包括覆盖/劫持一个 SUID 二进制文件(此类攻击已在 3.5.2 节中介绍),并最终提供一个具有 root 访问权限的终端。为此,需要:
/tmp/sh),该文件反过来会创建一个具有 root 访问权限的 shell 终端。/tmp/sh 可执行文件,从而打开一个具有 root 访问权限的新 shell。./exploit-3
仓库中 exploit-3.c 文件中的漏洞利用 3 使用与漏洞利用 1 相同的步骤来获得 root shell 访问权限。区别在于,漏洞利用 3 在获得 root shell 访问权限后,会将攻击者的 SSH(Secure Shell)公钥加载到 /root/.ssh/authorized_keys 文件中,并使用 Ngrok 平台创建用于远程 SSH 访问的 TCP(Transmission Control Protocol)隧道。
[1] AHMED, Alexis. Privilege Escalation Techniques: Learn the art of exploiting Windows and Linux systems. Birmingham: Packt Publishing, 2021年10月.
[2] KELLERMANN, Max. The Dirty Pipe Vulnerability. 可访问于:https://dirtypipe.cm4all.com/。访问日期:2022年7月23日。
[3] Exploit Database. 可访问于:https://www.exploit-db.com/。访问日期:2022年8月3日。
[4] Traitor: Automatically exploit low-hanging fruit to pop a root shell. 可访问于:https://github.com/liamg/traitor。访问日期:2022年8月3日。
[5] PayloadsAllTheThings. Linux - Privilege Escalation. 可访问于:https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Linux%20-%20Privilege%20Escalation.md#cve-2022-0847-dirtypipe。访问日期:2022年8月3日。
[6] Linux 内核存储库 - Struct pipe_inode_info. 可访问于:https://github.com/torvalds/linux/blob/v5.8/include/linux/pipe_fs_i.h#L76。访问日期:2022年8月3日。
[7] Linux 内核存储库 - Struct pipe_buffer. 可访问于:https://github.com/torvalds/linux/blob/v5.8/include/linux/pipe_fs_i.h#L26-L32。访问日期:2022年8月3日。
[8] ARNTZ, Pieter. Linux "Dirty Pipe" vulnerability gives unprivileged users root access. Malwarebytes Lab. 可访问于:https://www.malwarebytes.com/blog/news/2022/03/linux-dirty-pipe-vulnerability-gives-unprivileged-users-root-access。访问日期:2022年8月3日。
[9] Picus Security. Linux “Dirty Pipe” CVE-2022-0847 Vulnerability Exploitation Explained. 可访问于:https://www.picussecurity.com/resource/linux-dirty-pipe-cve-2022-0847-vulnerability-exploitation-explained。访问日期:2022年8月3日。
[10] Exploit Database - Local Privilege Escalation (Dirty Pipe). 可访问于:https://www.exploit-db.com/exploits/50808。访问日期:2022年8月3日。