BouaradaHoussem/h-ploit

GitHub: BouaradaHoussem/h-ploit

一个基于 LangGraph 和 MCP 的自主多智能体渗透测试框架,将 14 个专职 agent 串联完成从侦察到报告的全流程安全评估,并通过 LLM 驱动决策与漏洞自动验证来降低误报率。

Stars: 0 | Forks: 0

# h-ploit **自主多智能体渗透测试框架** ![Python](https://img.shields.io/badge/python-3.11%2B-3776AB?logo=python&logoColor=white) ![License](https://img.shields.io/badge/license-MIT-22c55e) ![Tests](https://img.shields.io/badge/tests-378%20passing-brightgreen) ![Orchestration](https://img.shields.io/badge/LangGraph-MCP-8b5cf6)
## h-ploit 是什么? h-ploit 是一个自主的渗透测试框架,它将 **14 个专门的 agent** 链接到一个单一的 LangGraph pipeline 中,每个 agent 都通过 **Model Context Protocol (MCP)** 封装了一个真实的攻击性工具。它运行的正是人类测试员会执行的工作流程——侦察、凭证测试、爬取、注入测试、CVE 扫描、漏洞利用*验证*以及报告——并使用 LLM (Groq `llama-3.3-70b`) 来进行判断决策:优先级排序、目标选择、发现分类和攻击链关联。每一个报告的漏洞都会被重新利用,以产生具体的证据和可直接复制粘贴的复现命令。它已经在 DVWA、Metasploitable 2 以及(在被动/授权模式下)真实的漏洞赏金范围内经过了实战检验。 ## 架构 ``` Target │ ┌───────────────────────▼───────────────────────┐ │ Recon nmap · amass · subfinder · crt.sh │ + WAF/CDN fingerprint └───────────────────────┬───────────────────────┘ ┌───────────────────────▼───────────────────────┐ │ Supervisor LLM prioritization (Groq) │ └───────────────────────┬───────────────────────┘ ┌───────────────────────▼───────────────────────┐ │ Creds hydra · ftplib · HTTP form replay │ (skipped behind WAF) └───────────────────────┬───────────────────────┘ ┌───────────────────────▼───────────────────────┐ │ Web httpx — live endpoints │ (CDN edge IPs filtered) └───────────────────────┬───────────────────────┘ ┌───────────────────────▼───────────────────────┐ │ Crawl katana — deep crawl + forms │ └───────────────────────┬───────────────────────┘ ┌───────────────────────▼───────────────────────┐ │ JS JS endpoint + GraphQL extraction │ └───────────────────────┬───────────────────────┘ ┌───────────────────────▼───────────────────────┐ │ XSS · LFI · CMDi dalfox / traversal / cmdi │ └───────────────────────┬───────────────────────┘ ┌───────────────────────▼───────────────────────┐ │ Nuclei LLM-selected targets · CVE scan │ └───────────────────────┬───────────────────────┘ ┌───────────────────────▼───────────────────────┐ │ Exploitation validation + PoC (curl) evidence │ └───────────────────────┬───────────────────────┘ ┌───────────────────────▼───────────────────────┐ │ Fuzz ffuf — directory discovery │ (WAF-aware wordlist) └───────────────────────┬───────────────────────┘ ┌───────────────────────▼───────────────────────┐ │ API sqlmap — SQL injection │ └───────────────────────┬───────────────────────┘ ┌───────────────────────▼───────────────────────┐ │ Correlation LLM attack-chain analysis │ └───────────────────────┬───────────────────────┘ ┌───────────────────────▼───────────────────────┐ │ Report Markdown + JSON · OWASP mapped │ └────────────────────────────────────────────────┘ ``` 工具节点是**确定性的** —— LLM 从不发出工具调用,因此该 pipeline 对格式错误的工具调用 bug 免疫。LLM 仅在它*读取*结果并返回分析的地方使用(主管、目标选择、发现分类、关联、执行摘要),并且每个 LLM 步骤都有基于规则的回退机制,因此该框架在没有 API key 的情况下也能完全运行。 ## 功能 - ✅ **14 个 agent 的 LangGraph pipeline**,基于共享的类型化状态对象 - ✅ **9 个 MCP server** 封装了真实的攻击性工具(argv 安全、有界限、标准库解析) - ✅ **LLM 驱动的决策** —— 优先级排序、nuclei/ffuf 目标选择、发现分类、攻击链关联(Groq `llama-3.3-70b`,确定性回退机制) - ✅ **注入覆盖** —— 反射型/DOM XSS、LFI/路径遍历、命令注入、SQL 注入(GET 参数**和** POST 表单) - ✅ **自动验证** —— 每个发现都被重新利用转化为具体证据(文件内容、`uid=` 输出、枚举的表)以及可复制粘贴的 `curl` PoC - ✅ **WAF/CDN 检测** —— Cloudflare、Akamai、Fastly、CloudFront、Imperva;攻击性工具会自动退避 - ✅ **子域名枚举** —— amass + subfinder + crt.sh,去重并合并 - ✅ **漏洞赏金模式** —— CDN-edge-IP 过滤、LLM 目标选择、WAF 感知模糊测试,以及针对公开域名的“漏洞赏金快速摘要” - ✅ **专业报告** —— Markdown + 机器可读的 JSON,映射 OWASP Top 10,包含修复和复现步骤 - ✅ **PostgreSQL 持久化** —— 任务在重启后依然保留;完整的运行历史记录 - ✅ **React dashboard** —— 实时显示每个 agent 的进度和严重程度细分 - ✅ **FastAPI 后端** —— 用于启动任务和获取报告的 REST API ## 演示 针对 Metasploitable 2 / mutillidae 目标运行: ``` $ python orchestrator.py 172.20.0.20 [✓] recon — 1 host, 6 open port(s), 0 subdomain(s) [✓] supervisor — prioritized: probe web services first (largest attack surface) [✓] web — 3 live web endpoint(s) [✓] crawl — 27 URL(s), 6 form(s) (2 POST) [✓] xss — 4 XSS finding(s) [✓] lfi — 2 LFI finding(s) [✓] cmdi — 1 CMDi finding(s) [✓] nuclei — 10 raw match(es) -> 8 actionable after filter [✓] exploitation — 5 CONFIRMED finding(s) [✓] report — 37 finding(s) -> reports/172.20.0.20_20260707_142013.md ``` 生成的报告摘录 —— **已验证**的发现包含真实的证据和可运行的 PoC: ``` ## 已验证的发现 (5) ### V-1: 通过 'page' 的 LFI / path traversal [Critical] — 已确认 - Location: `http://172.20.0.20/mutillidae/index.php` - Evidence: Successfully read /etc/passwd: root:x:0:0:root:/root:/bin/bash | daemon:x:1:1:... - Reproduction: curl -sk 'http://172.20.0.20/mutillidae/index.php?page=../../../etc/passwd' curl -sk 'http://172.20.0.20/mutillidae/index.php?page=../../../etc/passwd' | grep 'root:x:0:0' ### V-2: 通过 'target_host' 的 Command injection [Critical] — 已确认 - Evidence: Command executed: uid=33(www-data) gid=33(www-data) groups=33(www-data) - Reproduction: curl -sk 'http://172.20.0.20/mutillidae/index.php?page=dns-lookup.php' \ --data 'target_host=127.0.0.1; id&dns-lookup-php-submit-button=Lookup+DNS' ``` **严重程度摘要:** 2 个严重 · 10 个高危 · 5 个中危 · 20 个信息 —— 通过重新利用排除了误报。 ## 快速开始 ### 1. 安装 ``` git clone https://github.com/h-ploit/h-ploit.git && cd h-ploit python3 -m venv venv && source venv/bin/activate pip install -r requirements.txt ``` ### 2. 外部工具(必须在 `PATH` 中) ``` sudo apt install nmap hydra sqlmap amass # system packages go install github.com/projectdiscovery/httpx/cmd/httpx@latest go install github.com/projectdiscovery/katana/cmd/katana@latest go install github.com/projectdiscovery/nuclei/v3/cmd/nuclei@latest go install github.com/projectdiscovery/subfinder/v2/cmd/subfinder@latest go install github.com/ffuf/ffuf/v2@latest go install github.com/hahwul/dalfox/v2@latest ``` ### 3. 配置(可选) ``` export GROQ_API_KEY=... # enables LLM decisions (falls back to rules if unset) export DATABASE_URL=postgresql+asyncpg://pentest:pentest@localhost:5434/pentestdb ``` ### 4. 运行 ``` # CLI — 单个目标,streamed 到 console python orchestrator.py 172.20.0.20 # API + UI uvicorn backend.main:app --reload --port 8000 # backend cd frontend && npm install && npm run dev # dashboard on :5173 ``` ### 5. 调试任何阶段 ``` PENTEST_DEBUG=1 python orchestrator.py # or per-stage: RECON_DEBUG, NUCLEI_DEBUG, ... ``` ## 工具与 MCP Server | 工具 | 集成方式 | 用途 | | --- | --- | --- | | **nmap** | MCP server | 端口/服务发现 | | **httpx** | MCP server | 实时 HTTP(S) endpoint 检测 | | **katana** | MCP server | 深度爬取 + 表单提取 | | **ffuf** | MCP server | 目录/内容发现 | | **dalfox** | MCP server | 反射型/DOM XSS | | **sqlmap** | MCP server | SQL 注入 (GET + POST) | | **nuclei** | MCP server | CVE 与错误配置模板 | | **amass** | MCP server | 被动子域名枚举 | | **subfinder** | MCP server | 被动子域名枚举 | | **hydra** | agent (subprocess) | 凭证暴力破解 | | **crt.sh** | agent (HTTP) | 证书透明度子域名 | 每个 MCP server 都是有界限的(针对每个目标和总时间设限),以 `argv` 形式传递参数(从不通过 shell),并且仅返回结构化的、已解析的信号。 ## 实验室设置 ``` # DVWA — web 应用程序漏洞 docker run -d --name dvwa -p 8080:80 vulnerables/web-dvwa python orchestrator.py http://127.0.0.1:8080 # Metasploitable 2 — 完整的 vulnerable host (mutillidae, exposed services) docker run -d --name metasploitable -p 80:80 tleemcjr/metasploitable2 python orchestrator.py 127.0.0.1 ``` ## 报告结构 每次运行都会生成一份 Markdown 报告 (`reports/_.md`) 以及一份包含原始发现的机器可读 JSON 导出文件。 | # | 章节 | 内容 | | --- | --- | --- | | 1 | **标头** | 目标、时间戳、工具、授权声明 | | 2 | **执行摘要** | 通俗语言的风险摘要(LLM 或确定性生成) | | 3 | **主管优先级** | 运行的重点及其原因 | | 4 | **观察到的范围** | 开放端口、在线 endpoint、子域名 | | 5 | **严重程度摘要** | 所有类别的汇总计数 | | 6 | **攻击链** | LLM 关联的多步骤攻击链,最危险的排在最前 | | 7 | **凭证发现** | 可用的默认/弱凭证(服务、主机、严重程度) | | 8 | **已验证的发现** | 带有证据和 `curl` 复现的重新利用发现 | | 9 | **XSS 发现** | 带有 URL、参数、payload 的反射型/DOM XSS | | 10 | **LFI/路径遍历** | 带有提取证据的文件读取发现 | | 11 | **命令注入** | 基于输出和基于时间的盲注,附带证据 | | 12 | **GraphQL** | Introspection 状态 + schema 暴露(如果存在) | | 13 | **按严重程度分类的发现** | 扫描器发现,标记 OWASP,限制信息数量 | | 14 | **附录** | 运行的确切工具命令 | 公共域名目标还会在顶部获得一份额外的 **漏洞赏金快速摘要**:发现/在线的子域名、发现的 JS 与 API endpoint、WAF 状态,以及推荐的手动测试重点列表。 ## OWASP Top 10 (2021) 覆盖范围 客观的范围 —— h-ploit 专注于可外部测试、可自动化的类别。 | 类别 | 覆盖率 | 提供者 | | --- | --- | --- | | A01 · 失效的访问控制 | 🟡 部分 | LFI/路径遍历 | | A02 · 加密机制失效 | 🔴 无 | — | | A03 · 注入 | 🟢 强 | XSS, SQLi, 命令注入 | | A04 · 不安全的设计 | 🔴 无 | (需要人工审查)| | A05 · 安全配置错误 | 🟢 强 | nuclei、暴露、内容发现 | | A06 · 易受攻击和过时的组件 | 🟡 部分 | nuclei CVE 模板 | | A07 · 身份识别和认证失效 | 🟢 强 | 默认凭证测试 | | A08 · 软件和数据完整性失效 | 🔴 无 | — | | A09 · 安全日志和监控失效 | 🔴 无 | (外部无法观察)| | A10 · 服务端请求伪造 (SSRF) | 🟡 部分 | nuclei SSRF 模板 | ## 技术栈 | 层 | 技术 | | --- | --- | | 编排 | LangGraph(有状态多智能体图)| | 工具协议 | Model Context Protocol (MCP),stdio 传输 | | LLM | Groq `llama-3.3-70b-versatile` (可选) | | 后端 | FastAPI,异步 SQLAlchemy + asyncpg | | 持久化 | PostgreSQL(JSONB 发现、任务历史记录)| | 前端 | React + Vite(实时 agent dashboard)| | 测试 | pytest — 378 个离线测试 | ## 免责声明 h-ploit 是一款**主动式**安全测试工具,会执行侵入性操作(端口扫描、凭证测试、注入、漏洞利用验证)。它仅用于**已授权的**安全评估:您拥有的系统、实验室环境,或明确在允许自动化测试的书面委托或漏洞赏金计划范围内的目标。 未经授权对您不拥有或无权测试的系统进行使用可能是**违法的**,并由用户承担全部责任。作者对滥用或因本软件造成的任何损害概不负责。被动侦察(通过公共 OSINT 进行子域名枚举)与主动利用截然不同 —— 后者绝不能在授权范围之外运行。 **许可证:** MIT。
标签:AI智能体, CISA项目, DLL 劫持, 多智能体协同, 大语言模型, 实时处理, 密码管理, 测试用例, 运行时操纵