0xDiablos
hackthebox
Task: Exploit a 32-bit binary with gets() buffer overflow to call a flag-printing function with correct parameters. Solution: Overflow 188 bytes to overwrite EIP with the flag() function address, place magic values 0xdeadbeef and 0xc0ded00d on the stack as cdecl arguments after a fake return address.
$ ls tags/ techniques/
$ cat /etc/rate-limit
Rate limit reached (20 reads/hour per IP). Showing preview only — full content returns at the next hour roll-over.
0xDiablos — HackTheBox
Description
A classic binary exploitation challenge where you are given a 32-bit ELF binary called "vuln" and a remote target to exploit. The binary has a buffer overflow vulnerability that must be exploited to call a hidden flag-printing function with the correct magic parameters.
Binary Analysis
File: ELF 32-bit, dynamically linked, not stripped
Security:
- No PIE (base 0x8048000 — fixed addresses)
- No stack canary
- NX disabled (executable stack)
- Partial RELRO
- RWX segments present
Key functions (via objdump):
vuln()at0x08049272— containsgets()call (buffer overflow)flag()at0x080491e2— reads and prints flag.txt, but requires correct parameters
Vulnerability
vuln()allocates a buffer atebp - 0xb8(184 bytes)- Calls
gets()on this buffer — unbounded read, classic stack buffer overflow - No stack canary to prevent overwrite
flag(param1, param2) function logic:
- Opens "flag.txt" with
fopen() - Reads contents with
fgets()(64 bytes) - Checks if
param1 == 0xdeadbeefANDparam2 == 0xc0ded00d - Only if BOTH checks pass, calls
printf()to print the flag - If either check fails, returns silently without printing
Buffer overflow math:
- Buffer size: 184 bytes (
ebp - 0xb8) - Saved EBP: 4 bytes
- Offset to EIP (return address): 184 + 4 = 188 bytes
Exploitation Strategy
- Overflow the buffer in
vuln()to overwrite the saved return address (EIP) - Redirect execution to
flag()function - Since this is a 32-bit binary using cdecl calling convention, function arguments are passed on the stack after the return address
- Place the two magic values (
0xdeadbeef,0xc0ded00d) at the correct stack positions
Payload layout (32-bit cdecl):
[188 bytes padding] [flag() addr] [fake return] [param1] [param2]
'A' * 188 0x080491e2 'BBBB' 0xdeadbeef 0xc0ded00d
...
$ grep --similar
Similar writeups
- [pwn][free]Getting Started— hackthebox
- [pwn][free]Void— hackthebox
- [pwn][Pro]login— volgactf
- [pwn][free]Labyrinth— HackTheBox
- [pwn][Pro]Easy ROP— hackerlab