
CVE-2022-0847(Dirty Pipe) vulnerability exploits.
Disclosed on March 7, 2022 by Max Kellerman[2], CVE-2022-0847 is a vulnerability in the Linux kernel (versions 5.8 to 5.16.11) that allows attackers to overwrite read-only or immutable files and escalate their privileges on the victim's system. CVE-2022-0847 was nicknamed Dirty Pipe and has a CVSS score of 7.8 (considered high).
The Dirty Pipe vulnerability is described as a flaw in the way the flags attribute of the struct pipe_buffer[7] did not have proper initialization in the copy_page_to_iter_pipe and push_pipe functions in the Linux kernel and thus could contain stale values. One of the flags that can be set in the flags attribute of struct pipe_buffer is the flag called PIPE_BUF_FLAG_CAN_MERGE. It indicates whether merging more data into the pipe_buffer is allowed or not. Thus, when data is copied to a pipe_buffer, more data can be added to the pipe_buffer if the copied page is less than 4096 bytes in size.
By injecting PIPE_BUF_FLAG_CAN_MERGE into a page cache reference, it became possible to overwrite data in the page cache simply by writing new data to a specially prepared pipe (this process will be described in the following paragraphs). Thus, an unprivileged local user can use this flaw to overwrite/write to pages in the page cache backed by read-only files and thus escalate their privileges on the system.
That said, to exploit the vulnerability, the following steps must be followed:
Compile everything with the following command:
make
./exploit-1
Exploit 1, present in the file exploit-1.c of the repository, consists of overwriting the root user's password present in the file /etc/passwd (this file contains user account information, such as the encrypted password) and finally providing a terminal with root access. To do so, it was necessary to:
/etc/passwd file./etc/passwd file to the pipe and overwrite the contents of this file with a new known root password (as presented in steps 4 and 5 above).find / -perm -4000 2>/dev/null
./exploit-2 <path-of-suid-binary>
Exploit 2, present in the file exploit-2.c of the repository, consists of overwriting/hijacking a SUID binary (this type of attack was reported in section 3.5.2) and finally providing a terminal with root access. To do so, it was necessary to:
/tmp/sh), which in turn creates a shell terminal with root access./tmp/sh mentioned in step 1 is executed, thus opening a new shell with root access../exploit-3
Exploit 3, present in the file exploit-3.c of the repository, uses the same steps as exploit 1 to obtain root shell access. The difference is that exploit 3, after gaining root shell access, loads an attacker's SSH (Secure Shell) public key into the file /root/.ssh/authorized_keys and creates a TCP (Transmission Control Protocol) tunnel for remote SSH access using the Ngrok platform.
[1] AHMED, Alexis. Privilege Escalation Techniques: Learn the art of exploiting Windows and Linux systems. Birmingham: Packt Publishing, October 2021.
[2] KELLERMANN, Max. The Dirty Pipe Vulnerability. Available at: https://dirtypipe.cm4all.com/. Accessed on: July 23, 2022.
[3] Exploit Database. Available at: https://www.exploit-db.com/. Accessed on: August 3, 2022.
[4] Traitor: Automatically exploit low-hanging fruit to pop a root shell. Available at: https://github.com/liamg/traitor. Accessed on: August 3, 2022.
[5] PayloadsAllTheThings. Linux - Privilege Escalation. Available at: https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Linux%20-%20Privilege%20Escalation.md#cve-2022-0847-dirtypipe. Accessed on: August 3, 2022.
[6] Linux Kernel Repository - Struct pipe_inode_info. Available at: https://github.com/torvalds/linux/blob/v5.8/include/linux/pipe_fs_i.h#L76. Accessed on: August 3, 2022.
[7] Linux Kernel Repository - Struct pipe_buffer. Available at: https://github.com/torvalds/linux/blob/v5.8/include/linux/pipe_fs_i.h#L26-L32. Accessed on: August 3, 2022.
[8] ARNTZ, Pieter. Linux "Dirty Pipe" vulnerability gives unprivileged users root access. Malwarebytes Lab. Available at: https://www.malwarebytes.com/blog/news/2022/03/linux-dirty-pipe-vulnerability-gives-unprivileged-users-root-access. Accessed on: August 3, 2022.
[9] Picus Security. Linux “Dirty Pipe” CVE-2022-0847 Vulnerability Exploitation Explained. Available at: https://www.picussecurity.com/resource/linux-dirty-pipe-cve-2022-0847-vulnerability-exploitation-explained. Accessed on: August 3, 2022.
[10] Exploit Database - Local Privilege Escalation (Dirty Pipe). Available at: https://www.exploit-db.com/exploits/50808. Accessed on: August 3, 2022.