TiltedLunar123/ThreatLens

GitHub: TiltedLunar123/ThreatLens

一款轻量级 Python CLI 工具,用于解析 Windows 安全与 Sysmon 日志并自动检测暴力破解、横向移动、权限提升等攻击行为,告警直接映射 MITRE ATT&CK。

Stars: 0 | Forks: 0

Python 3.10+ Platform MIT License Tests MITRE ATT&CK

ThreatLens

面向安全分析师的日志分析与威胁狩猎 CLI
解析 Windows Security 与 Sysmon 日志。检测攻击行为。获取映射至 MITRE ATT&CK 的可操作告警。

## 什么是 ThreatLens? ThreatLens 是一款 Python 命令行工具,用于接收 Windows Security 和 Sysmon 事件日志,对其运行模块化检测规则,并生成带有 MITRE ATT&CK 映射的严重性分级告警。专为 SOC 分析师、应急响应人员和蓝队学习者打造。 安全团队每天需处理成千上万条日志事件。ThreatLens 自动化初步分类工作——捕捉暴力破解攻击、横向移动、权限提升和可疑进程执行——让分析师能专注于实质性调查。 ## 功能特性 | 检测项 | 捕获内容 | MITRE 技术 | |---|---|---| | **暴力破解 / 密码喷洒** | 来自单一源的大量失败登录;区分针对性暴力破解与密码喷洒 | T1110 | | **横向移动** | 单一账户快速对多台主机进行认证(网络登录、RDP) | T1021 | | **权限提升** | 向非系统账户分配敏感权限(SeDebugPrivilege, SeTcbPrivilege) | T1134 | | **可疑进程执行** | LOLBins、编码 PowerShell、certutil 下载载荷、SAM 转储、服务创建 | T1059 | **此外:** - 严重性分级:CRITICAL / HIGH / MEDIUM / LOW - JSON 与 CSV 报告导出,便于 SIEM 接入 - 通过 YAML 配置检测阈值 - 内置样本攻击数据——30 秒内即可演示 - 18 个单元测试覆盖所有检测模块 ## 快速开始 ``` # Clone git clone https://github.com/TiltedLunar123/ThreatLens.git cd ThreatLens # 设置环境 python -m venv .venv source .venv/bin/activate # Linux/macOS .venv\Scripts\activate # Windows # 安装 pip install -r requirements.txt pip install -e . # 针对示例攻击数据运行 threatlens scan sample_data/sample_security_log.json ``` ## 使用方法 ``` # 基本扫描 threatlens scan sample_data/sample_security_log.json # 详细模式 — 显示每个警报的证据 threatlens scan sample_data/sample_security_log.json --verbose # 仅显示 HIGH 和 CRITICAL 警报 threatlens scan sample_data/sample_security_log.json --min-severity high # 导出 JSON 报告 threatlens scan sample_data/sample_security_log.json -o report.json -f json # 导出 CSV 报告 threatlens scan sample_data/sample_security_log.json -o report.csv -f csv # 扫描日志文件目录 threatlens scan /path/to/logs/ # 列出所有检测规则 threatlens rules # 免安装运行 python -m threatlens.cli scan sample_data/sample_security_log.json ``` ## 示例输出 ``` _____ _ _ _ |_ _| |__ _ __ ___ __ _| |_| | ___ _ __ ___ | | | '_ \| '__/ _ \/ _` | __| | / _ \ '_ \/ __| | | | | | | | | __/ (_| | |_| |__| __/ | | \__ \ |_| |_| |_|_| \___|\__,_|\__|_____\___|_| |_|___/ Log Analysis & Threat Hunting CLI v1.0.0 Scanning 1 file(s)... Parsed 26 events from sample_security_log.json ============================================================ SCAN SUMMARY ============================================================ Events analyzed: 26 Alerts generated: 10 Scan duration: 0.00s CRITICAL 1 HIGH 4 MEDIUM 3 LOW 2 ============================================================ [CRITICAL] Suspicious Process: SAM registry hive access Time: 2025-01-15 09:15:00 Detail: Process 'reg.exe' executed with suspicious command line on DC-01 by jdoe MITRE: Execution / T1059 - Command and Scripting Interpreter Action: Review the full command line and parent process... [HIGH] Brute-Force Detected Time: 2025-01-15 08:30:01 Detail: 7 failed logon attempts from 10.0.1.50 targeting 1 account(s) within 300s MITRE: Credential Access / T1110 - Brute Force Action: Investigate source 10.0.1.50. Consider blocking the IP... [HIGH] Lateral Movement Detected Time: 2025-01-15 09:00:00 Detail: User 'svc_deploy' authenticated to 4 distinct hosts within 600s MITRE: Lateral Movement / T1021 - Remote Services [HIGH] Suspicious Privilege Assignment Time: 2025-01-15 09:05:00 Detail: User 'jdoe' was assigned sensitive privileges: SeDebugPrivilege, SeTcbPrivilege MITRE: Privilege Escalation / T1134 - Access Token Manipulation [HIGH] Suspicious Process: Base64-encoded PowerShell command Time: 2025-01-15 09:10:00 Detail: Process 'powershell.exe' executed with suspicious command line MITRE: Execution / T1059 - Command and Scripting Interpreter ``` ## 项目结构 ``` ThreatLens/ ├── threatlens/ │ ├── __init__.py # Package metadata │ ├── cli.py # CLI argument parsing & command routing │ ├── parser.py # JSON/NDJSON log parsing & normalization │ ├── models.py # LogEvent, Alert, Severity data models │ ├── report.py # Terminal output, JSON/CSV export │ ├── utils.py # Helpers (tables, colors, time grouping) │ └── detections/ │ ├── __init__.py # Detection registry │ ├── base.py # Abstract DetectionRule base class │ ├── brute_force.py # Failed logon burst & spray detection │ ├── lateral_movement.py # Multi-host auth pattern detection │ ├── privilege_escalation.py # Sensitive privilege monitoring │ └── suspicious_process.py # LOLBin & command-line analysis ├── rules/ │ └── default_rules.yaml # Tunable detection thresholds ├── sample_data/ │ └── sample_security_log.json # 26 events simulating a real attack chain ├── tests/ │ └── test_detections.py # 18 unit tests across all modules ├── setup.py ├── requirements.txt ├── .gitignore ├── LICENSE └── README.md ``` ## 运行测试 ``` pip install pytest pytest tests/ -v ``` ``` tests/test_detections.py::TestParser::test_parse_timestamp_iso PASSED tests/test_detections.py::TestParser::test_parse_event_basic PASSED tests/test_detections.py::TestBruteForce::test_triggers_on_burst PASSED tests/test_detections.py::TestBruteForce::test_password_spray_detected PASSED tests/test_detections.py::TestLateralMovement::test_triggers_on_multi_host PASSED tests/test_detections.py::TestPrivilegeEscalation::test_triggers_on_debug_priv PASSED tests/test_detections.py::TestSuspiciousProcess::test_encoded_powershell PASSED tests/test_detections.py::TestSuspiciousProcess::test_sam_dump PASSED ... 18 passed in 0.02s ``` ## 日志格式 ThreatLens 接受 JSON 数组或换行符分隔的 JSON (NDJSON)。其结构映射标准的 Windows Event Log JSON 导出格式: ``` { "TimeCreated": "2025-01-15T08:30:01Z", "EventID": 4625, "Computer": "WS-PC01", "EventData": { "TargetUserName": "admin", "IpAddress": "10.0.1.50", "LogonType": 3 } } ``` **使用 PowerShell 导出您自己的日志:** ``` Get-WinEvent -LogName Security -MaxEvents 1000 | Select-Object TimeCreated, Id, MachineName, Message | ConvertTo-Json | Out-File security_events.json ``` ## 工作原理 1. **解析 (Parse)** — 从 JSON/NDJSON 文件加载日志,并无论源格式如何,均将其规范化为通用的 `LogEvent` 数据模型 2. **检测 (Detect)** — 四条模块化检测规则通过时间窗口分组、字段关联和正则匹配,分析事件流中的攻击模式 3. **报告 (Report)** — 告警按严重性分级,映射到 MITRE ATT&CK,并附上可操作的建议展示。导出为 JSON 或 CSV 以供进一步分析 ## 安全与伦理 ThreatLens 是一款**仅用于防御**的工具。它分析您拥有或经授权审计的系统上已存在的日志。它**不会**: - 访问远程系统或网络 - 捕获或嗅探网络流量 - 利用任何漏洞 - 生成攻击流量或载荷 请仅在您拥有明确授权分析的系统与日志上使用此工具。 ## 路线图 - [ ] 原生 EVTX 解析(直接读取 `.evtx` 文件,无需导出) - [ ] 基于 YAML 的自定义规则引擎,支持用户定义检测 - [ ] Sigma 规则兼容层 - [ ] 包含严重性图表的 HTML 报告生成 - [ ] 实时日志跟踪模式 (`--follow`) - [ ] Syslog / CEF 输入格式支持 - [ ] Elasticsearch 输出连接器 - [ ] 攻击时间线可视化 ## 作者 **Jude Hilgendorf** — [GitHub](https://github.com/TiltedLunar123) ## 许可证 MIT License。详情请见 [LICENSE](LICENSE)。
标签:AMSI绕过, CLI, Cloudflare, Conpot, EDR, Homebrew安装, MITRE ATT&CK, PE 加载器, Python, Sysmon, WiFi技术, Windows安全, 事件日志, 免杀技术, 协议分析, 可疑进程, 威胁情报, 威胁检测, 安全运营, 库, 应急响应, 开发者工具, 恶意行为分析, 扫描框架, 文档结构分析, 无后门, 暴力破解检测, 权限提升, 横向移动, 渗透测试防御, 红队行动, 编程规范, 网络安全, 脆弱性评估, 逆向工具, 隐私保护