Usta0x001/Phantom
GitHub: Usta0x001/Phantom
一个基于 ReAct 循环的 AI 原生自主渗透测试平台,利用大模型推理串联安全工具,在隔离沙箱中完成从侦察到漏洞验证的全流程自动化。
Stars: 100 | Forks: 7
# ☠ PHANTOM ### 自主对抗模拟平台 *AI 原生渗透测试 —— 自主侦察、漏洞利用与结果验证。*
[](https://pypi.org/project/phantom-agent/) [](https://python.org) [](LICENSE) [](#architecture) [](#testing) [](#security-audit) [](#) [](#quick-start)
[**快速开始**](#quick-start) · [**架构**](#architecture) · [**使用**](#usage) · [**配置**](#configuration) · [**贡献**](#contributing)
| 🧠 | 自主 ReAct 循环 —— 规划、执行工具、读取结果、重新规划。无需人工指导即可处理死胡同和意外响应。 |
| 🔧 | 30+ 安全工具 —— nmap · nuclei · sqlmap · ffuf · httpx · katana · nikto · gobuster · arjun · semgrep · playwright —— 均自动编排。 |
| 🐳 | 临时 Docker 沙箱 —— 所有攻击工具在受网络限制的 Kali Linux 容器中运行。零主机文件系统访问。每次扫描后销毁容器。 |
| ⚡ | 多 Agent 并行 —— 生成专门的子 Agent(SQLi, XSS, 侦察)并发工作,并将发现报告给协调器。 |
| 🛡️ | 7 层防御模型 —— 范围守卫 → 工具防火墙 → Docker 沙箱 → 成本限制器 → 时间预算 → HMAC 审计跟踪 → 输出净化器。 |
| ✅ | 仅经验证的发现 —— 无幻觉。每个报告的漏洞都包含原始 HTTP 证据、复现步骤和可工作的漏洞利用脚本。 |
| 🗺️ | MITRE ATT&CK 丰富化 —— 自动进行 CWE、CAPEC、技术级标记,并为每个发现计算 CVSS 3.1 评分。 |
| 📋 | 合规覆盖 —— OWASP Top 10 (2021) · PCI DSS v4.0 · NIST 800-53 —— 每个发现自动映射。 |
| 💾 | 知识持久化 —— 跨扫描内存存储主机、过往发现和误报特征。每次扫描都从上一次中学习。 |
| 💰 | 全成本控制 —— 按请求和按扫描的预算上限。实时跟踪每个 Token 和每一美元。 |
① 系统架构 —— 组件概览
``` %%{init: {"theme": "dark"}}%% flowchart TD USER(["👤 User / CI-CD"]) subgraph IFACE["Interface Layer"] CLI["CLI · TUI"] PARSER["Output Parser"] end subgraph ORCH["Orchestration"] PROFILE["Scan Profile"] SCOPE["Scope Guard"] COST["Cost Controller"] AUDIT["HMAC Audit Log"] end subgraph AGENT["Agent Core — ReAct"] LLM["LLM via LiteLLM"] STATE["State Machine"] MEM["Memory Engine"] SKILLS["Skills Engine"] end subgraph SEC["Security Layer"] FW["Tool Firewall"] VERIFY["Verifier"] SANIT["Sanitizer"] end subgraph SANDBOX["Docker Sandbox — Kali Linux"] TSRV["Tool Server :48081"] TOOLS["30+ Security Tools"] BROWSER["Playwright · Chromium"] PROXY["Caido Proxy :48080"] end subgraph OUTPUT["Output Pipeline"] REPORTS["JSON · MD · HTML"] GRAPH["Attack Graph"] MITRE["MITRE ATT&CK Map"] end USER --> IFACE IFACE --> ORCH ORCH --> AGENT AGENT <--> SEC SEC --> SANDBOX AGENT --> OUTPUT style IFACE fill:#6c5ce7,stroke:#a29bfe,color:#ffffff style ORCH fill:#00b894,stroke:#55efc4,color:#ffffff style AGENT fill:#e17055,stroke:#fab1a0,color:#ffffff style SEC fill:#d63031,stroke:#ff7675,color:#ffffff style SANDBOX fill:#0984e3,stroke:#74b9ff,color:#ffffff style OUTPUT fill:#f9ca24,stroke:#f0932b,color:#2d3436 ```
② 扫描执行流程 —— 分阶段
``` %%{init: {"theme": "dark"}}%% sequenceDiagram actor User participant CLI as Phantom CLI participant Orch as Orchestrator participant Agent as Agent ReAct participant FW as Tool Firewall participant Box as Docker Sandbox participant LLM as LLM Provider participant T as Target App User->>CLI: phantom scan -t https://app.com CLI->>Orch: Validate scope · init cost controller Orch->>Box: Spin up ephemeral Kali container Orch->>Agent: Begin scan · profile + scope injected rect rgb(48, 25, 80) Note over Agent,LLM: Phase 1 — Reconnaissance Agent->>LLM: Analyze target · plan recon LLM-->>Agent: Run katana · httpx · nmap Agent->>FW: Validate tool call FW-->>Agent: Approved Agent->>Box: Execute recon tools Box->>T: HTTP probes · port scans · crawl T-->>Box: Responses Box-->>Agent: Endpoints · tech stack · open ports end rect rgb(80, 20, 20) Note over Agent,LLM: Phase 2 — Exploitation Agent->>LLM: Hypothesize attack vectors LLM-->>Agent: SQLi on /api/login · XSS on /search Agent->>Box: sqlmap · custom payload injection Box->>T: Exploit attempts T-->>Box: Vulnerability confirmed Box-->>Agent: Raw HTTP evidence end rect rgb(15, 60, 30) Note over Agent,LLM: Phase 3 — Verification Agent->>Box: Re-exploit with clean PoC script Box->>T: Reproduce exact attack T-->>Box: Confirmed Agent->>Agent: CVSS 3.1 · CWE tag · MITRE map end Agent->>CLI: Findings compiled CLI->>User: Vulnerabilities + PoCs + Compliance CLI->>Box: Destroy container ```
③ Agent ReAct 循环 —— 决策周期
``` %%{init: {"theme": "dark"}}%% flowchart LR INIT(["Scan Start"]) OBS["Observe\nCollect results"] THINK["Reason\nAnalyze context"] PLAN["Plan\nChoose tool"] ACT["Act\nBuild arguments"] FW{"Firewall?"} EXEC["Execute\nDocker sandbox"] DONE{"Stop\nCondition?"} VERIFY["Verify\nRe-test findings"] ENRICH["Enrich\nMITRE · CVSS"] REPORT["Report\nJSON · HTML · MD"] FINISH(["Scan Complete ☠"]) INIT --> OBS OBS --> THINK THINK --> PLAN PLAN --> ACT ACT --> FW FW -- "✓ Pass" --> EXEC FW -- "✗ Block" --> THINK EXEC --> OBS OBS --> DONE DONE -- "Continue" --> THINK DONE -- "Done" --> VERIFY VERIFY --> ENRICH ENRICH --> REPORT REPORT --> FINISH style INIT fill:#6c5ce7,stroke:#a29bfe,color:#fff style FINISH fill:#6c5ce7,stroke:#a29bfe,color:#fff style FW fill:#d63031,stroke:#ff7675,color:#fff style DONE fill:#e17055,stroke:#fab1a0,color:#fff style EXEC fill:#0984e3,stroke:#74b9ff,color:#fff style REPORT fill:#00b894,stroke:#55efc4,color:#fff ```
④ Docker 沙箱 —— 隔离架构
``` %%{init: {"theme": "dark"}}%% flowchart LR HOST(["Phantom Agent\nHost Machine"]) subgraph CONTAINER["Kali Linux Container — Network Isolated"] TSRV["Tool Server :48081"] PROXY["Caido Proxy :48080"] subgraph TOOLKIT["Security Toolkit"] SCA["nmap · masscan"] INJ["sqlmap · nuclei"] FUZ["ffuf · gobuster · arjun"] WEB["httpx · katana"] ANA["nikto · semgrep"] end subgraph RUNTIME["Runtime Environment"] PY["Python 3.12"] BR["Playwright + Chromium"] SH["Bash Shell"] end end TARGET(["Target\nApplication"]) HOST -- "Authenticated API" --> TSRV TSRV --> TOOLKIT TSRV --> RUNTIME PROXY -- "Intercept + Log" --> TARGET TOOLKIT -- "Attack traffic" --> TARGET RUNTIME -- "Browser sessions" --> TARGET style CONTAINER fill:#0984e3,stroke:#74b9ff,color:#ffffff style TOOLKIT fill:#d63031,stroke:#ff7675,color:#ffffff style RUNTIME fill:#6c5ce7,stroke:#a29bfe,color:#ffffff style HOST fill:#2d3436,stroke:#636e72,color:#dfe6e9 style TARGET fill:#2d3436,stroke:#636e72,color:#dfe6e9 ```
⑤ 7 层防御模型 —— 请求生命周期
``` %%{init: {"theme": "dark"}}%% flowchart TD REQ(["Incoming Request"]) L1["① Scope Validator\nTarget allowlist · SSRF protection"] L2["② Tool Firewall\nArg sanitization · Injection block"] L3["③ Docker Sandbox\nEphemeral Kali · Restricted Linux caps"] L4["④ Cost Controller\nPer-request ceiling · Budget cap"] L5["⑤ Time Limiter\nPer-tool timeout · Global scan expiry"] L6["⑥ HMAC Audit Trail\nTamper-evident append-only log"] L7["⑦ Output Sanitizer\nPII redaction · Credential scrubbing"] PASS(["✓ Authorized Output"]) BLOCK(["✗ Blocked & Logged"]) REQ --> L1 L1 -- "✓ In scope" --> L2 L1 -- "✗ Out of scope" --> BLOCK L2 -- "✓ Safe" --> L3 L2 -- "✗ Injection" --> BLOCK L3 --> L4 L4 -- "✓ Within budget" --> L5 L4 -- "✗ Over budget" --> BLOCK L5 -- "✓ In time" --> L6 L5 -- "✗ Timeout" --> BLOCK L6 --> L7 L7 --> PASS style REQ fill:#6c5ce7,stroke:#a29bfe,color:#fff style PASS fill:#00b894,stroke:#55efc4,color:#fff style BLOCK fill:#d63031,stroke:#ff7675,color:#fff style L1 fill:#2d3436,stroke:#636e72,color:#dfe6e9 style L2 fill:#2d3436,stroke:#636e72,color:#dfe6e9 style L3 fill:#2d3436,stroke:#636e72,color:#dfe6e9 style L4 fill:#2d3436,stroke:#636e72,color:#dfe6e9 style L5 fill:#2d3436,stroke:#636e72,color:#dfe6e9 style L6 fill:#2d3436,stroke:#636e72,color:#dfe6e9 style L7 fill:#2d3436,stroke:#636e72,color:#dfe6e9 ```
环境变量
| 变量 | 描述 | 默认值 | |----------|-------------|---------| | `PHANTOM_LLM` | LLM 模型(LiteLLM 格式) | `openai/gpt-4o` | | `LLM_API_KEY` | API 密钥 —— 逗号分隔以用于轮换 | — | | `PHANTOM_REASONING_EFFORT` | `low` / `medium` / `high` | `high` | | `PHANTOM_SCAN_MODE` | 默认扫描配置 | `standard` | | `PHANTOM_IMAGE` | 沙箱 Docker 镜像 | `ghcr.io/usta0x001/phantom-sandbox:latest` | | `PHANTOM_MAX_COST` | 每次扫描的最大总成本(USD) | `25.0` | | `PHANTOM_PER_REQUEST_CEILING` | 每次 LLM 请求的最大成本(USD) | `5.0` | | `PHANTOM_WEBHOOK_URL` | 用于严重警报的 Webhook URL | — | | `PHANTOM_DISABLE_BROWSER` | 禁用 Playwright 浏览器 | `false` | | `PHANTOM_TELEMETRY` | 启用匿名使用遥测 | `true` |支持的 LLM 提供商
Phantom 使用 [LiteLLM](https://github.com/BerriAI/litellm) —— 100+ 提供商开箱即用: | Provider | Example Model | Notes | |----------|--------------|-------| | **OpenAI** | `openai/gpt-4o` | 最佳整体质量 | | **Anthropic** | `anthropic/claude-opus-4-5` | 强大的多步推理能力 | | **Google** | `gemini/gemini-2.5-pro` | 超大上下文窗口 | | **Groq** | `groq/llama-3.3-70b-versatile` | 免费层,速度极快 | | **DeepSeek** | `deepseek/deepseek-chat` | 极佳的成本效益 | | **OpenRouter** | `openrouter/deepseek/deepseek-v3.2` | 多提供商路由 | | **Ollama** | `ollama/llama3.1` | 完全本地 —— 无需 API 密钥 | | **Azure OpenAI** | `azure/gpt-4o` | 企业级部署 |
**☠ PHANTOM** — *自主对抗模拟平台*
[PyPI](https://pypi.org/project/phantom-agent/) · [GitHub](https://github.com/Usta0x001/Phantom) · [Issues](https://github.com/Usta0x001/Phantom/issues) · 由 [Usta0x001](https://github.com/Usta0x001) 制作
标签:AI安全, Apache 2.0, Chat Copilot, CISA项目, DLL 劫持, Docker沙箱, LNA, PE 加载器, PyRIT, Python, ReAct, Web报告查看器, Whitebox, 多智能体系统, 大语言模型, 安全工具集合, 安全测试, 安全测试, 密码管理, 对手模拟, 攻击性安全, 攻击性安全, 数据展示, 无后门, 概念验证, 漏洞报告, 特征检测, 红队, 网络安全, 自主侦察, 自动化渗透测试, 请求拦截, 逆向工具, 隐私保护