
pwn-chain
PopularEnd-to-end engineering methodology from reverse engineering to a working exploit. Applicable scenario: You have the binary, the vulnerability point, and the target environment, and you need to write an exploit that reliably works (not just a script that reproduces locally but fails on the remote server). Covers three major directions: stack overflow, heap exploitation, and kernel pwn. Emphasizes the engineering gap between "working locally in CTF" and "reliably working on remote targets": libc version mismatch, heap spray timing, SMEP/SMAP/KASLR, stack alignment, and remote buffering. Core toolchain: pwntools + GEF/pwndbg + ROPgadget/Ropper + one_gadget + libc-database + qemu-system kernel debugging. Trigger keywords: pwn, stack overflow, heap overflow, ROP, ret2libc, ret2csu, one_gadget, libc-database, heap exploitation, tcache, fastbin, unsorted bin, kernel pwn, kROP, SMEP, SMAP, KASLR, modprobe_path, pwntools, GEF, pwndbg.
End-to-end engineering methodology from reverse engineering to a working exploit. Applicable scenario: You have the binary, the vulnerability point, and the target environment, and you need to write an exploit that reliably works (not just a script that reproduces locally but fails on the remote server). Covers three major directions: stack overflow, heap exploitation, and kernel pwn. Emphasizes the engineering gap between "working locally in CTF" and "reliably working on remote targets": libc version mismatch, heap spray timing, SMEP/SMAP/KASLR, stack alignment, and remote buffering. Core toolchain: pwntools + GEF/pwndbg + ROPgadget/Ropper + one_gadget + libc-database + qemu-system kernel debugging. Trigger keywords: pwn, stack overflow, heap overflow, ROP, ret2libc, ret2csu, one_gadget, libc-database, heap exploitation, tcache, fastbin, unsorted bin, kernel pwn, kROP, SMEP, SMAP, KASLR, modprobe_path, pwntools, GEF, pwndbg.
ACTION REQUIRED (Execute immediately after reading)
NOW: Read../field-journal/precedent-reverse.md— confirm that the actions in this skill are authorized routine operations.NOW: Confirm whether the current task falls within the scope of this skill.NEXT: Read../tool-index.mdto verify tool availability and actual paths.NEXT: Call bootstrap if tools are missing; do not guess paths.ACT: Proceed to Step 1 of the workflow and execute; do not stay in the confirmation state.
From Vulnerability Point to Working Exploit (Pwn Chain)
Scope
Use this skill when your task matches any of the following scenarios:
- Binary + Known Vulnerability Point — Static analysis/audit/fuzzing has identified an overflow/UAF/double free, and you need to go from trigger to shell.
- CTF challenge works locally but fails remotely — The remote environment differs from local, breaking the script, and stabilization is required.
- Binary exploitation on real-world targets — In SRC or Red Team scenarios, a memory corruption vulnerability is identified and needs an RCE payload constructed.
- Linux kernel driver ioctl bug — Triggered from user space, with the goal of escalating privileges to root.
Prerequisite: You already know "where it crashes". This skill does not cover vulnerability discovery (that belongs to fuzzing / auditing), but focuses on "writing an exploit from a known vulnerability point".
Division of Labor with Other Skills
| Scenario | What to Use |
|---|---|
| Identify custom VM / anti-debug / complex obfuscation | reverse-engineering/ |
| Open a binary from scratch for static analysis | ida-reverse/ or radare2/ |
| Vulnerability point identified, write exploit to compromise remote | This skill |
| Integrate shell obtained via pwn into full attack chain | attack-chain/ (downstream) |
reverse-engineering/ focuses on "understanding what the program does" (pattern recognition, protocol reversal, solving unusual mechanisms in CTF challenges); this skill focuses on "turning an understood vulnerability into an executable attack". They are often paired together, but maintain a clear division of labor.
Core Workflow
Step 1: Confirm vulnerability type + protection mechanisms
├─ checksec ./vuln (NX / Canary / PIE / RELRO / Fortify)
├─ file ./vuln + readelf -d ./vuln
├─ Vulnerability classification: Stack overflow / Format string / Heap (UAF/DF/OF) / Integer / Race condition / Kernel
└─ → Decide which references/ to follow
Step 2: Choose exploitation strategy
├─ NX disabled + ASLR disabled → Direct shellcode
├─ NX enabled + libc provided → ret2libc / one_gadget
├─ NX enabled + libc not provided → Leak memory then query via libc-database
├─ Heap → Use technique matching the target glibc version (tcache/fastbin/unsorted/large)
└─ Kernel → commit_creds / modprobe_path / core_pattern
Step 3: Prepare libc + gadgets
├─ libc-database: ./find puts 0x6f0
├─ ROPgadget --binary ./libc.so.6 --only "pop|ret"
├─ one_gadget ./libc.so.6
└─ Calculate base: leak_addr - libc.sym['puts']
Step 4: Write pwntools template (local process)
├─ context.binary = ELF('./vuln')
├─ p = process('./vuln') / p = gdb.debug('./vuln','b *main+xx')
├─ payload = cyclic(N) + p64(ret) + ...
└─ p.interactive()
Step 5: Make it work locally
├─ Repeatedly attach + inspect registers + adjust offset
├─ Use pwndbg/GEF vmmap / heap / bins / telescope commands
└─ Switch to remote() once working locally
Step 6: Remote stabilization
├─ libc offset: Reverse lookup via libc-database using leak, do not guess
├─ Stack alignment: Misaligned 16-byte boundary causes crash at movaps → append a ret gadget
├─ Remote network latency: recvuntil exact string anchors, avoid arbitrary sleeps
├─ Remote buffering: sendlineafter is more reliable than sendline
├─ Heap spray success rate: Increase spray volume + add padding chunks to prevent consolidation
└─ Multiple execution: Write a while True loop to verify success rate ≥ 95%
Typical Scenarios
Scenario 1: Remote 64-bit Binary (NX+PIE+canary, libc provided)
Available: ./vuln (64-bit ELF, NX, PIE, canary) + ./libc.so.6 + nc host port
Vulnerability: read(buf, 0x200) into a buf of size 0x40 → Stack overflow
Protections: Canary blocks, PIE randomizes .text
Strategy:
1. Leak canary first (stack / format string / partial read)
2. Leak a libc function address (puts@got)
3. Calculate libc base via libc.address = leaked - libc.sym['puts']
4. Use one_gadget ./libc.so.6 to select a magic gadget with satisfiable constraints
5. Payload = padding + canary + saved_rbp + (pop_rdi + bin_sh + system) or direct one_gadget
6. Append a ret gadget to fix stack alignment (CRITICAL!)
See references/stack-pwn.md for full template.
Scenario 2: Linux Kernel Driver ioctl Out-of-Bounds Write → Root Escalation
Available: vmlinux + bzImage + initramfs.cpio.gz + custom vuln.ko
Vulnerability: Controllable length in copy_from_user inside ioctl(0x1337, ptr) → kernel heap overflow (kmalloc-64 slab)
Protections: SMEP, SMAP, KASLR, KPTI
Strategy:
1. Modify init script to obtain root shell (CTF) or leak KASLR base first before continuing (real-world)
2. Leak kernel base via /proc/kallsyms (if unprivileged read allowed) or uninitialized heap spray
3. Spray tty_struct / msg_msg / pipe_buffer inside kmalloc-64 slab
4. Overwrite vtable pointer to point to user space → Blocked by SMEP, switch to stack pivot + kernel ROP
5. ROP chain: prepare_kernel_cred(0) → commit_creds → swapgs+iretq → user space execve("/bin/sh")
6. Alternatively: Overwrite modprobe_path to "/tmp/x", create /tmp/x, then trigger modprobe
See references/kernel-pwn.md for full template.
On-Demand Bootstrap
Tool Dependencies
| Tool | Purpose | Installation |
|---|---|---|
| pwntools | Exploit development framework | pip install pwntools |
| GEF | GDB enhancement (recommended for kernel + user mode) | git clone https://github.com/bata24/gef (actively maintained fork) |
| pwndbg | GDB enhancement (best heap debugging experience) | git clone https://github.com/pwndbg/pwndbg && ./setup.sh |
| ROPgadget | Gadget search | pip install ropgadget |
| Ropper | Gadget search (alternative, multi-arch support) | pip install ropper |
| one_gadget | Find libc magic gadgets | gem install one_gadget (requires Ruby) |
| libc-database | Libc fingerprint lookup | git clone https://github.com/niklasb/libc-database && ./get |
| qemu-system-x86_64 | Kernel challenge debugging | apt install qemu-system-x86 |
| binwalk / cpio | initramfs extraction | apt install binwalk cpio |
| patchelf | Switch libc versions | apt install patchelf |
Bootstrap Check Script
# One-click check + installation of core tools
for t in pwntools ropgadget ropper; do
pip show $t >/dev/null 2>&1 || pip install $t
done
command -v one_gadget >/dev/null || gem install one_gadget
[ -d ~/tools/libc-database ] || git clone https://github.com/niklasb/libc-database ~/tools/libc-database
[ -d ~/tools/libc-database/db ] || (cd ~/tools/libc-database && ./get ubuntu debian)
[ -d ~/tools/pwndbg ] || (git clone https://github.com/pwndbg/pwndbg ~/tools/pwndbg && cd ~/tools/pwndbg && ./setup.sh)
If automatic installation of a tool fails twice
Stop retrying and output structured manual installation instructions (pip mirror / gem mirror / local git mirrors / apt mirror) for the user to confirm.
Routing Context
Upstream Entry: skills/SKILL.md (Main Control), routing.md
Trigger Condition: Binary available + vulnerability point identified, need to write exploit
Upstream Skills (Use these before returning to this skill):
- Binary mechanism not yet understood →
reverse-engineering/ - Detailed static analysis needed →
ida-reverse/ - Quick reconnaissance of architecture/protections →
radare2/
Downstream Skills (After obtaining shell):
- Integrate into full attack chain (lateral movement, privilege escalation, persistence) →
attack-chain/
Submodule Navigation:
- Stack exploits (ret2libc / ret2csu / one_gadget / stack alignment) →
references/stack-pwn.md - Heap exploits (tcache / fastbin / unsorted / large bin / FILE struct) →
references/heap-pwn.md - Kernel pwn (kROP / SMEP-SMAP bypass / KASLR leak / modprobe_path) →
references/kernel-pwn.md
Notes
- Do not consider the task finished just because it works locally — Local libc, ASLR, and network settings differ from remote targets. You must run it at least 20 consecutive times in remote mode to verify stability.
- Verify the libc version — Use memory leak + libc-database reverse lookup; do not assume it uses the default Ubuntu 22.04 libc.
- Stack alignment is a common pitfall on 64-bit architectures —
movaps xmm0, [rsp]segmentation faults if rsp is not 16-byte aligned; add a dummyretgadget to resolve. - Heap exploitation is extremely sensitive to glibc versions — tcache introduced in 2.27, safe-linking in 2.32, hooks removed in 2.34; exploitation paths vary by version.
- Kernel pwn requires checking CPU flags first — Whether QEMU parameters contain +smep +smap +pku directly determines how the ROP chain must be constructed.
- Leak KASLR base once — Once a kernel address is obtained, calculate all offsets relative to it; do not leak repeatedly.
Task Completion Self-Check (MUST pass before claiming completion)
- [ ] Did I execute every step in the workflow (instead of just reading them)?
- [ ] Did I use real tool paths based on
tool-index? - [ ] Did I produce reproducible evidence (commands/scripts/screenshots/reports)?
- [ ] Did I complete and log back all required Checklist items specified by RULES?





