The Challenge
secureadminpanel is an x86-64 ELF. checksec confirms: NX enabled, stack canary present, no PIE. The binary presents a menu:
- Option 1: store your name (reads into a buffer)
- Option 2: print a “Regalino” — this leaks the stack canary as a hex value
- Option 3: read another input into a buffer with a classic stack overflow
The win function lives at 0x401276.
Approach
First thing was checksec: canary is there, NX on, no PIE. The canary means I can’t just overflow blindly — the stack check will kill the process before it ever returns to my payload.
I went straight to option 3 and tried a basic overflow to see what happened: segfault, then *** stack smashing detected ***. Canary triggered. So the canary has to come first.
I looked at all three menu options more carefully. Option 1 takes a name. Option 2 prints a “Regalino” value. I tested option 2 without setting any name first — it printed something that looked like a hex number, 0xf1234567890abcde or similar. I set a name with option 1 (padding to reach the canary position) and called option 2 again — this time it printed the actual canary. The binary is literally leaking it through the Regalino feature.
With the canary in hand, the overflow in option 3 is straightforward: 24 bytes of junk to reach the canary position, then the canary itself, then 8 bytes for saved RBP, then the win function address 0x401276.
Solution
|
|
The 24 byte offset and the exact position of the canary in the payload depend on the specific stack frame layout, which I confirmed by examining the disassembly of the vulnerable function. The win function at 0x401276 prints the flag or spawns a shell — either way, interactive() catches it.
What I Learned
A canary leak doesn’t require a format string bug or memory corruption — here the binary literally prints it for you (framed as a feature). Once you have the canary value, the overflow is textbook: pad to the canary, preserve it, overwrite the return address. No PIE means the win address never changes.