fr33d3m0n/threat-modeling
GitHub: fr33d3m0n/threat-modeling
基于LLM的AI原生威胁建模技能,通过8阶段工作流实现从代码理解到渗透测试计划的自动化安全分析。
Stars: 181 | Forks: 20
# 威胁建模技能 v3.0.3
AI 原生自动化软件风险分析技能。基于 LLM 驱动、代码优先的方法,用于全面的安全风险评估、威胁建模、安全分析、安全审计和渗透测试。
## v3.0.3 新特性
- 全面优化了报告系统 —— 报告现在更详细、更完整,人类可读性显著增强
- 现已支持 HTML 格式报告输出
查看 [CHANGELOG.md](CHANGELOG.md) 获取完整版本历史。
## v3.0.2 新特性
- 重大系统架构重构,提升了安全分析深度和路径覆盖率
- 从下一代 AI 原生渗透测试系统 "Cobweb" 移植了 SM2 状态机,用于深度问题解决
- 增加了多版本任务历史记录和精确的结构化阶段输出,便于 CI/CD 集成
- 优化了上下文工程和数据披露,Token 减少约 35%
查看 [CHANGELOG.md](CHANGELOG.md) 获取完整版本历史。
## 安装
### 选项 1:全局安装(推荐)
```
# 克隆到全局技能目录
git clone https://github.com/fr33d3m0n/threat-modeling.git \
~/.claude/skills/threat-modeling
# 启用钩子(可选,用于自动验证)
cp ~/.claude/skills/threat-modeling/hooks/settings-example.json \
~/.claude/settings.json
```
### 选项 2:项目本地安装
```
# 克隆到项目的 .claude/skills 目录
mkdir -p .claude/skills
git clone https://github.com/fr33d3m0n/threat-modeling.git \
.claude/skills/threat-modeling
```
### 系统要求
- Claude Code CLI
- Python 3.10+
- SQLite3(用于知识库查询)
## 快速开始
1. **启动 Claude Code** 在你的目标项目目录中:
cd /path/to/your/project
claude
2. **调用技能** 使用简单的提示词:
/threat-modeling Perform a complete threat model analysis on @.
3. **遵循 8 阶段工作流** - Claude 将引导你完成每个阶段。
## 使用模式
该技能支持标准 8 阶段工作流之外的 **6 种灵活应用模式**:
### 模式 1:完整工作流(标准)
针对代码库的完整 8 阶段威胁建模。
```
/threat-modeling Perform a complete threat model analysis on @/path/to/project
Project context:
- This is an e-commerce platform backend API service
- Built with Django REST Framework
- User data includes PII and payment information
Focus areas: Authentication mechanisms, payment flow, API security
```
### 模式 2:知识库咨询
作为安全咨询资源使用,无需执行完整工作流。
```
Query complete information for CWE-89 (SQL Injection),
including attack patterns, testing methods, and mitigations
```
**响应包括**:CWE 概述、相关 CAPEC 模式、WSTG 测试步骤、ASVS 要求、缓解示例。
### 模式 3:深度漏洞分析
针对特定漏洞或代码片段的深入分析。
```
Analyze SSRF risk in this code, construct attack path and design POC
[Code snippet]
```
**响应包括**:漏洞机制、攻击路径、POC 设计、CWE/CAPEC/ATT&CK 映射。
### 模式 4:安全测试生成
基于安全标准生成测试用例。
```
Generate WSTG-based security test cases for this API endpoint
```
**响应包括**:身份验证、授权、输入验证、会话管理测试用例及载荷。
### 模式 5:前向集成(设计阶段)
在设计阶段进行预emptive威胁建模,无需等待代码。
```
Conduct STRIDE threat analysis based on this API specification
[OpenAPI specification]
```
**响应包括**:基于 API 端点的 DFD、信任边界、STRIDE 枚举、设计建议。
### 模式 6:后向集成(渗透测试)
为渗透测试提供攻击路径和 POC 设计支持。
```
I found JWT signature verification bypass in the target system,
help construct complete attack chain
```
**响应包括**:漏洞确认、攻击链、POC 载荷、ATT&CK 映射、报告模板。
## 模式选择指南
| 模式 | 输入 | 输出 | 适用场景 |
|------|-------|--------|-------------|
| **完整工作流** | 代码库 | 完整威胁报告 | 开发 / 发布前 |
| **知识库咨询** | 问题 | 知识响应 | 任何阶段 |
| **漏洞分析** | 代码 / 描述 | 攻击路径 + POC | 代码审查 / 渗透测试 |
| **测试生成** | 目标描述 | 测试清单 | 测试阶段 |
| **前向集成** | 设计文档 | 设计阶段分析 | 设计阶段 |
| **后向集成** | 已发现漏洞 | 攻击链 + 计划 | 渗透测试 |
## 命令行标志
| 标志 | 描述 |
|------|-------------|
| `--debug` | 发布内部 YAML 数据文件和评估报告 |
| `--lang=xx` | 设置输出语言 (en, zh, ja, ko, es, fr, de, pt, ru) |
**示例**:
```
/threat-model @my-project # Default mode
/threat-model @my-project --debug # With internal data
/threat-model @my-project --lang=zh --debug # Chinese output with debug
```
## 高级场景(扩展提示词)
除了标准 8 阶段工作流外,使用这些扩展提示词进行更深层次的安全分析:
### 场景 1:完整接口与数据流发现
对所有系统接口进行全面发现和风险分析。
```
/threat-modeling @/path/to/project
Perform complete interface and data flow discovery analysis:
1. Comprehensive discovery of all system interfaces:
- User interaction interfaces (Web UI, CLI, Mobile)
- External APIs (REST, GraphQL, gRPC, WebSocket)
- System interfaces (File system, Database, Message queue)
- Internal services (Microservice calls, RPC, Event bus)
2. Build complete data flow diagram:
- Annotate all data entry and exit points
- Identify sensitive data flow paths
- Mark trust boundary crossing points
3. Risk analysis for each interface:
- Input validation risks
- Authentication/authorization risks
- Data leakage risks
- Injection attack risks
Output format: Complete interface inventory sorted by risk level, with CWE mapping and CVSS scores
```
### 场景 2:攻击树、POC 生成与渗透测试计划
深度攻击链分析,包含漏洞利用 POC 生成和渗透测试计划。
```
/threat-modeling @/path/to/project --debug
Based on discovered security issues, perform deep attack analysis:
1. Attack tree construction:
- Build attack tree for each high-risk threat
- Analyze attack prerequisites and dependencies
- Calculate attack success probability and impact scope
2. Attack chain analysis:
- Identify multi-step attack paths (Initial Access → Execution → Persistence → Exfiltration)
- Map to MITRE ATT&CK tactics and techniques
- Mark critical pivot points in attack chain
3. Exploit POC generation:
- Generate POC code for each exploitable vulnerability
- Include payload construction, trigger conditions, expected results
- Provide safe testing methods (avoid destructive operations)
4. Penetration testing plan:
| Issue ID | Vulnerability | Test Case | Test Steps | POC | Recommended Tools |
|----------|---------------|-----------|------------|-----|-------------------|
Output: Complete penetration testing plan document, ready for security testing execution
```
### 场景 3:Docker 测试环境与自动化验证
搭建隔离测试环境并执行渗透测试计划。
```
/threat-modeling @/path/to/project
Set up test environment and execute penetration test verification:
1. Environment analysis:
- Parse project's docker-compose.yml / Dockerfile
- Identify required service dependencies (database, cache, message queue)
- Analyze default configuration and environment variables
2. Docker test environment construction:
- Generate isolated test environment docker-compose.test.yml
- Configure network isolation and port mapping
- Prepare test data and initialization scripts
- Integrate security testing tool containers (OWASP ZAP, Nuclei, SQLMap)
3. Automated test execution:
- Execute generated penetration testing plan
- Collect test results and evidence screenshots
- Verify vulnerability exploitability
4. Test report:
- Vulnerability confirmation status (Confirmed / Not Exploitable / False Positive)
- Actual risk assessment adjustment
- Reproduction steps and evidence chain
Output: Test environment config files + Automated test scripts + Test results report
```
### 场景 4:攻击链可视化与 POC 优化
全面的攻击链分析,包含可视化和优化的漏洞利用。
```
/threat-modeling @/path/to/project --debug
Complete attack chain analysis and visualization:
1. Attack graph construction:
- Build complete system attack graph
- Nodes: Assets, vulnerabilities, attack techniques
- Edges: Attack paths, prerequisites, success probability
2. Critical path analysis:
- Identify shortest attack path (from entry to core assets)
- Identify highest success rate path
- Identify attack chain with maximum impact scope
3. POC optimization combination:
- Tool chain optimization (Recon → Exploit → Post-Exploit)
- Automated attack script generation
- One-click vulnerability verification workflow
4. Visualization output:
- Mermaid format attack tree diagram
- Attack path heatmap
- Risk-impact matrix diagram
- ATT&CK Navigator mapping
Output format:
- Attack graph Markdown (with Mermaid diagrams)
- Optimized POC toolkit
- Risk visualization dashboard data
```
### 快速参考:扩展提示词
| 场景 | 重点 | 关键输出 |
|----------|-------|------------|
| **接口发现** | 所有接口 + 数据流 | 风险排序的接口清单 |
| **攻击树与 POC** | 攻击链 + 漏洞利用 | 包含 POC 代码的渗透测试计划 |
| **Docker 测试环境** | 隔离测试 | 测试环境 + 自动化脚本 |
| **攻击可视化** | 可视化分析 | 攻击图 + 热力图 |
## 输出结构
```
{PROJECT_ROOT}/
├── Risk_Assessment_Report/ # Final reports (P8)
│ ├── {PROJECT}-RISK-ASSESSMENT-REPORT.md
│ ├── {PROJECT}-RISK-INVENTORY.md
│ ├── {PROJECT}-PENETRATION-TEST-PLAN.md
│ └── ...
└── .phase_working/{SESSION_ID}/ # Working data
├── data/ # YAML phase data
│ ├── P1_project_context.yaml
│ ├── P2_dfd_elements.yaml
│ └── ...
└── reports/ # Markdown reports
├── P1-PROJECT-UNDERSTANDING.md
└── ...
```
## 脚本命令
### 知识库查询
```
# STRIDE 威胁模式
python scripts/unified_kb_query.py --stride spoofing
# 安全控制
python scripts/unified_kb_query.py --control AUTHN
# 包含完整链条的 CWE 信息
python scripts/unified_kb_query.py --cwe CWE-89 --full-chain
# CAPEC 攻击模式
python scripts/unified_kb_query.py --capec CAPEC-66 --attack-chain
# AI/LLM 特定威胁
python scripts/unified_kb_query.py --all-llm
```
### 模块发现
```
python scripts/module_discovery.py /path/to/project --p1-discovery
```
### 阶段数据管理
```
# 查询上一阶段数据
python scripts/phase_data.py --query --phase 1 --root /path/to/project
# 验证阶段输出
python scripts/phase_data.py --validate --phase 2 --root /path/to/project
# 初始化新会话
python scripts/phase_data.py --init --project "PROJECT-NAME" --path /path/to/project
```
## 8 阶段工作流
```
P1 → P2 → P3 → P4 → P5 → P6 → P7 → P8
│ │ │ │ │ │ │ └── Report Generation
│ │ │ │ │ │ └── Mitigation Planning
│ │ │ │ │ └── Risk Validation (POC, attack paths)
│ │ │ │ └── STRIDE Threat Analysis (threat matrix)
│ │ │ └── Security Design Review (16 domains)
│ │ └── Trust Boundary Evaluation
│ └── Call Flow & DFD Analysis (data flows, call flows)
└── Project Understanding (modules, entry points)
```
## 知识库
| 类别 | 覆盖范围 |
|----------|----------|
| 安全控制 | 16 个领域,107 项控制措施 |
| 威胁模式 | CWE/CAPEC/ATT&CK(1,900+ 模式) |
| AI/LLM 威胁 | 350+ 威胁 |
| 合规性 | OWASP ASVS, WSTG, MASTG |
| SQLite 索引 | 26+ MB 可搜索 |
## 支持的项目类型
| 类型 | 示例技术 | 特别关注 |
|------|---------------------|---------------|
| Web API | Django, FastAPI, Express | 身份验证,API 安全 |
| 微服务 | K8s, Istio, Kafka | 服务网格,零信任 |
| AI/LLM 应用 | Claude API, RAG, 向量数据库 | 提示词注入,模型安全 |
| 移动后端 | JWT, OAuth, Firebase | 令牌安全,数据隐私 |
| 遗留系统 | 单体应用, SOAP | 技术债务,迁移风险 |
## 许可证
BSD-3-Clause
## 仓库
https://github.com/fr33d3m0n/threat-modeling
标签:AI原生, CISA项目, Claude Code, DLL 劫持, DNS重绑定攻击, LLM驱动, Python, Ruby, TLS抓取, 云安全监控, 人工智能, 多模态安全, 大语言模型, 威胁建模, 安全报告, 安全测试, 安全风险评估, 攻击性安全, 无后门, 漏洞分析, 用户模式Hook绕过, 知识库, 结构化查询, 网络安全, 自动化安全, 路径探测, 软件安全, 逆向工具, 防御加固, 隐私保护, 静态分析