Buffer overflow offset finder
Find the exact number of bytes before the saved return address using a de Bruijn pattern and the value from a single crash.
Open in ctfpalThe offset is the first unknown in any stack overflow: how many bytes of input sit between the start of the buffer and the saved return address. Guessing it by incrementing a counter takes dozens of runs; a de Bruijn pattern takes one.
Why one crash is enough
In a de Bruijn sequence every substring of the given length occurs exactly once. So whatever four or eight bytes land in the instruction pointer, their position in the sequence is unambiguous - and that position is the offset. See the pattern generator for the mechanics.
The offset is not the buffer size
It is the buffer size plus any other locals the compiler placed after it, plus the saved frame pointer, plus alignment padding. That is why reading char buf[64] in the source and assuming 64 is wrong often enough to waste an afternoon - the compiler’s layout is the truth, and the pattern measures it directly.
Part of a module
10. Binary exploitation
Read a binary’s protections, find an overflow offset in one crash, and build a ROP chain when the stack is not executable.
Practise on real challenges
Go deeper
- From crash to shell: stack overflows, offsets, ret2win, and ret2libcA segfault is not an exploit. The path from an unexpected crash to a controlled instruction pointer to a shell, with the mitigation checks that decide which technique you need and the stack-alignment detail that breaks working exploits.
Related tools
Cyclic pattern generator and offset finder
Generate a de Bruijn sequence and find the exact overflow offset from a crashed register value - the pwntools cyclic workflow, in the browser.
ROP chain and payload builder
Assemble an exploit payload from padding, addresses, and raw bytes, with a live hexdump and offset ruler - the pwntools flat() workflow.
Struct pack and unpack (p32, p64, u32, u64)
Convert integers to little-endian byte strings and back at 8, 16, 32, and 64 bits - the pwntools p32/p64 helpers without the install.
ELF, PE and Mach-O binary analyzer
Parse headers, sections, imports, and symbols from Linux, Windows, and macOS binaries, with C++ symbol demangling and gadget discovery.