tomocchi1029/attack-chain-reconstructor
GitHub: tomocchi1029/attack-chain-reconstructor
利用 LLM 推理将多个漏洞扫描器的离散漏洞发现关联重构为完整攻击链,并重新评估组合风险。
Stars: 0 | Forks: 0
# 攻击链重构器
[](https://www.python.org/downloads/)
[](LICENSE)
## 为什么?
现代漏洞扫描器(Semgrep、CodeQL、Trivy、npm audit 等)会生成**单个漏洞发现的列表**。但攻击者不以列表的方式思考——他们以**攻击链**的方式思考:
**Attack Chain Reconstructor** 接收单个漏洞发现,并利用 LLM 推理来:
1. **识别可组合的漏洞** —— 哪些发现可以组合在一起?
2. **构建攻击图** —— 可视化多步骤的漏洞利用路径
3. **生成攻击场景** —— 逐步的漏洞利用叙述
4. **重新评估严重性** —— 一个“Low”+“Medium”可能会组合成“Critical”
## 快速开始
```
pip install attack-chain-reconstructor
# 来自 Semgrep JSON 输出
acr scan --input semgrep-results.json --format json -o report.md
# 来自 Trivy
trivy fs --format json . > trivy.json
acr scan --input trivy.json --format json -o report.md
# 来自多个扫描器
acr scan --input semgrep.json,trivy.json,codeql.sarif -o report.md
```
## 示例输出
```
## 攻击链 #1:Admin Account Takeover (Critical)
**Chain**: IDOR-001 → Info-Leak-003 → SSRF-002 → Auth-Bypass-004
### 步骤 1:利用 IDOR-001 (Medium)
The `/api/users/{id}` endpoint lacks authorization checks. An attacker can
iterate over user IDs to retrieve arbitrary user profiles, including internal
session metadata fields (`session_token_hash`).
### 步骤 2:结合 Info-Leak-003 (Low)
Verbose error responses in `/api/debug` leak the hashing algorithm used
for session tokens (HMAC-SHA256 with a weak key derived from app config).
### 步骤 3:利用 SSRF-002 (High)
The image proxy endpoint accepts arbitrary URLs. Using the leaked session
token hash, the attacker can craft requests to internal admin endpoints
via SSRF, bypassing the external firewall.
### 步骤 4:Auth-Bypass-004 (Medium)
The admin panel trusts the `X-Internal-Auth` header, which can be set
through the SSRF proxy chain. Full admin access achieved.
### 影响
Complete administrative access to the application, including ability to
modify all user data, access billing information, and pivot to internal
services.
### 修复建议
1. Add authorization checks to `/api/users/{id}` (fixes Step 1)
2. Disable verbose error responses in production (fixes Step 2)
3. Restrict SSRF target to allowlisted domains (fixes Step 3)
```
## 攻击图可视化
```
graph LR
A[IDOR-001
Medium] --> B[Info-Leak-003
Low] B --> C[SSRF-002
High] C --> D[Auth-Bypass-004
Medium] D --> E[🔥 Admin Access
Critical] style E fill:#ff4444,color:#fff ``` ## 支持的输入格式 | 扫描器 | 格式 | 状态 | |---------|--------|--------| | Semgrep | JSON | ✅ | | Trivy | JSON | ✅ | | CodeQL | SARIF | ✅ | | npm audit | JSON | ✅ | | pip-audit | JSON | ✅ | | Gitleaks | JSON | ✅ | | 自定义 | JSON (见 schema) | ✅ | ## 配置 ``` # .acr.yml llm: provider: openai # or anthropic, glm, ollama model: glm-4.6 api_key: ${LLM_API_KEY} analysis: max_chain_length: 6 # maximum steps in a chain min_confidence: 0.6 # minimum confidence score (0-1) include_low_severity: true # include Low findings in chain analysis output: format: markdown # markdown, json, html include_graph: true # include Mermaid attack graph include_fixes: true # include remediation suggestions ``` ## 工作原理 ``` ┌─────────────┐ ┌──────────────┐ ┌─────────────┐ ┌────────────┐ │ Scanner │────▶│ Finding │────▶│ LLM Chain │────▶│ Report │ │ Results │ │ Normalizer │ │ Analyzer │ │ Generator │ │ (JSON/SARIF)│ │ (unified │ │ (GLM/GPT/ │ │ (Markdown/│ │ │ │ schema) │ │ Claude) │ │ HTML) │ └─────────────┘ └──────────────┘ └─────────────┘ └────────────┘ │ ┌───────────────────────┐ │ 1. Link findings │ │ 2. Build graph │ │ 3. Generate scenarios │ │ 4. Re-assess severity │ └───────────────────────┘ ``` ## 安装说明 (开发) ``` git clone https://github.com/yourusername/attack-chain-reconstructor.git cd attack-chain-reconstructor pip install -e ".[dev]" pytest ``` ## 许可证 MIT
Medium] --> B[Info-Leak-003
Low] B --> C[SSRF-002
High] C --> D[Auth-Bypass-004
Medium] D --> E[🔥 Admin Access
Critical] style E fill:#ff4444,color:#fff ``` ## 支持的输入格式 | 扫描器 | 格式 | 状态 | |---------|--------|--------| | Semgrep | JSON | ✅ | | Trivy | JSON | ✅ | | CodeQL | SARIF | ✅ | | npm audit | JSON | ✅ | | pip-audit | JSON | ✅ | | Gitleaks | JSON | ✅ | | 自定义 | JSON (见 schema) | ✅ | ## 配置 ``` # .acr.yml llm: provider: openai # or anthropic, glm, ollama model: glm-4.6 api_key: ${LLM_API_KEY} analysis: max_chain_length: 6 # maximum steps in a chain min_confidence: 0.6 # minimum confidence score (0-1) include_low_severity: true # include Low findings in chain analysis output: format: markdown # markdown, json, html include_graph: true # include Mermaid attack graph include_fixes: true # include remediation suggestions ``` ## 工作原理 ``` ┌─────────────┐ ┌──────────────┐ ┌─────────────┐ ┌────────────┐ │ Scanner │────▶│ Finding │────▶│ LLM Chain │────▶│ Report │ │ Results │ │ Normalizer │ │ Analyzer │ │ Generator │ │ (JSON/SARIF)│ │ (unified │ │ (GLM/GPT/ │ │ (Markdown/│ │ │ │ schema) │ │ Claude) │ │ HTML) │ └─────────────┘ └──────────────┘ └─────────────┘ └────────────┘ │ ┌───────────────────────┐ │ 1. Link findings │ │ 2. Build graph │ │ 3. Generate scenarios │ │ 4. Re-assess severity │ └───────────────────────┘ ``` ## 安装说明 (开发) ``` git clone https://github.com/yourusername/attack-chain-reconstructor.git cd attack-chain-reconstructor pip install -e ".[dev]" pytest ``` ## 许可证 MIT
标签:AI风险缓解, DLL 劫持, GPT, Petitpotam, Python, 大语言模型, 攻击图, 无后门, 漏洞管理, 自动化分析, 跨站脚本, 逆向工具