Rakesh-R-K/SentinelHunt
GitHub: Rakesh-R-K/SentinelHunt
一款基于多模型机器学习集成和行为检测的实时网络威胁狩猎平台,专注发现零日漏洞和 APT 等未知威胁。
Stars: 0 | Forks: 0
# 🛡️ SentinelHunt
**AI 驱动的实时网络威胁狩猎平台**
[](LICENSE)
[](https://www.python.org/)
[](https://golang.org/)
[](https://www.typescriptlang.org/)
[](https://redis.io/)
[](https://docs.docker.com/compose/)
## 🎯 什么是 SentinelHunt?
SentinelHunt 是一个**顶石级(Capstone-grade)威胁狩猎平台**,它结合了集成机器学习、MITRE ATT&CK 映射和实时 Redis 流技术,在网络流量中检测零日漏洞和高级持续性威胁(APT)——而无需依赖特征库。
### 对比分析
| 能力 | 传统 IDS | SentinelHunt |
|-----------|----------------|--------------|
| 检测方式 | ❌ 基于特征库(无法检测零日攻击) | ✅ 行为式 ML 集成(可捕获未知威胁) |
| ML 模型 | ❌ 无或单一模型 | ✅ 5 模型集成(Autoencoder, LSTM, IForest, LOF, OCSVM) |
| 检测规则 | ❌ 正则表达式模式 | ✅ 8 项行为规则(DGA, 横向移动, 数据窃取, JA3...) |
| 威胁情报 | ❌ 静态订阅源 | ✅ VirusTotal + AbuseIPDB + Shodan + 5 个 OSINT 源 |
| 框架映射 | ❌ 无 | ✅ 自动化 MITRE ATT&CK(7 项战术,20+ 项技术) |
| 架构 | ❌ 批量文件处理 | ✅ Redis Streams 实时流水线 |
| 可解释性 | ❌ 黑盒 | ✅ SHAP + 人类可读的叙述 |
| 仪表盘 | ❌ 静态报告 | ✅ WebSocket 实时 SOC 界面 |
## 🏗️ 架构
```
┌───────────────────────────────────────────────────────────────┐
│ SentinelHunt v2.0 │
└───────────────────────────────────────────────────────────────┘
┌──────────┐ ┌──────────────┐ ┌─────────────────────┐
│ Go │ │ Redis │ │ Real-Time Scorer │
│ Collector│───▶│ Streams │───▶│ (ML + Rules + MITRE)│
│ (pcap) │ │ │ │ │
└──────────┘ └──────────────┘ └─────────┬───────────┘
│
▼
┌──────────┐ ┌──────────────┐ ┌─────────────────────┐
│ React │◀───│ Socket.io │◀───│ Alert Stream │
│ Dashboard│ │ WebSocket │ │ (sentinelhunt:alerts)│
└──────────┘ └──────────────┘ └─────────────────────┘
│
┌─────────┴───────────┐
│ Threat Intel │
│ (VT/AbuseIPDB/ │
│ Shodan/OSINT) │
└─────────────────────┘
```
### 组件
| 组件 | 语言 | 描述 |
|-----------|----------|-------------|
| **Packet Collector** | Go | 高性能 pcap 捕获 → Redis Streams |
| **Real-Time Scorer** | Python | 集成 ML + 8 项检测规则 + MITRE 映射 |
| **ML Engine** | Python/PyTorch | Autoencoder, LSTM, IForest, LOF, OneClassSVM |
| **Detection Rules** | Python | DGA, 横向移动, 数据窃取, 凭据滥用, JA3, 协议异常 |
| **MITRE Mapper** | Python | 自动 ATT&CK 丰富化 + Navigator 层导出 |
| **Threat Intel** | Python | VirusTotal, AbuseIPDB, Shodan, IOC DB (STIX 2.1) |
| **API Server** | Node.js | REST + WebSocket (Socket.io), JWT 认证, 速率限制 |
| **Dashboard** | React/TS | 具有调查工作流的实时 SOC 界面 |
| **Explainability** | Python | SHAP 特征归因 + 人类可读的叙述 |
## ✨ 核心功能
### 🤖 ML 集成(5 种模型)
- **Autoencoder** — 用于异常检测的深度重构误差
- **LSTM** — 用于信标模式的时间序列建模
- **Isolation Forest** — 基于树的无监督离群点检测
- **Local Outlier Factor** — 基于密度的局部异常评分
- **One-Class SVM** — 基于边界的新颖性检测
### 🔍 8 项检测规则
- 端口扫描 · DNS 隧道/DGA · JA3 TLS 指纹识别 · 横向移动
- 协议异常 · 凭据暴力破解 · 数据窃取 · C2 信标
### ⬡ MITRE ATT&CK 集成
- 自动化技术映射(跨越 7 项战术的 20+ 种技术)
- ATT&CK Navigator 层导出
- 每个警报的调查指导
### 🌐 威胁情报
- **APIs:** VirusTotal, AbuseIPDB, Shodan
- **OSINT 源:** alienvault, abuse.ch, emerging threats 等
- **IOC 数据库:** 基于 SQLite,支持 STIX 2.1 导入/导出
### 🧠 可解释 AI
- 基于 SHAP 的特征归因(全局 + 单警报)
- 面向 SOC 分析师的人类可读威胁叙述
- 特征重要性可视化
## 🚀 快速开始
### 选项 1: Docker(推荐)
```
# 克隆并启动所有服务
git clone https://github.com/your-org/SentinelHunt.git
cd SentinelHunt
# 复制环境配置
cp .env.example .env
# 使用你的 API keys 编辑 .env (可选)
# 启动平台 (5 个服务)
docker-compose up -d
# Dashboard: http://localhost:3000
# API: http://localhost:5000
# Redis: localhost:6379
```
### 选项 2: 手动设置
```
# 1. 安装 Python 依赖
pip install -r requirements.txt
# 2. 安装 Node.js 依赖
cd dashboard/backend && npm install && cd ../..
cd dashboard/frontend && npm install && cd ../..
# 3. 安装 Go 依赖
cd collector && go mod download && cd ..
# 4. 启动 Redis
docker run -d -p 6379:6379 redis:7-alpine
# 5. 启动 API 后端
cd dashboard/backend && npm start &
# 6. 启动 Dashboard
cd dashboard/frontend && npm start &
# 7. 训练 ML 模型
python -m ml.training_pipeline --ensemble
# 8. 启动实时评分器
python -m streaming.realtime_scorer &
# 9. (可选) 运行 demo 流量模拟器
python -m streaming.demo_simulator --rate 10
```
### 演示模式(无需真实流量)
```
# 启动 Redis + API + Dashboard, 然后:
python -m streaming.demo_simulator --rate 5 --duration 120
# 生成真实的良性 + 攻击流量 (85/15 混合):
# Port scans, DNS tunnels, lateral movement, exfiltration, brute force
```
### 默认凭据
| 用户名 | 密码 | 角色 |
|----------|----------|------|
| `analyst` | `sentinelhunt2026` | SOC Analyst |
| `admin` | `sentineladmin` | Administrator |
## 📊 检测能力
### 可检测的攻击类型
| 攻击 | 检测方法 | MITRE 技术 |
|--------|-----------------|-----------------|
| 端口扫描 | 目标端口计数启发式 + ML | T1046 |
| DNS 隧道 | 熵 + 子域名深度 + 查询长度 | T1071.004 |
| DGA 信标 | 双字符组熵分析 + ML | T1568.002 |
| 横向移动 | 管理端口上的内部到内部流量 | T1021 |
| 数据窃取 | 流量 + 速率阈值 + ML | T1041, T1048 |
| 凭据暴力破解 | 连接频率 + 失败模式 | T1110 |
| 协议异常 | 端口-服务不匹配检测 | T1571 |
| C2 通信 | 时间规律性 + 加密流量 | T1573.002 |
### ML 模型集成
```
IsolationForest (25%)
│
Input → Feature → Autoencoder (30%) → Weighted → Final
Engineering │ Voting Score
LOF (20%) │
│ ─────┘
OneClassSVM (25%)
```
每个模型独立对流进行评分。集成模型使用校准后的权重组合分数,以在最大化检测率的同时最大限度地减少误报。
## 🧪 测试
```
# 运行完整测试套件
pytest tests/ -v --tb=short
# 运行覆盖率测试
pytest tests/ --cov=detection_engine --cov=ml --cov=streaming -v
# 运行特定测试模块
pytest tests/test_detection_rules.py -v
pytest tests/test_ml_models.py -v
pytest tests/test_api_endpoints.py -v
```
### 基准测试
```
# 针对标准 IDS 数据集 (CIC-IDS2017) 运行
python -m experiments.benchmark_runner
# Adversarial robustness 测试
python -c "
from ml.adversarial_robustness import AdversarialTester
# 查看 experiments/ 获取完整用法
"
```
## 📁 项目结构
```
SentinelHunt/
├── collector/ # Go packet collector
│ ├── main.go # Entry point + packet processing
│ ├── flow_tracker.go # Flow aggregation + feature extraction
│ ├── redis_publisher.go # Redis Streams integration
│ └── config.yaml # Collector configuration
├── ml/ # Machine learning engine
│ ├── models/
│ │ ├── autoencoder.py # Deep autoencoder (PyTorch)
│ │ ├── lstm_detector.py # LSTM sequence detector
│ │ └── ensemble.py # 4-model ensemble system
│ ├── training_pipeline.py # Production training pipeline
│ └── adversarial_robustness.py # Adversarial attack testing
├── detection_engine/ # Detection logic
│ ├── rules/ # 8 behavioral detection rules
│ ├── scoring/ # Threat scoring + severity
│ ├── intelligence/ # Campaign detection + timelines
│ └── mitre_mapping.py # ATT&CK technique mapper
├── streaming/ # Real-time pipeline
│ ├── redis_broker.py # Redis Streams pub/sub
│ ├── realtime_scorer.py # Live flow scoring engine
│ ├── demo_simulator.py # Demo traffic generator
│ └── config.py # Centralized configuration
├── threat_intel/ # Threat intelligence
│ ├── enrichment.py # VT/AbuseIPDB/Shodan client
│ ├── ioc_manager.py # IOC database (STIX 2.1)
│ └── feed_ingester.py # OSINT feed pipeline
├── dashboard/
│ ├── backend/ # Express + Socket.io API
│ └── frontend/ # React + TypeScript SOC UI
├── explainability/ # SHAP + narratives
├── experiments/ # Benchmarking + evaluation
├── tests/ # pytest test suite
├── docker-compose.yml # 5-service deployment
├── config.yaml # Platform-wide configuration
├── .env.example # Environment variable template
└── requirements.txt # Python dependencies
```
## 🔧 配置
所有设置均通过 `config.yaml` 和环境变量控制:
```
# config.yaml — 关键设置
ml:
ensemble_threshold: 0.5 # Anomaly threshold
iforest_n_estimators: 200 # IForest trees
detection:
port_scan_threshold: 20 # Min ports for scan detection
dns_entropy_threshold: 3.5 # DGA entropy cutoff
redis:
host: localhost
flow_stream: sentinelhunt:flows
alert_stream: sentinelhunt:alerts
```
请参阅 `.env.example` 获取 API 密钥和密钥信息。
## 🐳 Docker 部署
```
docker-compose up -d
# 服务:
# redis — 消息代理 (端口 6379)
# ml-engine — Python ML 评分器
# api-server — Node.js REST + WebSocket (端口 5000)
# dashboard — React 前端 (端口 3000)
# collector — Go 抓包器
```
## 📚 参考资料
- CIC-IDS2017 Dataset — Canadian Institute for Cybersecurity
- MITRE ATT&CK Framework — https://attack.mitre.org
- SHAP (SHapley Additive exPlanations) — Lundberg & Lee, 2017
- Isolation Forest — Liu, Ting & Zhou, 2008
## 📄 许可证
MIT License — 详情请参阅 [LICENSE](LICENSE)。
标签:Apex, Autoencoder, Beacon Object File, C2通信, Cloudflare, DGA检测, DNS 反向解析, Docker, ESC4, Go, IP 地址批量处理, LSTM, MITM代理, MITRE ATT&CK, OSINT, PE 加载器, Python, Redis, Ruby工具, SHAP, TypeScript, XAI, 人工智能, 凭据扫描, 可解释AI, 威胁情报, 孤立森林, 安全态势感知, 安全插件, 安全防御评估, 开发者工具, 异常检测, 搜索引擎查询, 无后门, 日志审计, 机器学习, 横向移动, 深度学习, 用户模式Hook绕过, 编程规范, 网络安全, 网络流量分析, 请求拦截, 逆向工具, 隐私保护, 集成学习, 零日漏洞