Usta0x001/Phantom

GitHub: Usta0x001/Phantom

一个基于 ReAct 循环的 AI 原生自主渗透测试平台,利用大模型推理串联安全工具,在隔离沙箱中完成从侦察到漏洞验证的全流程自动化。

Stars: 100 | Forks: 7


# ☠ PHANTOM ### 自主对抗模拟平台 *AI 原生渗透测试 —— 自主侦察、漏洞利用与结果验证。*
[![PyPI](https://img.shields.io/pypi/v/phantom-agent?style=for-the-badge&logo=pypi&logoColor=white&label=phantom-agent&color=6c5ce7)](https://pypi.org/project/phantom-agent/) [![Python](https://img.shields.io/badge/Python-3.12+-3776AB?style=for-the-badge&logo=python&logoColor=white)](https://python.org) [![License](https://img.shields.io/badge/License-Apache%202.0-4DB6AC?style=for-the-badge)](LICENSE) [![Docker](https://img.shields.io/badge/Docker-Sandbox-2496ED?style=for-the-badge&logo=docker&logoColor=white)](#architecture) [![Tests](https://img.shields.io/badge/Tests-731%20Passing-2ECC71?style=for-the-badge&logo=pytest&logoColor=white)](#testing) [![Bugs Fixed](https://img.shields.io/badge/Bugs%20Fixed-88-E74C3C?style=for-the-badge)](#security-audit) [![Status](https://img.shields.io/badge/Status-Beta-F39C12?style=for-the-badge)](#) [![Platform](https://img.shields.io/badge/Platform-Linux%20|%20macOS%20|%20Windows-555555?style=for-the-badge&logo=linux&logoColor=white)](#quick-start)
[**快速开始**](#quick-start)  ·  [**架构**](#architecture)  ·  [**使用**](#usage)  ·  [**配置**](#configuration)  ·  [**贡献**](#contributing)
## 概述 Phantom 是一个基于 ReAct(推理-行动)循环构建的 **自主 AI 渗透测试 Agent**。它将大型语言模型连接到 30 多种专业安全工具,在隔离的 Docker 沙箱中运行所有攻击操作,并生成经过验证的漏洞报告 —— 全程无需人工干预。 与 CVE 特征扫描器不同,Phantom 会对目标进行 **推理**:它读取 HTTP 响应,形成假设,选择合适的工具,链接多步骤攻击,然后编写并执行 PoC 脚本,在每项发现出现在报告中之前对其进行确认。 | | 传统扫描器 | **Phantom** | |--|--|--| | **方法** | 针对 CVE 数据库的特征匹配 | LLM 推理 + 自适应工具链 | | **误报** | 40–70% —— 需要人工分类 | 每项发现均通过可工作的 PoC 验证 | | **深度** | 单次 HTTP 探测 | 多阶段:侦察 → 利用 → 验证 | | **适应性** | 固定规则,静态 Payload | 实时适应目标响应 | | **新漏洞** | 仅限已知 CVE | 逻辑缺陷 + 新型攻击路径 | | **报告** | 通用漏洞列表 | 映射 MITRE ATT&CK,符合合规要求 | ## 核心能力
🧠 自主 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 ```
## 快速开始 **要求:** Docker · Python 3.12+ · LLM API 密钥 ``` # 安装 pip install phantom-agent # 或完全隔离安装: pipx install phantom-agent # 设置你的 LLM export PHANTOM_LLM="openai/gpt-4o" # any LiteLLM-supported model export LLM_API_KEY="sk-..." # 运行你的首次扫描 phantom scan --target https://your-app.com ``` ### 通过 Docker ``` docker run --rm -it \ -e PHANTOM_LLM="openai/gpt-4o" \ -e LLM_API_KEY="your-key" \ -v /var/run/docker.sock:/var/run/docker.sock \ ghcr.io/usta0x001/phantom:latest \ scan --target https://your-app.com ``` ## 使用方法 ``` # 快速扫描(~15 分钟)— CI/CD 友好 phantom scan -t https://app.com -m quick # 标准扫描(~45 分钟)— 推荐默认值 phantom scan -t https://app.com # 深度扫描(1–3 小时)— 详尽覆盖 phantom scan -t https://app.com -m deep # 隐蔽模式 — 低噪声,WAF/IDS 规避 phantom scan -t https://app.com -m stealth # 仅 API — REST/GraphQL,无浏览器 phantom scan -t https://api.app.com -m api_only # Focus 指令 phantom scan -t https://app.com \ --instruction "Focus on SQL injection and broken auth in /api/v2" # 恢复中断的扫描 phantom scan -t https://app.com --resume # 交互式 TUI phantom -t https://app.com # 非交互式(CI/CD pipelines) phantom scan -t https://app.com --non-interactive # 设置成本上限 PHANTOM_MAX_COST=2.00 phantom scan -t https://app.com ``` ### 扫描配置 | Profile | 最大迭代次数 | 典型持续时间 | 最适用于 | |---------|:--------------:|:----------------:|----------| | `quick` | 50 | ~15 分钟 | CI/CD 门禁,快速分类 | | `standard` | 120 | ~45 分钟 | 常规安全测试 | | `deep` | 300 | 1–3 小时 | 全面审计,合规性 | | `stealth` | 60 | ~30 分钟 | 生产系统,IDS 规避 | | `api_only` | 100 | ~45 分钟 | REST/GraphQL APIs | ### 输出 每次扫描生成: ``` phantom_runs/_/ ├── vulnerabilities/ │ ├── vuln-0001.md # Full finding with PoC exploit │ └── vuln-0002.md ├── audit.jsonl # HMAC-signed immutable event log ├── scan_stats.json # Cost, tokens, timing metrics ├── enhanced_state.json # Full scan state snapshot └── vulnerabilities.csv # Summary index for triage ``` ### 扫描后丰富化管道 每次扫描自动运行 7 个阶段的丰富化处理: | 阶段 | 动作 | |-------|--------| | 1. MITRE ATT&CK | CWE, CAPEC, 技术级标记 | | 2. 合规性 | OWASP Top 10 · PCI DSS v4 · NIST 800-53 | | 3. 攻击图 | NetworkX 路径分析 | | 4. Nuclei 模板 | 自动生成用于回归测试的 YAML | | 5. 知识库 | 更新持久化跨扫描内存 | | 6. 通知 | 针对关键发现的 Webhook / Slack 警报 | | 7. 报告 | JSON + HTML + Markdown 输出 | ## CI/CD 集成 ``` # .github/workflows/security.yml name: Security Scan on: push: branches: [main] schedule: - cron: '0 2 * * 1' # Weekly — Monday at 2 AM jobs: phantom-scan: runs-on: ubuntu-latest steps: - name: Run Phantom run: | pip install phantom-agent phantom scan \ --target ${{ vars.STAGING_URL }} \ --scan-mode quick \ --non-interactive \ --output json env: PHANTOM_LLM: openai/gpt-4o LLM_API_KEY: ${{ secrets.LLM_API_KEY }} PHANTOM_MAX_COST: "1.00" ``` ## 配置
环境变量 | 变量 | 描述 | 默认值 | |----------|-------------|---------| | `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 已在多个版本中通过了广泛的对抗性审计: | 严重程度 | 已识别 | 已修复 | |----------|:----------:|:-----:| | Critical | 8 | 8 | | High | 19 | 19 | | Medium | 34 | 34 | | Low | 27 | 27 | | **总计** | **88** | **88** | 所有 88 个已识别问题均已解决。完整历史记录请参见 [CHANGELOG.md](CHANGELOG.md)。 ## 测试 ``` # 运行完整测试套件 pytest tests/ -v # 含覆盖率报告 pytest tests/ --cov=phantom --cov-report=html # 运行特定类别 pytest tests/ -m "security" pytest tests/ -m "integration" ``` 当前状态:**731 个测试通过 · 0 个失败 · 97 个跳过** ## 文档 | 资源 | 描述 | |----------|-------------| | [架构](docs/ARCHITECTURE.md) | 深入系统设计 | | [文档](docs/DOCUMENTATION.md) | 完整 API 和配置参考 | | [贡献](CONTRIBUTING.md) | 开发指南 | | [更新日志](CHANGELOG.md) | 版本历史和发布说明 | ## 贡献 欢迎贡献。设置说明请参见 [CONTRIBUTING.md](CONTRIBUTING.md)。 - **Bugs** → [提交 Issue](https://github.com/Usta0x001/Phantom/issues) - **功能** → [发起讨论](https://github.com/Usta0x001/Phantom/discussions) - **PRs** → Fork · 分支 · 测试 · 提交 ## 许可证 Apache License 2.0 —— 详见 [LICENSE](LICENSE)。 ## 致谢 站在巨人的肩膀上: [LiteLLM](https://github.com/BerriAI/litellm) · [Nuclei](https://github.com/projectdiscovery/nuclei) · [SQLMap](https://github.com/sqlmapproject/sqlmap) · [Playwright](https://github.com/microsoft/playwright) · [Textual](https://github.com/Textualize/textual) · [Rich](https://github.com/Textualize/rich) · [NetworkX](https://github.com/networkx/networkx) · [ffuf](https://github.com/ffuf/ffuf) · [Caido](https://caido.io)
**☠ 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, 多智能体系统, 大语言模型, 安全工具集合, 安全测试, 安全测试, 密码管理, 对手模拟, 攻击性安全, 攻击性安全, 数据展示, 无后门, 概念验证, 漏洞报告, 特征检测, 红队, 网络安全, 自主侦察, 自动化渗透测试, 请求拦截, 逆向工具, 隐私保护