Lesson 3 of 9 · 28m
Measuring Overwrite Offsets and Proving Control of Execution
Use cyclic patterns, debugger evidence, and controlled lab breakpoints to demonstrate instruction-pointer influence without pretending control is exploitation.
The first time you see the instruction pointer filled with your input, it feels like the machine has confessed. It has not. It has only shown that bytes you control reached a control-flow consumer. Proving that distinction rigorously is what separates a controlled experiment from a noisy crash.
Measure with a cyclic pattern
A cyclic pattern gives every position a different fingerprint. Generate a unique sequence, feed it to the lab binary, and inspect which fragment landed in the control register:
python3 - <<'PY'
from pwn import cyclic
open('/tmp/cyclic.bin','wb').write(cyclic(200))
PY
gdb -q /tmp/vuln-greet -ex 'run "$(cat /tmp/cyclic.bin)"' -ex 'info registers rip rsp rbp' -ex 'x/8gx $rsp' -ex quitIn pwntools, cyclic_find converts the observed fragment back to an offset:
python3 - <<'PY'
from pwn import cyclic_find
print(cyclic_find(0x616161616161616c))
PYDo not guess offsets by adding four characters at a time. That wastes hours and hides off-by-one behavior.
Expect architecture and compiler reality
On x86-64, overwriting rip directly is less visually obvious than in old 32-bit examples because the CPU may fault when a noncanonical address is loaded. The proof often appears as a crash while returning, a corrupted value at the top of the stack, or a controlled jump target visible after stepping through ret.
Inspect instructions rather than trusting crash output:
x/3i $pc
bt
x/12gx $rsp
info registers rip rsp rbpIf stack protector is enabled, the first consumer may be __stack_chk_fail rather than ret. That is not control; it is the mitigation detecting corruption before control transfer.
Prove influence with a benign control target
In a teaching binary, use a debugger breakpoint or an address inside the same lab program. Break at greet, run with the generated file, step through finish, and inspect x/4i $pc. You are demonstrating reachability, not weaponizing the program; the exact primitive varies by binary, so report evidence rather than universal recipes.
Control is a chain of constraints
Once the offset is known, enumerate exact byte count, pointer width, forbidden bytes, alignment, and post-write consumers such as canary checks or cleanup code. Those constraints decide whether control is stable and why the same overwrite can be exploitable in one build and merely a crash in another.
Field notes
- A cyclic match in memory is not automatically control-flow influence; verify that the corrupted value is consumed as control data.
- Noncanonical x86-64 addresses often fault differently than chosen executable addresses; read the disassembly at the fault.
- Input encoding can transform bytes before the vulnerable copy, so test wire bytes and memory bytes separately.
- Treat
ripcontrol as a lab milestone. Reliability, mitigation interaction, and payload placement are still ahead.
Was this lesson helpful?