write-exploit
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseExploit Development Loop
漏洞利用开发循环
Write exploits iteratively — run, observe, fix, repeat until the flag drops.
以迭代方式编写漏洞利用程序——运行、观察、修复,重复直到获取flag。
Workflow
工作流程
- Understand the vulnerability — Read challenge source/binary analysis first
- Write initial exploit — Start simple, add complexity as needed
- Test against target — Run locally first, then remote
- Debug failures — Read output carefully, add debug prints, check assumptions
- Iterate — Fix and re-run until flag captured
- Clean up — Save working exploit as , flag to
solve.pyflag.txt
- 理解漏洞 — 首先阅读挑战的源码/二进制分析内容
- 编写初始漏洞利用程序 — 从简单开始,按需增加复杂度
- 针对目标测试 — 先本地运行,再远程测试
- 调试故障 — 仔细阅读输出,添加调试打印,检查假设
- 迭代 — 修复后重新运行,直到获取flag
- 整理 — 将可用的漏洞利用程序保存为,flag保存到
solve.pyflag.txt
Exploit Templates
漏洞利用模板
Binary Exploitation (pwntools)
二进制漏洞利用(pwntools)
python
#!/usr/bin/env python3
from pwn import *
context.binary = elf = ELF('./binary')python
#!/usr/bin/env python3
from pwn import *
context.binary = elf = ELF('./binary')context.log_level = 'debug'
context.log_level = 'debug'
def conn():
if args.REMOTE:
return remote('HOST', PORT)
return process('./binary')
io = conn()
def conn():
if args.REMOTE:
return remote('HOST', PORT)
return process('./binary')
io = conn()
=== EXPLOIT HERE ===
=== EXPLOIT HERE ===
io.interactive()
undefinedio.interactive()
undefinedWeb Exploitation (requests)
Web漏洞利用(requests)
python
#!/usr/bin/env python3
import requests
import sys
TARGET = sys.argv[1] if len(sys.argv) > 1 else 'http://localhost:8080'
s = requests.Session()python
#!/usr/bin/env python3
import requests
import sys
TARGET = sys.argv[1] if len(sys.argv) > 1 else 'http://localhost:8080'
s = requests.Session()=== EXPLOIT HERE ===
=== EXPLOIT HERE ===
print(f"FLAG: {flag}")
undefinedprint(f"FLAG: {flag}")
undefinedCrypto Solve Script
密码学求解脚本
python
#!/usr/bin/env python3
from Crypto.Util.number import *
from pwn import *python
#!/usr/bin/env python3
from Crypto.Util.number import *
from pwn import *=== GIVEN VALUES ===
=== GIVEN VALUES ===
=== SOLVE ===
=== SOLVE ===
flag = long_to_bytes(m)
print(f"FLAG: {flag.decode()}")
undefinedflag = long_to_bytes(m)
print(f"FLAG: {flag.decode()}")
undefinedPwntools Remote Interaction
Pwntools远程交互
python
#!/usr/bin/env python3
from pwn import *
io = remote('HOST', PORT)python
#!/usr/bin/env python3
from pwn import *
io = remote('HOST', PORT)Read until prompt
Read until prompt
io.recvuntil(b'> ')
io.recvuntil(b'> ')
Send payload
Send payload
io.sendline(payload)
io.sendline(payload)
Get response
Get response
response = io.recvline()
print(f"Response: {response}")
response = io.recvline()
print(f"Response: {response}")
Interactive mode for shell
Interactive mode for shell
io.interactive()
undefinedio.interactive()
undefinedDebug Tips
调试技巧
- Use for full pwntools traffic
context.log_level = 'debug' - Add before sends
print(f"[*] payload: {payload.hex()}") - Use to see unexpected output
io.recv(timeout=2) - Check before blocking reads
io.can_recv() - Use for local debugging with breakpoints
gdb.attach(io) - For web: after every request
print(r.status_code, r.text[:500])
- 使用查看完整的pwntools流量
context.log_level = 'debug' - 在发送前添加
print(f"[*] payload: {payload.hex()}") - 使用查看意外输出
io.recv(timeout=2) - 在阻塞读取前检查
io.can_recv() - 使用进行带断点的本地调试
gdb.attach(io) - 针对Web漏洞:每个请求后使用
print(r.status_code, r.text[:500])
Common Pitfalls
常见陷阱
- Wrong endianness: Use for little-endian,
p64()for bigp64(val, endian='big') - Newline issues: adds
sendline(),\ndoesn't — know which the server expectssend() - Timing: Add between sends if server is slow
sleep(0.5) - Encoding: Web payloads may need URL encoding, base64, or hex
- Stack alignment: x86-64 needs 16-byte alignment — add extra gadget
ret - Python 2 vs 3: pwntools works with bytes in Python 3 — use not
b"string""string"
- 字节序错误:小端序使用,大端序使用
p64()p64(val, endian='big') - 换行问题:会添加
sendline(),\n不会——要清楚服务器期望哪种方式send() - 计时问题:如果服务器响应慢,在发送之间添加
sleep(0.5) - 编码问题:Web payload可能需要URL编码、base64或十六进制编码
- 栈对齐:x86-64需要16字节对齐——添加额外的gadget
ret - Python 2 vs 3:pwntools在Python 3中使用字节类型——使用而非
b"string""string"
Iteration Pattern
迭代模式
1. Write exploit → run → "Connection refused"
Fix: Check host/port, is service up?
2. Write exploit → run → "EOF in recv"
Fix: Server closed connection — payload crashed it. Check offsets.
3. Write exploit → run → wrong output
Fix: Add debug prints, check each step's output matches expectation.
4. Write exploit → run → "flag{...}"
Done! Save to flag.txt1. 编写漏洞利用程序 → 运行 → "Connection refused"
修复:检查主机/端口,服务是否启动?
2. 编写漏洞利用程序 → 运行 → "EOF in recv"
修复:服务器关闭了连接——payload导致崩溃。检查偏移量。
3. 编写漏洞利用程序 → 运行 → 输出错误
修复:添加调试打印,检查每一步的输出是否符合预期。
4. 编写漏洞利用程序 → 运行 → "flag{...}"
完成!保存到flag.txtTarget
目标
$ARGUMENTS
$ARGUMENTS