niko-shiybu/PwnGPT-Automation
GitHub: niko-shiybu/PwnGPT-Automation
基于多 LLM 协同与 GDB 动态调试的 CTF 二进制漏洞利用自动化框架,通过技能卡系统和双层迭代循环自动生成并验证 exploit 脚本。
Stars: 1 | Forks: 0
# PwnGPT — 计划 B v3
基于 LLM 的自动 CTF 二进制漏洞利用框架,使用技能卡、GDB 动态调试以及双层迭代 agent 循环。
## 快速开始
```
source .venv/bin/activate
# 单个挑战
python3 automation/openhands_agent.py \
--problem pwn/stack/rop-1/problems.txt \
--binary pwn/stack/rop-1/rop1 \
--challenge-type rop --max-iters 3 \
--repo-root /path/to/PwnGPT
# 批量评估
python3 automation/evaluate.py \
--manifest automation/benchmarks/manifest_rop.json \
--agent openhands --max-iters 3 --timeout 0
```
## 配置说明
将 `automation/local_config.example.py` 复制为 `automation/local_config.py`:
```
OPENAI_API_KEY = "sk-..."
OPENAI_BASE_URL = "https://dashscope.aliyuncs.com/compatible-mode/v1"
AUTOMATION_MODEL = "qwen-max"
AUTOMATION_PYTHON = "/home/fyc/miniconda3/envs/pwngpt/bin/python3"
GDB_PATH = "/home/fyc/local/bin/gdb"
```
## 架构
### 双层 Agent 循环
```
Phase 0: Information Collection
├── collect_evidence() → binary metadata
├── auto-measure → offsets, gadgets, GOT/PLT addresses
├── discovery cards → fmt_offset, data symbols
└── build_capabilities → structured environment snapshot
Outer Loop (Planner — strategy level, max 3 rounds)
│
├── ① Planner (LLM)
│ Reads C code + fact_store + capabilities
│ Chooses: use_skill (select from 23 cards) OR write_code (write exploit directly)
│ Overrides params based on vulnerability analysis
│
├── ② Executor
│ ├── use_skill → validate → recovery probes → build_IR → render → verify
│ └── write_code → extract Python → write to file → verify
│
│ PASS → return success
│ FAIL ↓
│
Inner Loop (Decider + GDB — debug level, max 7 rounds)
│
├── ③ Real GDB Diagnosis
│ diagnose_exploit():
│ - analyze_crash: run exploit, capture corefile (RIP/RSP/fault_addr/signal)
│ - extract_payload: hook send/sendline, capture all payload stages
│ - run_gdb_session: GDB --batch replay payload → registers/backtrace/stack
│
├── ④ Decider (LLM)
│ Examines: GDB report + C code + fact_store + verify output
│ Decides ONE action:
│ - retry_params: specific param fix → re-render → stay in inner loop
│ - need_gdb: more GDB commands → re-run GDB → stay in inner loop
│ - rewrite_code: write complete corrected exploit → verify → stay in inner loop
│ - escalate: strategy fundamentally wrong → back to Planner (outer loop)
│
└──→ iterate until success or escalate
```
### 核心组件
```
automation/
├── openhands_agent.py # Main entry: Plan B v3 two-layer loop
├── llm_client.py # OpenAI-compatible LLM client
├── local_config.py # API keys, model, GDB path
│
├── skills/
│ ├── skill_cards/*.json # 23 skill cards (ROP + FMT)
│ ├── skill_engine.py # 35+ resolvers + validate_skill + rank_skills
│ ├── ir_builder.py # facts → structured exploit parameters
│ ├── renderers.py # Deterministic pwntools code generation
│ ├── capability_builder.py # evidence + facts → capabilities snapshot
│ └── skill_scheduler.py # Auto-recovery probes + fact merging
│
├── debug/
│ ├── gdb_debugger.py # ★ Real GDB dynamic debugging module
│ │ - analyze_crash() # Run exploit, capture corefile
│ │ - extract_payload_stages() # Capture all payload stages (multi-stage)
│ │ - run_gdb_session() # GDB batch replay with whitelist commands
│ │ - diagnose_exploit() # Full auto-diagnosis pipeline
│ └── gdb_runner.py # Static probes (objdump/ELF/ROPgadget)
│
├── interaction/
│ ├── io_probe.py # Binary interaction mode detection
│ ├── io_contract.py # IO stage modeling
│ └── io_renderer.py # IO code generation (never sendlineafter)
│
├── verify/
│ └── verifier.py # Subprocess exploit verification
│
├── collect/
│ └── evidence_collector.py # Binary evidence collection
│
├── facts.py # Fact store migration + access helpers
└── evaluate.py # Batch evaluation runner
```
## 技能卡系统
包含 23 张卡,涵盖 ROP 和 FMT 漏洞利用模式。LLM 自主选择卡片 —— 没有硬编码的优先级,也没有固定的排名。
每张卡定义了以下内容:
- `goal`:实现的漏洞利用模式
- `requires`:必须可用的事实(由 resolver 检查)
- `provides`:漏洞利用达成的目标
- `renderer`:确定性代码生成函数
被 BLOCKED 的卡(例如缺少 libc 但需要 libc 的卡)将从 LLM 的视图中过滤掉。
### 数据流
```
evidence + binary
→ probes (gdb_runner) → fact_store (persistent across rounds)
→ capability_builder → capabilities (rebuilt each round)
→ validate_skill → catalog with READY/NEED_*/BLOCKED status
→ Planner (LLM) selects card + overrides params
→ ir_builder → structured params
→ renderer → exploit.py
→ subprocess verify
→ FAIL → gdb_debugger (real GDB)
→ Decider (LLM) → retry/rewrite/escalate
```
## 测试结果
| 挑战类型 | 通过 | 总计 | 通过率 |
|---------------|--------|-------|------|
| ROP (栈) | 4 | 10 | 40% |
| FMT (字符串) | 2 | 5 | 40% |
**通过的挑战**:rop-1, rop-2, rop-3, rop-5, fmt-1, fmt-4
标签:Agent, AI自动化, CTF框架, DLL 劫持, Go语言工具, Petitpotam, Web报告查看器, 大语言模型, 客户端加密, 逆向工具