Pingu314/soc_threat_analyzer
GitHub: Pingu314/soc_threat_analyzer
这是一个基于Python的安全运营中心仿真工具,旨在通过SIGMA风格规则检测暴力破解与异常登录行为,并利用威胁情报和MITRE ATT&CK框架对告警进行丰富与风险评分。
Stars: 0 | Forks: 0
# SOC Threat Analyzer
一个基于 Python 的安全运营中心(SOC)仿真工具,用于检测基于身份验证的攻击,利用威胁情报丰富告警信息,并通过映射到 MITRE ATT&CK 的风险评分来划分事件优先级。
## 场景
本项目模拟了一个 SOC 环境,其中使用身份验证日志分析来检测活跃的攻击模式。该流程反映了真实 SOC Tier 1 的工作流:
```
Ingest -> Parse -> Detect -> Enrich -> Score -> Alert
```
## 检测规则(基于 SIGMA)
所有规则均在 `src/detector.py` 中定义为功能性的 SIGMA 风格字典。阈值和时间窗口由 `config/settings.py` 驱动——没有硬编码的值。
| 规则 ID | 规则 | MITRE 技术 | 触发条件 |
|---------|------|----------------|---------|
| bf-001 | Brute Force Detection | T1110.001 – Password Guessing | 5 分钟内来自同一 IP 的 ≥3 次失败登录 |
| ps-001 | Password Spraying Detection | T1110.003 – Password Spraying | 10 分钟内来自同一 IP 针对≥3 个不同用户 |
| it-001 | Impossible Travel Detection | T1078 – Valid Accounts | 5 分钟内来自≥2 个不同 IP 的同一用户 |
## 示例输出
针对示例日志运行 `python src/main.py` 将在所有三个规则下产生 9 个告警:
```
$ python src/main.py
[bf-001] Brute force from 185.220.101.1 (4 attempts)
[bf-001] Brute force from 192.168.1.10 (3 attempts)
[bf-001] Brute force from 1.1.1.1 (3 attempts)
[bf-001] Brute force from 45.83.64.1 (5 attempts)
[ps-001] Password spraying from 45.83.64.1 targeting ['admin', 'guest', 'operator', 'root', 'test']
[it-001] Impossible travel for 'root' across ['185.220.101.1', '45.83.64.1']
[it-001] Impossible travel for 'admin' across ['192.168.1.10', '45.83.64.1']
[it-001] Impossible travel for 'jsmith' across ['103.21.244.0', '185.220.101.1']
[it-001] Impossible travel for 'test' across ['45.83.64.1', '8.8.8.8']
Total alerts after deduplication: 9
```
**示例丰富告警(JSON):**
```
{
"rule_id": "bf-001",
"rule": "Brute Force Detection",
"mitre": "T1110.001",
"sigma_severity": "high",
"ip": "185.220.101.1",
"user": "multiple",
"count": 4,
"country": "DE",
"org": "AS60729 Stiftung Erneuerbare Freiheit",
"risk_score": 12,
"severity": "HIGH"
}
{
"rule_id": "ps-001",
"rule": "Password Spraying Detection",
"mitre": "T1110.003",
"sigma_severity": "high",
"ip": "45.83.64.1",
"user": "multiple",
"count": 5,
"country": "DE",
"org": "AS208843 Alpha Strike Labs GmbH",
"risk_score": 25,
"severity": "HIGH",
"distinct_users": "admin, guest, operator, root, test"
}
{
"rule_id": "it-001",
"rule": "Impossible Travel Detection",
"mitre": "T1078",
"sigma_severity": "medium",
"ip": "multiple",
"user": "jsmith",
"count": 2,
"country": "Unknown",
"org": "Unknown",
"risk_score": 10,
"severity": "MEDIUM",
"distinct_ips": "103.21.244.0, 185.220.101.1"
}
```
## 架构
```
logs.txt
│
▼
parser.py -> parses log entries, skips malformed lines
│
▼
detector.py -> runs all SIGMA rules, deduplicates alerts
├─ bf-001 Brute Force (T1110.001)
├─ ps-001 Password Spraying (T1110.003)
└─ it-001 Impossible Travel (T1078)
│
▼
threat_intel.py -> ipinfo.io enrichment with in-memory cache
private IP detection (RFC 1918)
│
▼
risk_scoring.py -> calculates risk score, severity, MITRE label
│
▼
main.py -> prints alerts + exports to output/alerts.csv
dashboard.py -> Flask REST API at /alerts
```
## 风险评分
| 因素 | 分值 |
|--------|--------|
| 每次失败登录 | +3 |
| 可疑国家(RU, CN, KP) | +5 |
| 在组织中检测到 Tor 出口节点 | +5 |
| 每个被针对的不同用户(密码喷洒) | +2 |
| 每个不同的 IP(不可能旅行) | +2 |
| 分数 | 严重等级 |
|-------|----------|
| 0–5 | LOW |
| 6–11 | MEDIUM |
| 12+ | HIGH |
## 功能
- 带有逐行错误处理和跳过日志记录的日志解析
- 三个基于功能的 SIGMA 检测规则
- 跨检测轮次的告警去重
- 通过 ipinfo.io 进行 IP 丰富,并使用内存缓存
- 私有 IP 检测(RFC 1918)——无浪费的 API 调用
- MITRE ATT&CK 子技术映射
- 带有完整告警上下文的 CSV 导出
- 位于 `/alerts` 的 Flask REST 仪表板
- 通过 Python `logging` 模块进行结构化日志记录
- 32 个单元和集成测试,使用 pytest 和共享 fixtures
## 技术
- Python 3.10+
- Flask(REST 仪表板)
- requests + ipinfo.io(威胁情报)
- pytest(单元测试)
- MITRE ATT&CK(T1110.001, T1110.003, T1078)
- SIGMA 规则格式
## 项目结构
```
soc_threat_analyzer/
├── config/
│ └── settings.py # single source of truth for all config
├── data/
│ ├── logs.txt # sample authentication logs
│ └── ips.txt # sample IP list
├── src/
│ ├── main.py # pipeline orchestration + CSV export
│ ├── parser.py # log file parser
│ ├── detector.py # SIGMA rules + all detection logic
│ ├── threat_intel.py # ipinfo.io enrichment with caching
│ ├── risk_scoring.py # scoring + severity + MITRE mapping
│ └── dashboard.py # Flask REST API
├── tests/
│ ├── conftest.py # shared pytest fixtures
│ └── test_all.py # 32 unit + integration tests
├── output/
│ └── alerts.csv # generated output (gitignored)
├── requirements.txt
└── .gitignore
```
## 如何运行
```
pip install -r requirements.txt
python src/main.py
```
Flask 仪表板:
```
python src/dashboard.py
# → http://localhost:5000/alerts
```
测试:
```
python -m pytest tests/
```
## 配置
编辑 `config/settings.py` 以调整检测行为——无需更改其他地方:
```
THRESHOLD = 3 # brute force: failed login threshold
WINDOW_MINUTES = 5 # brute force: time window
SPRAY_THRESHOLD = 3 # spraying: distinct user threshold
SPRAY_WINDOW_MINUTES = 10
TRAVEL_THRESHOLD = 2 # impossible travel: distinct IP threshold
TRAVEL_WINDOW_MINUTES = 5
SUSPICIOUS_COUNTRIES = ["RU", "CN", "KP"]
SEVERITY_HIGH = 12
SEVERITY_MEDIUM = 6
```
## 局限性
- 使用公共 ipinfo.io API(无企业威胁情报源)
- 仿真日志数据(无真实生产日志)
- 内存缓存在重启时重置
## 未来改进
- SIEM 集成(Splunk / ELK)
- 实时日志摄入
- AbuseIPDB 或 VirusTotal 集成
- 持久化缓存(Redis)
- 跨多源的告警关联
- 仪表板可视化
## 免责声明
本项目仅用于教育目的,并使用合成数据模拟 SOC 工作流。
标签:AMSI绕过, Cloudflare, Impossible Travel, MITRE ATT&CK, Python, SIGMA 规则, 免杀技术, 威胁情报, 威胁检测, 安全规则引擎, 安全运营中心, 密码喷射, 开发者工具, 异常检测, 情报富化, 无后门, 暴力破解检测, 红队行动, 网络安全, 网络映射, 认证安全, 逆向工具, 隐私保护, 风险评分