$ cat writeup.md…
$ cat writeup.md…
sunshinectf2026
Task: stripped PIE amd64 binary prints an fgets'd buffer directly as a printf format string across 8 loop rounds (classic format-string bug), with canary, NX, PIE and Partial RELRO. Solution: leak canary/libc/PIE in round 1 via %N$p, then use %hn halfword writes across later rounds to plant a ret2libc ROP chain over main's saved return address; canary stays intact so main returns cleanly into system("/bin/sh").
$ cat /etc/rate-limit
Rate limit reached (20 reads/hour per IP). Showing preview only — full content returns at the next hour roll-over.
=== Mad Libs === Fill in the blanks!
English summary: A "mad libs" prompt asks the user to fill in blanks eight times. Each entry is echoed back, but the program reflects the user string through printf without a format specifier, giving a classic format-string primitive that is used 8 times per connection. Goal: get a shell on the remote and read the flag (sun{...}).
Provided files: mad_libs (ELF64, PIE, amd64, stripped), libc.so.6 (Ubuntu GLIBC 2.39-0ubuntu8.3), and ld-linux-x86-64.so.2. RUNPATH is $ORIGIN.
Protections:
There is no win()/system() in the binary, so exploitation must pivot into the supplied libc 2.39.
main (@ 0x11c9) runs an 8-iteration loop:
puts("=== Mad Libs ==="); puts("Fill in the blanks!"); for (int i = 0; i < 8; i++) { printf("(%d) > ", i + 1); if (fgets(buf /* [rbp-0x110] */, 0x100, stdin) == NULL) break; printf(buf); // <-- FORMAT STRING BUG: user buffer as format string } puts("Story complete!"); return; // canary checked, then leave; ret
Frame layout: buf at rbp-0x110, canary at rbp-0x8, frame size 0x120. The user string reaches printf directly as the format argument — a textbook format-string vulnerability, repeated for up to 8 rounds. Because the canary is never corrupted, main can be allowed to return cleanly, so we simply overwrite main's saved return address and let it ret into a ROP chain.
Offsets were pinned locally by running the binary under the provided loader inside an Ubuntu 24.04 (glibc 2.39) docker container:
...
$ grep --similar