Athar2410/soar-incident-response-platform

GitHub: Athar2410/soar-incident-response-platform

基于随机森林分类器的轻量级SOAR平台,实现网络流量检测、威胁情报富化到自动防火墙阻断的完整事件响应管道。

Stars: 0 | Forks: 0

# 🛡️ SOAR 事件响应平台 ![Python](https://img.shields.io/badge/Python-3.10+-3776AB?style=flat&logo=python&logoColor=white) ![Scikit-Learn](https://img.shields.io/badge/Scikit--Learn-ML-F7931E?style=flat&logo=scikit-learn&logoColor=white) ![Streamlit](https://img.shields.io/badge/Streamlit-Dashboard-FF4B4B?style=flat&logo=streamlit&logoColor=white) ![SQLite](https://img.shields.io/badge/SQLite-Database-003B57?style=flat&logo=sqlite&logoColor=white) ![VirusTotal](https://img.shields.io/badge/VirusTotal-API-394EFF?style=flat) ![AbuseIPDB](https://img.shields.io/badge/AbuseIPDB-API-red?style=flat) ## 📌 概述 本项目实现了一个完整的**检测 → 富化 → 响应**安全管道: 1. **检测** — 一个经过训练的随机森林多类分类器(基于 NSL-KDD 数据集,41 个特征)将网络流量分为 5 个类别:Normal、DoS、Probe、R2L 和 U2R 2. **富化** — 自动在 VirusTotal 和 AbuseIPDB 中查询可疑源 IP,以获取信誉评分、地理位置和 ASN 数据 3. **响应** — 高置信度的恶意 IP 会通过 Windows 防火墙(`netsh`)或 Linux 的 `iptables` 被自动阻断,事件将记录到 SQLite 中,并发送 Slack 告警 ## 🏗️ 架构 ``` soar_platform/ ├── detection/ │ ├── detector.py # ML model loader + classify_traffic() │ ├── nids_model.pkl # Trained Random Forest (rf_multiclass) │ └── test_detector.py ├── enrichment/ │ ├── enricher.py # VirusTotal + AbuseIPDB API queries │ └── test_enricher.py ├── response/ │ ├── responder.py # Firewall block + SQLite logging + Slack │ └── test_responder.py ├── dashboard/ │ └── app.py # Streamlit SOC dashboard (4 pages) ├── logs/ │ └── incidents.db # SQLite incident database ├── main.py # Pipeline orchestrator ├── config.py # API keys + thresholds ├── check_db.py # Quick DB inspection utility ├── requirements.txt └── .env # Secret keys (never commit) ``` ## ⚙️ 管道流程 ``` [Network Traffic / Scapy Capture] │ ▼ ┌─────────────────┐ │ 1. DETECT │ Random Forest Classifier │ 41 NSL-KDD │ 5-class: Normal/DoS/Probe/R2L/U2R │ features │ Confidence threshold: 50% └────────┬────────┘ │ is_attack = True ▼ ┌─────────────────┐ │ 2. ENRICH │ VirusTotal API → malicious engine count │ Threat Intel │ AbuseIPDB API → confidence score (0-100) │ │ GeoIP + ASN → country, ISP, owner └────────┬────────┘ │ abuse_score >= 80 ▼ ┌─────────────────┐ │ 3. RESPOND │ Windows: netsh advfirewall (host) │ Auto-Response │ Linux: iptables -I INPUT -j DROP (Kali VM) │ │ SQLite: incident logged to logs/incidents.db │ │ Slack: webhook alert to #soc-alerts └─────────────────┘ ``` ## 🚀 设置与安装 ### 前置条件 - Python 3.10+ - Windows(主机)+ VMware 上的 Kali Linux(用于实时的 iptables 阻断) - 免费 API 密钥:[VirusTotal](https://www.virustotal.com) + [AbuseIPDB](https://www.abuseipdb.com/register) ### 1. 克隆仓库 ``` git clone https://github.com/Athar2410/soar-incident-response-platform.git cd soar-incident-response-platform ``` ### 2. 创建虚拟环境 ``` python -m venv soar_venv # Windows: soar_venv\Scripts\activate # Linux/Kali: source soar_venv/bin/activate ``` ### 3. 安装依赖 ``` pip install -r requirements.txt ``` ### 4. 配置 API 密钥 在项目根目录下创建 `.env` 文件: ``` VT_API_KEY=your_virustotal_api_key_here ABUSE_API_KEY=your_abuseipdb_api_key_here SLACK_WEBHOOK=your_slack_webhook_url_here # optional ``` ### 5. 添加你的 NIDS 模型 将你训练好的模型放置在: ``` detection/nids_model.pkl ``` ### 6. 运行管道 ``` # 以 Administrator 身份运行 以配置防火墙规则 python main.py ``` ### 7. 启动仪表盘 ``` streamlit run dashboard/app.py # 在 http://localhost:8501 打开 ``` ## 📊 仪表盘页面 | 页面 | 描述 | |------|-------------| | 📊 Dashboard | KPI 卡片、攻击类型饼图、严重程度柱状图、Top IP 表格 | | 🚨 Incidents | 支持过滤的事件日志,可导出为 CSV | | 🔍 Enrichment | Abuse 评分与 VT 检测结果的散点图,按 IP 的威胁摘要 | | ⚙️ Pipeline | 架构图、管道统计信息、当前配置 | ## 🔧 配置 编辑 `config.py` 以调整阈值: | 设置 | 默认值 | 描述 | |---------|---------|-------------| | `VT_MALICIOUS_THRESHOLD` | 10 | 若 ≥ 10 个 VT 引擎检出则标记 IP | | `ABUSE_SCORE_THRESHOLD` | 50 | 若 AbuseIPDB 评分 ≥ 50 则标记 IP | | `AUTO_BLOCK_THRESHOLD` | 80 | 若 AbuseIPDB 评分 ≥ 80 则自动阻断 IP | | `PLATFORM` | `"windows"` | 在 Kali 上使用 iptables 时需设置为 `"linux"` | ## 🐧 Kali Linux — 实时 iptables 阻断 若要在你的 Kali 虚拟机上使用真实的 `iptables` 执行阻断: 1. 通过 VMware 共享文件夹将项目复制到 Kali 2. 在 `main.py` 中更改 `PLATFORM = "linux"` 3. 使用 sudo 运行: ``` sudo python main.py ``` 响应模块将执行: ``` sudo iptables -I INPUT -s -j DROP ``` 查看所有由 SOAR 创建的规则: ``` sudo iptables -L INPUT -n --line-numbers | grep SOAR ``` 移除所有 SOAR 规则: ``` sudo iptables -D INPUT -s -j DROP ``` ## 💬 Slack 告警 要启用 Slack 通知: 1. 前往 [api.slack.com/apps](https://api.slack.com/apps) → Create App → Incoming Webhooks 2. 启用 webhooks → 添加到某个频道(例如 `#soc-alerts`) 3. 将 Webhook URL 复制到你的 `.env` 中: ``` SLACK_WEBHOOK=https://hooks.slack.com/services/XXX/YYY/ZZZ ``` 每个被自动阻断的 IP 都会触发类似如下的告警: ``` 🚨 SOAR Alert — INC-0001 > Attack: DOS (conf: 97.0%) > IP: 185.220.101.47 — DE / Stiftung Erneuerbare Freiheit > VT: 15/91 engines | AbuseIPDB: 100/100 > Action: 🛡️ IP BLOCKED ``` ## 📦 技术栈 | 组件 | 技术 | |-----------|------------| | ML 模型 | scikit-learn RandomForestClassifier | | 数据集 | NSL-KDD (41 个特征, 5 个类别) | | 威胁情报 | VirusTotal API v3, AbuseIPDB API v2 | | 防火墙 | Windows netsh / Linux iptables | | 数据库 | SQLite (通过 Python sqlite3) | | 仪表盘 | Streamlit + Plotly | | 告警 | Slack Incoming Webhooks | | HTTP | Python requests 库 | | 调度 | APScheduler (实时模式) | ## 📈 示例结果 | 指标 | 值 | |--------|-------| | 检测延迟 | < 0.5 秒 | | 富化时间 | ~18 秒 (受 VT 速率限制) | | 管道总耗时 | 每个事件 < 20 秒 | | VT API 用量 | ~3 次请求/分钟 (远低于免费的 4 次/分钟限制) | | 自动阻断准确性 | 取决于 AbuseIPDB 阈值 (默认: 评分 ≥ 80) | ## 🔮 未来扩展 - [ ] **实时 Scapy 抓包** — 用真实的数据包嗅探替代模拟事件 - [ ] **MITRE ATT&CK 映射** — 为每个告警打上 ATT&CK 技术 ID 标签 - [ ] **邮件告警** — 除 Slack 外增加 SMTP 通知 - [ ] **Docker 容器化** — 封装平台以便于部署 - [ ] **Suricata 集成** — 对比 ML 检测结果与基于规则的 IDS - [ ] **REST API** — 将管道作为 Flask API 暴露,以便外部集成 ## ⚠️ 免责声明 本工具仅用于**教育和研究目的**。请仅在你拥有或已获得明确书面授权进行测试的网络和系统上进行测试。作者不对任何误用行为负责。 ## 👤 作者 **Atharva Amle** - GitHub: [@Athar2410](https://github.com/Athar2410) - 项目:SOAR 事件响应平台 ## 📄 许可证 MIT 许可证 — 可免费使用、修改和分发,但需注明出处。
标签:AbuseIPDB, Apex, Ask搜索, DoS检测, iptables, IP 地址批量处理, IP封堵, Kubernetes, ML检测, netsh, NSL-KDD, Python, Slack告警, SOAR, SQLite, Streamlit, VirusTotal, 信誉查询, 威胁情报, 安全仪表盘, 安全运营, 密码管理, 开发者工具, 异常检测, 扫描框架, 无后门, 机器学习, 网络安全, 网络流量分类, 自动化响应, 访问控制, 逆向工具, 防火墙, 随机森林, 隐私保护