How we use Dirty Pipe to get reverse root shell on Android Emulator and Pixel 6

中文In-PersonMalware

time

01:10 ~ 01:55

site

R1

In February this year, a vulnerability named Dirty Pipe was revealed for Linux kernel 5.8+, which allows arbitrary writing of read-only files. On Android, Google Pixel 6 and SAMSUNG Galaxy S22 all used a version of Android 12 that can trigger the vulnerability. We tried to use this vulnerability to escalate privileges on Android 12 by using Android Emulator x86_64 as the initial environment before porting it to Google Pixel 6.

Privilege escalation using Dirty Pipe is relatively easy in general Linux environments. An attacker can escalate privileges by modifying the binary with the suid flag, or by writing to /etc/shadow. However, neither of them exists in the Android environment. In addition, Android enables SELinux by default, restricting users to only perform operations permitted by the policy. We try to find another path that can bypass SELinux while gaining root privileges.

Read-only files do not exhibit CoW behavior when it is maliciously written, so as long as we are writing into a read-only file that has already been mmaped by the process, we will be directly modifying the corresponding memory. Utilizing this feature, we use Dirty Pipe to overwrite the read-only file used by init to hijack init and obtain root and init context for subsequent attacks.

SELinux has very powerful permission management, but making permissions too strict will get in the way during development, hence some backdoors were intentionally left for developers. This also allows attackers to bypass SELinux more easily, but it still requires loading kernel modules.

SELinux has a special rule transition that can change a process’ context during execve, while init can transition to the context with module_load permission, open and read the corresponding executable and loadable files. Kernel modules can thus be loaded through Dirty Pipe.

In this talk, we will describe how we found a way to hijack the init process, loading a kernel module despite Dirty Pipe’s inability to write the first byte of the page, bypassing the SELinux protection mechanism, and finally, how we managed to successfully get the reverse root shell on the mobile phone.

YingMuo

YingMuo

TeamT5 D39 Vulnerability Researcher (Intern) who has recently started researching Android and Linux Kernel vulnerabilities. They are also a new member of the Balsn CTF team.
LiN

LiN

TeamT5 D39 Vulnerability Researcher (Intern) who has recently started researching Android and Linux Kernel vulnerabilities.

English interpretations will be provided for all sessions not presented in English.

Agenda Table

Use event local timezone
TimeZone

00:30

  • Attendant Registration Time

01:20

  • Welcome Speech & Event Introduce

02:10

03:00

  • Break

03:15

04:05

  • Lunch

05:00

05:45

  • Break

06:00

06:45

  • Tea Time

07:00

07:25

08:10

  • Break

08:25

09:10

  • Closing

09:25