Lesson 1 of 9 · 24m
Exploit Primitives, Not Copy-Paste Shellcode
Learn to describe memory corruption as a chain of primitives — write control, read control, execution influence — instead of treating exploits as magic payloads.
The day-one lecture I give new exploit developers is short: if you cannot name your primitives, you do not have an exploit. You have a crash, a poem, or a screenshot. Professionals work in primitives because primitives survive small changes. Payload copy-paste does not.
A primitive is controlled influence
A primitive answers three questions: what can you influence, how much control do you have, and how repeatable is it? A stack buffer overflow is not automatically control of rip. It may be control of one saved pointer, eight bytes past a canary, or nothing useful because a structure member is overwritten first.
primitive example value
write-what-where heap overflow reaches a function pointer strong
relative write index off end of array context-dependent
control-flow hijack overwrite return address or vtable slot strong
information leak uninitialized memory or format string often requiredThe stronger your vocabulary, the faster you can choose a path. Exploitation is engineering under constraint, not spellcasting.
Start from the crash and work backward
A useful first analysis is brutally concrete:
gdb ./target -q
(gdb) run < crash-input
(gdb) info registers
(gdb) bt
(gdb) x/8gx $rspDo not stop at SIGSEGV. Ask which input byte reached which byte in memory, which instruction used the corrupted value, and whether the crash is before or after the useful overwrite. Many crashes are downstream artifacts; the important write happened earlier.
Control is measured, not asserted
Use cyclic patterns to measure offsets, but treat the offset as the beginning of analysis rather than the answer:
python3 - <<'PY'
from pwn import *
print(cyclic(256).decode())
PYAfter calculating an offset, build a minimal input that changes only the target bytes. Then prove causality: put 0x4141414141414141 where you believe control lands and inspect the faulting state. If the input layout shifts with argument count, environment size, allocator state, or parsing quirks, reliability work has started.
Mitigations reshape exploitation
The beginner question is "can I overwrite the return address?" The professional question is "what mitigations stand between my corruption and execution?" A target with a canary, NX, full RELRO, ASLR, PIE, and a modern allocator is not impossible; it is a different puzzle requiring a leak, a better primitive, or a logic-assisted path.
Write the primitive table in your notes
Before writing exploit code, fill this in:
corruption source:
controllable bytes:
fixed bytes:
target reached:
crash instruction:
leak available:
mitigations active:
reliability variables:If any row is unknown, your next experiment is obvious. This is why disciplined exploit developers look fast. They are not guessing more skillfully; they are refusing to skip the model.
Field notes
- A crash in
mallocusually means heap metadata was damaged earlier, not thatmallocis the bug. - Offsets can differ between
gdb, direct execution, ssh, systemd, and containers because stack layout and environment differ. - Cyclic offsets measure byte placement, not exploitability; alignment and intervening writes matter.
- If ASLR makes a result intermittent, do not call it impossible until you understand which address must be leaked or brute-forced.
Was this lesson helpful?