261 lines
10 KiB
Markdown
261 lines
10 KiB
Markdown
<!-- WEHUB_ZH_README -->
|
||
> [!NOTE]
|
||
> 本文档由 WeHub 基于上游 README 翻译整理,属于社区翻译,非官方中文文档。
|
||
> [English](./README.en.md) · [原始项目](https://github.com/GreyDGL/PentestGPT) · [上游 README](https://github.com/GreyDGL/PentestGPT/blob/HEAD/README.md)
|
||
> 原作者、版权与许可证归属以原始项目及本仓库 LICENSE 文件为准。
|
||
|
||
<!-- Improved compatibility of back to top link: See: https://github.com/othneildrew/Best-README-Template/pull/73 -->
|
||
<a name="readme-top"></a>
|
||
|
||
<!-- PROJECT SHIELDS -->
|
||
[![Contributors][contributors-shield]][contributors-url]
|
||
[![Forks][forks-shield]][forks-url]
|
||
[![Stargazers][stars-shield]][stars-url]
|
||
[![Issues][issues-shield]][issues-url]
|
||
[![MIT License][license-shield]][license-url]
|
||
[![Discord][discord-shield]][discord-url]
|
||
|
||
<!-- PROJECT LOGO -->
|
||
<br />
|
||
<div align="center">
|
||
|
||
<h3 align="center">PentestGPT</h3>
|
||
|
||
<p align="center">
|
||
AI 驱动的自主渗透测试智能体
|
||
<br />
|
||
<strong>发表于 USENIX Security 2024</strong>
|
||
<br />
|
||
<br />
|
||
<a href="https://pentestgpt.com"><strong>官方网站:pentestgpt.com »</strong></a>
|
||
<br />
|
||
<br />
|
||
<a href="https://www.usenix.org/conference/usenixsecurity24/presentation/deng">研究论文</a>
|
||
·
|
||
<a href="https://github.com/GreyDGL/PentestGPT/issues">报告 Bug</a>
|
||
·
|
||
<a href="https://github.com/GreyDGL/PentestGPT/issues">请求功能</a>
|
||
</p>
|
||
</div>
|
||
|
||
<!-- ABOUT THE PROJECT -->
|
||
<a href="https://trendshift.io/repositories/3770" target="_blank"><img src="https://trendshift.io/api/badge/repositories/3770" alt="GreyDGL%2FPentestGPT | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
|
||
|
||
---
|
||
|
||
## 演示
|
||
|
||
### 安装
|
||
[](https://asciinema.org/a/761661)
|
||
|
||
[在 YouTube 观看](https://www.youtube.com/watch?v=RUNmoXqBwVg)
|
||
|
||
### PentestGPT 实战
|
||
[](https://asciinema.org/a/761663)
|
||
|
||
[在 YouTube 观看](https://www.youtube.com/watch?v=cWi3Yb7RmZA)
|
||
|
||
---
|
||
|
||
## v1.0 新特性(Agentic 升级)
|
||
|
||
- **迭代循环(Iteration Loop)** - 智能体持续运行,维护记录进度的上下文文件,并在触及限制时携带先前上下文重启。循环在捕获 flag 或达到最大迭代次数时终止。
|
||
- **自主智能体(Autonomous Agent)** - 用于智能、自主渗透测试的智能体流水线
|
||
- **会话持久化(Session Persistence)** - 保存并恢复渗透测试会话
|
||
|
||
> 交互式**现代化遗留(modernized legacy)**模式现已支持**多模型**(`pentestgpt-legacy`)—— OpenAI、Anthropic、Google Gemini、DeepSeek、xAI、Qwen、Moonshot 以及本地 Ollama。参见[交互式多 LLM 模式](#interactive-multi-llm-mode-modernized-legacy)。
|
||
|
||
---
|
||
|
||
## 功能特性
|
||
|
||
- **AI 驱动的挑战求解器** - 利用 LLM 的高级推理能力执行渗透测试与 CTF
|
||
- **实时演练(Live Walkthrough)** - 在智能体攻克挑战时实时跟踪步骤
|
||
- **多类别支持** - Web、Crypto、Reversing、Forensics、PWN、权限提升(Privilege Escalation)
|
||
- **实时反馈** - 通过实时活动更新观察 AI 的工作过程
|
||
- **可扩展架构** - 简洁、模块化的设计,便于未来增强
|
||
|
||
---
|
||
|
||
## 快速开始
|
||
|
||
### 前置条件
|
||
|
||
- **Python 3.12+**
|
||
- **[uv](https://docs.astral.sh/uv/)** - Python 包管理器
|
||
- **Claude Code CLI** (`claude`) - 已安装并完成认证。参见 [Claude Code 文档](https://docs.anthropic.com/en/docs/claude-code)
|
||
|
||
### 安装
|
||
|
||
```bash
|
||
git clone https://github.com/GreyDGL/PentestGPT.git
|
||
cd PentestGPT
|
||
make install # runs uv sync
|
||
```
|
||
|
||
### 命令参考
|
||
|
||
| Command | Description |
|
||
|---------|-------------|
|
||
| `make install` | 安装依赖 |
|
||
| `make test` | 运行全部测试 |
|
||
| `make check` | 运行 lint + typecheck |
|
||
| `make build` | 构建可分发包 |
|
||
|
||
---
|
||
|
||
## 用法
|
||
|
||
```bash
|
||
# Run against a target
|
||
pentestgpt --target 10.10.11.234
|
||
|
||
# With challenge context
|
||
pentestgpt --target 10.10.11.50 --instruction "WordPress site, focus on plugin vulnerabilities"
|
||
|
||
# Limit iterations
|
||
pentestgpt --target 10.10.11.234 --max-iterations 5
|
||
```
|
||
|
||
智能体在**迭代循环**中运行:它自主工作,维护记录进度的上下文文件,并在触及限制时携带先前上下文重启。循环在捕获 flag 或达到最大迭代次数(默认:10)时终止。
|
||
|
||
---
|
||
|
||
## 交互式多 LLM 模式(现代化遗留)
|
||
|
||
USENIX 2024 论文中的经典人机协同 PentestGPT 得以保留,并现代化为 `pentestgpt-legacy`。它运行三个协作的 LLM 会话——**推理 / 生成 / 解析**——在由你交互式驱动会话的同时(`next`、`more`、`todo`、`discuss`)维护**渗透测试任务树(Pentesting Task Tree,PTT)**。与自主智能体(仅 Claude)不同,此模式通过各提供商的官方 SDK **原生**对接多家提供商。
|
||
|
||
### 配置提供商
|
||
|
||
为要使用的任意提供商设置 API 密钥(在环境变量中或 `.env` 中——参见 `.env.example`)。仅启用已配置的提供商。
|
||
|
||
```bash
|
||
OPENAI_API_KEY=... ANTHROPIC_API_KEY=... GEMINI_API_KEY=... # or GOOGLE_API_KEY
|
||
DEEPSEEK_API_KEY=... GROK_API_KEY=... QWEN_API_KEY=... KIMI_API_KEY=...
|
||
```
|
||
|
||
### 运行
|
||
|
||
```bash
|
||
# Auto-pick the best available models for each session
|
||
pentestgpt-legacy
|
||
|
||
# Choose models per session
|
||
pentestgpt-legacy --reasoning-model claude-opus-4-8 --parsing-model gemini-3.5-flash
|
||
|
||
# Local model via Ollama (OpenAI-compatible)
|
||
pentestgpt-legacy --reasoning-model ollama:qwen3 --base-url http://localhost:11434/v1
|
||
|
||
# List every supported model (shows which providers are configured)
|
||
pentestgpt-legacy --list-models
|
||
|
||
# Live round-trip every configured model and print a pass/fail matrix
|
||
pentestgpt-legacy --smoke-test
|
||
```
|
||
|
||
### 支持的模型(2026 年 6 月经网页核实)
|
||
|
||
`pentestgpt-legacy --list-models` 始终渲染实时注册表。模型 ID 变更后请重新运行 `--smoke-test`。当前快照:
|
||
|
||
| Provider | Current models | Legacy (kept) | Env key |
|
||
|----------|----------------|---------------|---------|
|
||
| **OpenAI** | `gpt-5.5`, `gpt-5.5-pro`, `gpt-5.4-mini`, `gpt-5.4-nano`, `gpt-5.2`, `gpt-5.3-codex` | `gpt-4o`, `gpt-4o-mini`, `o3`, `o4-mini` | `OPENAI_API_KEY` |
|
||
| **Anthropic** | `claude-opus-4-8`, `claude-sonnet-4-6`, `claude-haiku-4-5-20251001` | — | `ANTHROPIC_API_KEY` |
|
||
| **Google Gemini** | `gemini-3.1-pro`, `gemini-3.5-flash`, `gemini-3-pro`, `gemini-3.1-flash-lite` | `gemini-2.5-pro`, `gemini-2.5-flash` | `GEMINI_API_KEY` / `GOOGLE_API_KEY` |
|
||
| **DeepSeek** | `deepseek-v4-flash`, `deepseek-v4-pro` | `deepseek-chat`, `deepseek-reasoner` | `DEEPSEEK_API_KEY` |
|
||
| **xAI Grok** | `grok-4.3` | — | `GROK_API_KEY` / `XAI_API_KEY` |
|
||
| **Alibaba Qwen** | `qwen3.7-max`, `qwen3.5-flash`, `qwen3-max` | `QWEN_API_KEY` / `DASHSCOPE_API_KEY` |
|
||
| **Moonshot Kimi** | `kimi-k2.6` | — | `KIMI_API_KEY` (`.cn` 默认;设置 `MOONSHOT_BASE_URL` 以使用 `.ai`) |
|
||
| **Local (Ollama)** | `ollama:<model>` (e.g. `ollama:qwen3`) | — | none (`OLLAMA_BASE_URL`) |
|
||
|
||
> 注册表位于 `pentestgpt_legacy/llm/registry.py`(唯一真实来源)。
|
||
> 添加模型只需一条 `ModelSpec` 条目;OpenAI 兼容提供商复用同一连接器。
|
||
|
||
---
|
||
|
||
## 遥测(Telemetry)
|
||
|
||
PentestGPT 收集匿名使用数据以帮助改进工具。这些数据会发送至我们的 [Langfuse](https://langfuse.com) 项目,包括:
|
||
- 会话元数据(目标类型、持续时间、完成状态)
|
||
- 工具执行模式(使用了哪些工具,而非实际命令)
|
||
- Flag 检测事件(检测到 flag,而非 flag 内容)
|
||
|
||
**不收集敏感数据** - 命令输出、凭据或实际 flag 值绝不会被传输。
|
||
|
||
### 选择退出
|
||
|
||
```bash
|
||
# Via command line flag
|
||
pentestgpt --target 10.10.11.234 --no-telemetry
|
||
|
||
# Via environment variable
|
||
export LANGFUSE_ENABLED=false
|
||
```
|
||
|
||
---
|
||
|
||
## 基准测试
|
||
|
||
PentestGPT 在 XBOW 验证套件上达到 **86.5% 成功率**(104 项基准中的 90 项):
|
||
|
||
- **成本**:每项成功基准平均 $1.11,中位数 $0.42
|
||
- **时间**:每项成功基准平均 6.1 分钟,中位数 3.3 分钟
|
||
- **按难度划分的成功率**:
|
||
- Level 1:91.1%
|
||
- Level 2:74.5%
|
||
- Level 3:62.5%
|
||
|
||
---
|
||
|
||
## 引用
|
||
|
||
若你在研究中使用 PentestGPT,请引用我们的论文:
|
||
|
||
```bibtex
|
||
@inproceedings{299699,
|
||
author = {Gelei Deng and Yi Liu and Víctor Mayoral-Vilches and Peng Liu and Yuekang Li and Yuan Xu and Tianwei Zhang and Yang Liu and Martin Pinzger and Stefan Rass},
|
||
title = {{PentestGPT}: Evaluating and Harnessing Large Language Models for Automated Penetration Testing},
|
||
booktitle = {33rd USENIX Security Symposium (USENIX Security 24)},
|
||
year = {2024},
|
||
isbn = {978-1-939133-44-1},
|
||
address = {Philadelphia, PA},
|
||
pages = {847--864},
|
||
url = {https://www.usenix.org/conference/usenixsecurity24/presentation/deng},
|
||
publisher = {USENIX Association},
|
||
month = aug
|
||
}
|
||
```
|
||
|
||
---
|
||
|
||
## 许可证
|
||
|
||
根据 MIT License 发布。更多信息请参见 `LICENSE.md`。
|
||
|
||
**免责声明**:本工具仅供教育用途和经授权的安全测试(authorized security testing)使用。作者不赞成任何非法用途。使用风险自负。
|
||
|
||
---
|
||
|
||
## 致谢
|
||
|
||
- 研究得到 [Quantstamp](https://www.quantstamp.com/) 与 [NTU Singapore](https://www.ntu.edu.sg/) 的支持
|
||
|
||
<p align="right">(<a href="#readme-top">返回顶部</a>)</p>
|
||
|
||
<!-- MARKDOWN LINKS & IMAGES -->
|
||
[contributors-shield]: https://img.shields.io/github/contributors/GreyDGL/PentestGPT.svg?style=for-the-badge
|
||
[contributors-url]: https://github.com/GreyDGL/PentestGPT/graphs/contributors
|
||
[forks-shield]: https://img.shields.io/github/forks/GreyDGL/PentestGPT.svg?style=for-the-badge
|
||
[forks-url]: https://github.com/GreyDGL/PentestGPT/network/members
|
||
[stars-shield]: https://img.shields.io/github/stars/GreyDGL/PentestGPT.svg?style=for-the-badge
|
||
[stars-url]: https://github.com/GreyDGL/PentestGPT/stargazers
|
||
[issues-shield]: https://img.shields.io/github/issues/GreyDGL/PentestGPT.svg?style=for-the-badge
|
||
[issues-url]: https://github.com/GreyDGL/PentestGPT/issues
|
||
[license-shield]: https://img.shields.io/github/license/GreyDGL/PentestGPT.svg?style=for-the-badge
|
||
[license-url]: https://github.com/GreyDGL/PentestGPT/blob/master/LICENSE.md
|
||
[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge&logo=linkedin&colorB=555
|
||
[linkedin-url]: https://www.linkedin.com/in/gelei-deng-225a10112/
|
||
[linkedin-url2]: https://www.linkedin.com/in/vmayoral/
|
||
[discord-shield]: https://dcbadge.vercel.app/api/server/eC34CEfEkK
|
||
[discord-url]: https://discord.gg/eC34CEfEkK
|