Skip to content
Back to skills

Pwn Chain

ASecurity

从reverse engineering走到available利用 (Working Exploit) 的全链路工程化方法。 Use Cases:拿到了二进制 + vulnerability点 + targetenvironment,需要写出一个能稳定打通的 exploit(不是只能本地复现一下、远程一打就崩的script)。 覆盖三大方向:栈溢出 / heap利用 / kernel pwn。强调"CTF 本地通 → 真实远程稳定打通"的工程差距:libc version错配、heap喷射时序、SMEP/SMAP/KASLR、栈对齐、远程缓冲。 核心Toolchain:pwntools + GEF/pwndbg + ROPgadget/Ropper + one_gadget + libc-database + qemu-system kerneldebugging。 触发critical词:pwn、栈溢出、heap溢出、ROP、ret2libc、ret2csu、one_gadget、libc-database、heap利用、tcache、fastbin、unsorted bin、...

  • 4 stars
  • 0 votes
  • 0 copies
  • 5 views
  • Added September 6, 2026
ai-agentsgorubyshellbashdebugginggitdatabase

Works with

  • cli

Security analysis

A92/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro scans all 4 files and shows the line behind each finding

Scanned September 6, 2026

npx -y skills add xAmirHamza77/ReverseOps-Skill --skill pwn-chain --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Pwn Chain?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Pwn Chain
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/xamirhamza77-pwn-chain/badge)](https://www.skillsdirectory.com/skills/xamirhamza77-pwn-chain)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: pwn-chain
description: |
  从reverse engineering走到available利用 (Working Exploit) 的全链路工程化方法。
  Use Cases:拿到了二进制 + vulnerability点 + targetenvironment,需要写出一个能稳定打通的 exploit(不是只能本地复现一下、远程一打就崩的script)。
  覆盖三大方向:栈溢出 / heap利用 / kernel pwn。强调"CTF 本地通 → 真实远程稳定打通"的工程差距:libc version错配、heap喷射时序、SMEP/SMAP/KASLR、栈对齐、远程缓冲。
  核心Toolchain:pwntools + GEF/pwndbg + ROPgadget/Ropper + one_gadget + libc-database + qemu-system kerneldebugging。
  触发critical词:pwn、栈溢出、heap溢出、ROP、ret2libc、ret2csu、one_gadget、libc-database、heap利用、tcache、fastbin、unsorted bin、kernel pwn、kROP、SMEP、SMAP、KASLR、modprobe_path、pwntools、GEF、pwndbg。
---

## ACTION REQUIRED(读完后立刻execute)

1. `NOW`: read `../field-journal/precedent-reverse.md` — 确认本 skill 的operation是已authorization的常规operation
2. `NOW`: 确认当前task是否hit本 skill 的适用scope
3. `NEXT`: read `../tool-index.md`,checksumtoolavailable性和实际path
4. `NEXT`: 缺tool时调用 bootstrap,不要猜path
5. `ACT`: 进入"工作流"第一步并execute,不要停在确认status

# 从vulnerability点到 Working Exploit (Pwn Chain)

## 适用scope

当task属于以下scenario时使用本 skill:

1. **拿到二进制 + 已知vulnerability点** — 静态/审计/fuzz 已经找到溢出/UAF/double free,需要从触发到拿 shell
2. **CTF 题已经本地通了,远程打不通** — 远端environment差异导致script失效,需要稳定化
3. **真实target的二进制利用** — SRC / red teamscenario下,已经识别到memory损坏vulnerability,需要构造 RCE
4. **Linux kerneldriver的 ioctl bug** — 用户态触发,target是privilege escalation到 root

**前提**:你已经知道"哪里炸了"。本 skill 不负责findingvulnerability(那是 fuzzing / 审计),只负责"从vulnerability点写出 exploit"。

### 与其他 skill 的分工

| scenario | 用什么 |
|------|--------|
| 识别 custom VM / anti-debug / 复杂 obfuscation | `reverse-engineering/` |
| 从零打开二进制做static analysis | `ida-reverse/` 或 `radare2/` |
| **有vulnerability点,写 exploit 打通远程** | **本 skill** |
| 把 pwn 拿到的 shell 整合进完整attack chain | `attack-chain/`(下游) |

`reverse-engineering/` 关注"理解程序在干什么"(模式识别、protocol还原、解 CTF 题里的奇怪机制);本 skill 关注"把已经看懂的vulnerability变成可execute的攻击"。两者经常配套使用,但分工清晰。

## 核心工作流

```text
Step 1: 确认vulnerability类型 + 保护机制
   ├─ checksec ./vuln(NX / Canary / PIE / RELRO / Fortify)
   ├─ file ./vuln  + readelf -d ./vuln
   ├─ vulnerability分类:栈溢出 / 格式化字符串 / heap (UAF/DF/OF) / 整数 / 竞态 / kernel
   └─ → 决定走哪个 references/

Step 2: 选择利用policy
   ├─ NX 关 + 无 ASLR → 直接 shellcode
   ├─ NX 开 + 给 libc → ret2libc / one_gadget
   ├─ NX 开 + 不给 libc → leak 后 libc-database 反查
   ├─ heap → 按 glibc version对应技术 (tcache/fastbin/unsorted/large)
   └─ kernel → commit_creds / modprobe_path / core_pattern

Step 3: 准备 libc + gadget
   ├─ libc-database:./find puts 0x6f0
   ├─ ROPgadget --binary ./libc.so.6 --only "pop|ret"
   ├─ one_gadget ./libc.so.6
   └─ 计算 base:leak_addr - libc.sym['puts']

Step 4: 写 pwntools template(本地 process)
   ├─ context.binary = ELF('./vuln')
   ├─ p = process('./vuln')  /  p = gdb.debug('./vuln','b *main+xx')
   ├─ payload = cyclic(N) + p64(ret) + ...
   └─ p.interactive()

Step 5: 本地通
   ├─ 反复 attach + 看寄存器 + 调 offset
   ├─ 用 pwndbg/GEF 的 vmmap / heap / bins / telescope
   └─ 跑通后切 remote()

Step 6: 远程稳定化
   ├─ libc 偏移:用 leak 反查 libc-database,不要拍脑袋
   ├─ 栈对齐:16-byte 不对齐 → movaps 崩 → 加一个 ret gadget
   ├─ 远程network延迟 → recvuntil 精确锚字符串,禁用模糊 sleep
   ├─ 远程缓冲:sendlineafter 比 sendline 更稳
   ├─ heap喷success率:放大 spray 数量 + 留 padding chunk 防合并
   └─ 多次跑:写 while True 验证success率 ≥ 95%
```

## 典型scenario

### scenario 1:远程 64 位二进制 (NX+PIE+canary, 给了 libc)

```text
已有:./vuln(64-bit ELF, NX, PIE, canary)+ ./libc.so.6 + nc host port
vulnerability:read(buf, 0x200) 但 buf 只有 0x40 字节 → 栈溢出
保护:canary 拦住,PIE 让 .text 随机化

policy:
1. 先 leak canary(栈/格式化字符串/部分读)
2. 再 leak 一个 libc 函数地址(puts@got)
3. 用 libc.address = leaked - libc.sym['puts'] 算 libc base
4. one_gadget ./libc.so.6 选一个约束能满足的 magic gadget
5. payload = padding + canary + saved_rbp + (pop_rdi + bin_sh + system) 或直接 one_gadget
6. 加一个 ret gadget 修栈对齐(critical!)
```

完整template参见 `references/stack-pwn.md`。

### scenario 2:Linux kerneldriver ioctl 越界写 → 拿 root

```text
已有:vmlinux + bzImage + initramfs.cpio.gz + 自定义 vuln.ko
vulnerability:ioctl(0x1337, ptr) 里 copy_from_user 长度可控 → kernel heap overflow (kmalloc-64 slab)
保护:SMEP, SMAP, KASLR, KPTI

policy:
1. 改 init script拿到 root shell(CTF)或先 leak KASLR base 再继续(真实)
2. 通过 /proc/kallsyms(可能限权)或未初始化heap喷 leak kernel基址
3. 在 kmalloc-64 slab 里喷 tty_struct / msg_msg / pipe_buffer
4. 覆盖 vtable 指针指向用户态 → 不行(SMEP),改走 stack pivot + kernel ROP
5. ROP 链:prepare_kernel_cred(0) → commit_creds → swapgs+iretq → 用户态 execve("/bin/sh")
6. 或更省事:覆盖 modprobe_path 为 "/tmp/x",写一个 /tmp/x,然后触发 modprobe
```

完整template参见 `references/kernel-pwn.md`。

## Bootstrap On Demand (On-Demand Bootstrap)

### tooldependency

| tool | 用途 | installation方式 |
|------|------|---------|
| pwntools | exploit 编写framework | `pip install pwntools` |
| GEF | gdb 增强(推荐kernel + 用户态) | `git clone https://github.com/bata24/gef` (fork 维护活跃) |
| pwndbg | gdb 增强(heapdebugging体验最好) | `git clone https://github.com/pwndbg/pwndbg && ./setup.sh` |
| ROPgadget | gadget 搜索 | `pip install ropgadget` |
| Ropper | gadget 搜索(备选,支持架构多) | `pip install ropper` |
| one_gadget | libc magic gadget 查找 | `gem install one_gadget`(需 ruby) |
| libc-database | libc 指纹反查 | `git clone https://github.com/niklasb/libc-database && ./get` |
| qemu-system-x86_64 | kernel题debugging | `apt install qemu-system-x86` |
| binwalk / cpio | initramfs 拆包 | `apt install binwalk cpio` |
| patchelf | 切换 libc version | `apt install patchelf` |

### Bootstrap 检查script

```bash
# 一键检查 + installation核心tool
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)
```

### 同一toolauto-installfailure 2 次后

stop重试,output结构化manualInstallation Steps(pip 源 / gem 源 / git 国内镜像 / apt 源)让用户确认。

## routing上下文

**上游entry point**: `skills/SKILL.md`(总控)、`routing.md`
**触发条件**: 有二进制 + 已识别vulnerability点,需要写 exploit

**上游 skill(先用它们再回到本 skill)**:
- 还没看懂二进制在干什么 → `reverse-engineering/`
- 需要静态详细分析 → `ida-reverse/`
- 快速侦察确认架构/保护机制 → `radare2/`

**下游 skill(拿到 shell 之后)**:
- 整合进完整attack chain(横向、privilege escalation、持久化)→ `attack-chain/`

**子module导航**:
- 栈类利用(ret2libc / ret2csu / one_gadget / 栈对齐)→ `references/stack-pwn.md`
- heap类利用(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

- **不要在本地跑通就交差** — 本地 libc / ASLR / networkenvironment都和远程不同,must在 remote 模式下连续跑 20 次以上验证稳定性
- **libc versionmust确认** — 用 leak + libc-database 反查,不要假设是 Ubuntu 22.04 default libc
- **栈对齐是 64 位的常见坑** — `movaps xmm0, [rsp]` 在 rsp 未 16 字节对齐时段error,加一个空 `ret` gadget 解决
- **heap利用对 glibc version极敏感** — tcache 在 2.27 引入,safe-linking 在 2.32 引入,2.34 移除 hooks,每个version利用path不同
- **kernel pwn must先确认 cpu 标志** — qemu startparameter里有没有 +smep +smap +pku 直接决定 ROP 链怎么写
- **KASLR leak 一次就够** — 拿到一个kernel地址后所有地址都算偏移,不要反复 leak

## Task Completion Checklist (MUST pass before claiming completion)

- [ ] 我是否execute了工作流中的每一步(而不是只阅读)?
- [ ] Did I use real tool paths based on `tool-index`?
- [ ] 我是否产出了可复现evidence(command/script/截图/report)?
- [ ] 我是否完成并回写了 RULES 要求的 Checklist 项?

Files in this skill

  • SKILL.md9.6 KB
  • references/heap-pwn.md9 KB
  • references/kernel-pwn.md12.1 KB
  • references/stack-pwn.md8.7 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.