The idea
Rune has a signed engagement against Cresswell Telecom and a foothold on a provisioning host as the service
account rune. On the box is a small service binary, /opt/challenge/leak-vuln, that greets you by name. The
bug is in how it builds the greeting: it passes your name straight to printf as the format string —
printf(name) instead of printf("%s", name).
That is a format-string bug. printf acts on whatever conversion specifiers the string
contains, reading its arguments off the stack: %p prints a stack word, %s treats a stack word as an address
and prints the string there, and %7$p jumps straight to the seventh word. The binary is setuid root and holds
a secret it read from a root-only file — a file rune cannot read with cat. You will walk the stack with
%p, find where the secret sits, and read it back out with %s. No crash, no code — only reading memory the
program never meant to show you.
Steps
-
The foothold and a door you cannot open
You are on Rune's Kali box. The foothold is an SSH login on the provisioning host at
10.0.1.20as the service accountrune. Click Start to open a shell there, confirm who you are withid, and try to read the secret file/opt/challenge/token.txtdirectly. It is owned by root and closed to you — that is the door the format-string bug will open from the inside.kali:~# ssh box
-
A greeting that trusts your name
Run the portal the way it expects — give it a name, and it answers
Welcome, <name>. Now give it a name made of conversion specifiers instead:%p %p %p. If the program were printing your name safely it would echo%p %p %pback verbatim. Instead it prints addresses — proof that your input is being used as the format string, and thatprintfis reading words off the stack for each%p.kali:~# ssh box 'printf "%%p %%p %%p %%p %%p %%p\n" | /opt/challenge/leak-vuln'
-
Walk the stack to the secret
You do not have to count
%ps by hand.%N$pjumps straight to the Nth stack word —%7$pis the seventh — so you can probe positions directly. The setuid binary loaded the root-only secret into memory before greeting you, and a pointer to it sits on the stack. Probe positions with%N$puntil one holds a pointer into that secret; here it is position 15. (You can confirm the layout ingdbwithprocessTracingon, but the%N$pwalk finds it without one.)kali:~# ssh box 'for n in 13 14 15 16; do printf "slot %s: " "$n"; printf "%%$n\$p\n" | /opt/challenge/leak-vuln | sed "s/.*Welcome, //"; done'
-
Read the secret with %s
%pprinted the pointer;%sfollows it. Send%15$sandprintftakes the word at position 15 as an address and prints the string there — the root-only secret the setuid process is holding. You read a filerunewas refused, without ever touching the file: you read it out of the privileged process's memory through the format-string bug.kali:~# ssh box 'printf "%%15\$s\n" | /opt/challenge/leak-vuln'
-
What Cresswell's developers should change
Rune's finding is one line of code: untrusted input was used as a format string. The fixes:
- Never let input be the format.
printf("%s", name)instead ofprintf(name). The name is then only ever data, and%p/%sin it are printed as the literal text they are. This one change closes the bug. - Turn on the compiler's warnings.
-Wformat -Wformat-securityflagsprintf(name)at build time, and_FORTIFY_SOURCEaborts some format-string misuse at runtime. They exist precisely to catch this class. - Remember why a read matters. Even when a leak reveals "nothing useful", it often reveals an address — and one real address defeats ASLR, turning an unpredictable overflow target into a known one. A disclosure is routinely the first half of a larger exploit, which is why it is worth finding on its own.
One honest line: running any of this against a system whose owner has not authorised you in writing is unauthorised access, an offence under laws like the UK Computer Misuse Act and the United States' CFAA. Rune has a signed engagement; that permission is the only thing separating this from a crime.
kali:~# ssh box 'ls -l /opt/challenge/leak-vuln /opt/challenge/token.txt'
- Never let input be the format.
Run these steps on real machines