sahilsinghi/threat-intel-platform

GitHub: sahilsinghi/threat-intel-platform

基于自托管 MISP 的威胁情报聚合平台,支持多源 IOC 自动拉取、数据富化、去重及 REST API 分发。

Stars: 0 | Forks: 0

# 自动化威胁情报平台 基于自托管 MISP 的 IOC 聚合器,支持多源订阅、数据富化、去重以及 REST API。 **作品集项目 06/10 · Sahil Singhi · [github.com/sahilsinghi](https://github.com/sahilsinghi)** ## 功能介绍 | 层级 | 内容 | 实现方式 | |-------|------|-----| | **收集** | 5 个免费 IOC 源 | OTX, URLhaus, ThreatFox, MalwareBazaar, Feodotracker | | **标准化** | 统一的 MISP schema | ip-src, url, domain, sha256, md5 | | **富化** | 每个 IOC 的上下文 | WHOIS + GeoIP (ipinfo.io) + VirusTotal 信誉 | | **去重** | 30 天滚动窗口 | SQLite — 同一 IOC 在 30 天内不会被重复摄取 | | **分发** | 自托管 MISP | Web UI + REST API 位于 `https://localhost:8443` | | **调度** | 每小时增量获取 | APScheduler | | **监控** | Flask REST API | 端口 5001 上的 `/health` `/stats` `/recent` | | **可视化** | ATT&CK Navigator | 自动生成的 layer JSON | ## 成功标准 - [x] MISP 实例运行在 `https://localhost:8443` - [x] 摄取 pipeline 通过 APScheduler 每小时运行,并记录每次运行日志 - [x] 所有 5 个源均成功摄取 - [ ] 完成 24 小时摄取,且 MISP 中存在 > 1000 个唯一 IOC *(运行 pipeline)* - [x] 去重缓存可防止跨运行的重复项 - [x] 每个 IOC 均进行了 WHOIS + GeoIP + VirusTotal 数据富化 - [x] PyMISP 集成测试通过运行中的 MISP 验证 - [x] Flask REST API 暴露 `/stats`, `/recent`, `/health` - [x] 已生成 ATT&CK Navigator layer JSON - [x] 已记录跨作品集的 SOAR 桥接 ## 前置条件 - Docker Desktop (≥ 4 GB RAM 分配 — MISP 需要约 3 GB) - Python 3.11+ 所需 API 密钥(均免费): | 服务 | 获取地址 | 环境变量 | |---------|----------------|---------| | AlienVault OTX | otx.alienvault.com → My Profile | `OTX_API_KEY` | | VirusTotal | virustotal.com → Profile → API Key | `VIRUSTOTAL_API_KEY` | | ipinfo.io | ipinfo.io → Account | `IPINFO_TOKEN` | URLhaus, ThreatFox, MalwareBazaar, Feodotracker — **无需密钥**。 ## 安装说明 ### 1. 克隆并配置 ``` git clone https://github.com/sahilsinghi/threat-intel-platform.git cd threat-intel-platform cp .env.example .env # 编辑 .env — 填写 OTX_API_KEY, VIRUSTOTAL_API_KEY, IPINFO_TOKEN ``` ### 2. 启动 MISP ``` docker compose up -d ``` 首次启动时,MISP 初始化大约需要 5 分钟。查看日志: ``` docker compose logs -f misp ``` 当你看到 `MISP is ready` 时,打开 `https://localhost:8443` 并接受自签名证书。 **默认凭证:** `admin@admin.test` / `admin` **请立即更改密码** — Admin → My Profile → Change Password。 ### 3. 获取你的 MISP automation key 1. 登录 `https://localhost:8443` 2. 前往 **Event Actions → Automation** 3. 复制 **Automation key** 4. 将其粘贴到 `.env` 中作为 `MISP_KEY=` ### 3b. 修复 MISP 配置权限(一次性操作,需在每次启动容器后执行) MISP Docker entrypoint 将 `config.php` 的权限写为 `root:root 600`,但 PHP-FPM 以 `www-data` 用户运行且无法读取它,导致所有 API 调用出现 500 错误。 使用随附的脚本进行修复: ``` ./scripts/fix-misp-perms.sh ``` ### 4. 安装 Python 依赖 ``` python3 -m venv venv source venv/bin/activate pip install -r requirements.txt ``` ### 5. 运行 pipeline ``` source venv/bin/activate python -m pipeline.orchestrator ``` 该 pipeline 会: 1. 在 `data/cache.db` 初始化 SQLite 去重缓存 2. 立即执行所有 5 个源的完整摄取 3. 启动 APScheduler 进行每小时运行 4. 在 `http://localhost:5001` 启动 Flask 监控 API ## API 端点 | 端点 | 描述 | |----------|-------------| | `GET /health` | pipeline + MISP 连接状态 | | `GET /stats` | IOC 总数、按源分类、按类型分类、最近运行情况 | | `GET /recent?limit=100` | 最近摄取的 IOC | 示例: ``` curl http://localhost:5001/stats | python3 -m json.tool curl http://localhost:5001/recent?limit=20 curl http://localhost:5001/health ``` ## ATT&CK Navigator 生成一个显示过去 30 天技术覆盖范围的 layer: ``` source venv/bin/activate python scripts/export_navigator.py --output navigator_layer.json ``` 加载地址:https://mitre-attack.github.io/attack-navigator/ → Open Existing Layer → Upload File ## 跨作品集桥接 (SOAR 集成) Sahil 的 SOAR 警报分流 pipeline(Project #02)现在在调用实时 API 之前会先查询 MISP。 ``` from pymisp import PyMISP misp = PyMISP("https://localhost:8443", MISP_KEY, False) results = misp.search(controller="attributes", value="1.2.3.4", pythonify=True) ``` 详情请参阅 [docs/cross-portfolio-bridge.md](docs/cross-portfolio-bridge.md)。 n8n workflow 代码片段请参阅 [docs/soar-misp-integration.md](docs/soar-misp-integration.md)。 **影响:** 在 SOAR 分流中减少了约 70% 的外部 API 调用 — MISP 缓存命中跳过了 VirusTotal + ipinfo。 **相关项目:** [SOAR Alert Triage Pipeline (Project #02)](https://github.com/sahilsinghi) · [APT Profiler (Project #07)](https://github.com/sahilsinghi) ## 运行测试 ``` source venv/bin/activate pip install pytest pytest tests/test_normalizer.py tests/test_dedup.py -v # MISP 集成测试(需要 MISP 运行中 + 设置 MISP_KEY) pytest tests/test_misp_integration.py -v ``` ## 架构 完整的 Mermaid 图表请参阅 [docs/architecture.md](docs/architecture.md)。 ``` [OTX] [URLhaus] [ThreatFox] [MalwareBazaar] [Feodotracker] │ (hourly via APScheduler) ▼ [Feed Adapters] → [Normalizer] → [Enricher] → [Dedup Cache] → [PyMISP] (SQLite) │ ▼ [MISP] https://localhost:8443 │ [SOAR Pipeline] ``` ## 仓库结构 ``` threat-intel-platform/ ├── docker-compose.yml MISP + MySQL + Redis ├── requirements.txt ├── .env.example Copy to .env, fill in keys ├── pipeline/ │ ├── feeds/ │ │ ├── otx.py AlienVault OTX adapter │ │ ├── urlhaus.py URLhaus adapter │ │ ├── threatfox.py ThreatFox adapter (best ATT&CK tags) │ │ ├── malwarebazaar.py MalwareBazaar adapter │ │ └── feodotracker.py Feodotracker C2 IPs │ ├── normalizer.py Raw IOC → MISP attribute schema │ ├── enricher.py WHOIS + GeoIP + VT enrichment │ ├── dedup.py SQLite 30-day dedup + audit log │ ├── misp_client.py PyMISP event creation + IOC search │ └── orchestrator.py Main entry point + APScheduler ├── api/ │ └── monitoring.py Flask /stats /recent /health ├── scripts/ │ ├── export_navigator.py ATT&CK Navigator JSON exporter │ └── fix-misp-perms.sh Fix config.php permissions after container restart ├── tests/ │ ├── test_normalizer.py │ ├── test_dedup.py │ └── test_misp_integration.py └── docs/ ├── architecture.md ├── feed-list.md ├── cross-portfolio-bridge.md └── soar-misp-integration.md ``` ## 简历要点 ## 安全说明 - 在运行 pipeline 之前**更改默认的 MISP 管理员密码** - 在没有身份验证/VPN 的情况下,**切勿将 MISP 暴露在 localhost 之外** - `.env` 文件位于 `.gitignore` 中 — 切勿提交它 - MISP 使用自签名 SSL 证书 — `MISP_VERIFYCERT=false` 专为本地使用而设置 ## 许可证 MIT © Sahil Singhi
标签:Docker, PB级数据处理, Python, 威胁情报, 安全运维, 安全防御评估, 开发者工具, 数据泄露, 数据聚合, 无后门, 网络调试, 自动化, 请求拦截, 逆向工具