onurtnc/loghunter

GitHub: onurtnc/loghunter

一个零依赖的轻量级日志检测引擎,通过类似 Sigma 的 YAML 规则扫描多格式系统日志并生成附带 MITRE ATT&CK 标签的告警报告。

Stars: 0 | Forks: 0

# LogHunter **类似 Sigma 规则运行、零依赖的日志检测引擎(迷你 SIEM)。** ![Python](https://img.shields.io/badge/python-3.8%2B-blue) ![License](https://img.shields.io/badge/license-MIT-green) ![Dependencies](https://img.shields.io/badge/dependencies-none-brightgreen) ![Tests](https://img.shields.io/badge/tests-19%20passing-success) 读取 Windows Sysmon/Security、Linux `auth.log`、JSON、NDJSON 和 CSV 日志;通过 YAML 规则进行匹配;生成带有 MITRE ATT&CK 标签的告警。可输出控制台、JSON、CSV 和 HTML 报告。**无需任何外部库** —— 如果没有 PyYAML,将自动启用内置的迷你 YAML parser。 ## 为什么需要它? 商业 SIEM 既昂贵又臃肿。而 SOC 分析师日常面临的大部分工作 其实就是一个问题:“这个日志文件里有没有恶意行为?” LogHunter 正是为此而生: 提供一个文件,运行规则,即可获得按优先级排序的发现列表。 ## 特性 | 特性 | 说明 | |---|---| | 类似 Sigma 的规则 | 支持 `contains`, `startswith`, `endswith`, `re`, `cidr`, `gt/lt`, `all` modifier | | 复合条件 | `selection and not filter`, `a and (b or c)`, `1 of sel_*`, `all of sel_*` | | 关联分析 | “5 分钟内 5 次登录失败”等阈值规则(`timeframe_config`) | | 多格式 parser | Sysmon/Security JSON, NDJSON, JSON array, syslog/auth.log, CSV, 纯文本 | | 字段标准化 | 自动展开嵌套 JSON,解析 `Event.EventData.Data` | | 风险评分 | 根据发现级别和数量生成 0-100 之间的单一分数 | | 输出格式 | 彩色控制台、JSON、CSV、单文件暗色主题 HTML 报告 | | CI 友好 | 通过 `--fail-on high` 在 pipeline 中返回 exit code 1 | | 噪声控制 | 自动去重 (dedup), `--min-level`, `--tag` 过滤器 | ## 安装 ``` git clone https://github.com//loghunter.git cd loghunter python -m loghunter samples/ # kurulum bile gerekmiyor ``` 如果想将其添加为系统命令: ``` pip install -e . loghunter samples/ ``` ## 使用方法 ``` # 扫描示例日志 python -m loghunter samples/ # 单一文件,强制 format python -m loghunter samples/sysmon.json -f json # 仅 high 及以上 rules python -m loghunter /var/log/auth.log --min-level high # 特定 ATT&CK technique python -m loghunter samples/ --tag attack.t1059 # 生成报告 python -m loghunter samples/ --html rapor.html --json bulgular.json --csv bulgular.csv # 你的自定义 rule 目录 python -m loghunter logs/ -r /opt/kurallar/ # CI: 如果存在 critical 发现则中断 build python -m loghunter logs/ --fail-on critical --quiet ``` ### 示例输出 ``` ============================================================================== LogHunter - Tespit Raporu ============================================================================== Dosya: 3 Olay: 29 Kural: 10 Alarm: 12 Risk skoru: [###################.] 97/100 Seviyeler: high:7 critical:3 medium:2 ------------------------------------------------------------------------------ [CRITICAL] LSASS Bellek Erisimi (Kimlik Bilgisi Hirsizligi) zaman : 2026-07-28 09:16:11 kaynak: sysmon.json:3 etiket: attack.t1003.001, attack.credential-access EventID : 10 Computer : WS-FIN-014 [HIGH] SSH Kaba Kuvvet Saldirisi (5x / 5dk) zaman : 2026-07-28 03:14:11 kaynak: auth.log:5 etiket: attack.t1110.001, attack.credential-access src_ip : 45.155.205.233 hit_count : 5 ``` ## 编写自定义规则 只需在 `rules/` 目录下创建一个 `.yml` 文件即可: ``` title: Supheli Zamanlanmis Gorev id: win-schtask-010 description: Kalicilik icin schtasks ile gorev olusturma. level: high logsource: product: windows service: sysmon detection: selection: EventID: 1 Image|endswith: \schtasks.exe suspicious: CommandLine|contains: - /create - powershell filter: User: 'NT AUTHORITY\SYSTEM' condition: selection and suspicious and not filter tags: - attack.t1053.005 - attack.persistence falsepositives: - Yazilim guncelleyicilerin olusturdugu gorevler ``` ### 支持的 modifier | Modifier | 示例 | 含义 | |---|---|---| | (无) | `EventID: 4625` | 完全匹配(支持 `*` 和 `?` 通配符) | | `contains` | `CommandLine\|contains: -enc` | 是否包含 | | `startswith` / `endswith` | `Image\|endswith: \cmd.exe` | 匹配开头 / 结尾 | | `re` | `_raw\|re: 'curl.*\|\s*bash'` | 正则表达式 | | `cidr` | `src_ip\|cidr: 10.0.0.0/8` | IP 范围 | | `gt` `gte` `lt` `lte` | `bytes\|gt: 100000` | 数值比较 | | `all` | `CommandLine\|contains\|all: [shadow, delete]` | 列表中的**所有**项都必须匹配 | ### 关联(阈值)规则 ``` detection: selection: event_type: ssh_failed_login timeframe_config: count: 5 # kac olay window_minutes: 5 # kac dakikalik pencerede group_by: [src_ip] # neye gore gruplansin condition: selection ``` ## 内置规则 | ID | 级别 | 标题 | |---|---|---| | `win-lsass-003` | critical | LSASS 内存访问(凭证窃取) | | `win-shadow-006` | critical | 删除卷影副本(勒索软件特征) | | `lnx-curl-pipe-103` | critical | 通过 `curl \| bash` 执行脚本 | | `win-ps-encoded-001` | high | 编码的 PowerShell 命令 | | `win-lolbin-002` | high | 通过 LOLBin 下载文件 | | `win-svc-004` | high | 可疑的服务安装 | | `win-bruteforce-005` | high | Windows 登录暴力破解 | | `lnx-ssh-bruteforce-101` | high | SSH 暴力破解 | | `lnx-root-login-102` | medium | Root 直接通过 SSH 登录 | | `lnx-persistence-104` | medium | Cron / systemd 持久化 | ## 架构 ``` loghunter/ ├── minyaml.py PyYAML yoksa devreye giren mini YAML parser ├── parsers.py Log formatlarini ortak olay sozlugune cevirir ├── rules.py Kural modeli, alan eslestirme, condition degerlendirici ├── engine.py Tarama dongusu, korelasyon, dedup, risk skoru ├── report.py Konsol / JSON / CSV / HTML ciktilari └── cli.py argparse arayuzu ``` 流程:`parsers` → 标准化事件 → `rules.matches()` → `engine` 告警 → `report`。 ## 测试 ``` python -m unittest discover -s tests -v # 或 pytest -v ``` ## 路线图 - [ ] 直接读取真实的 `.evtx` 文件 - [ ] 时间线 (timeline) HTML 视图 - [ ] 自动转换 Sigma repo 中的规则 - [ ] Syslog 监听模式(实时扫描) - [ ] ATT&CK Navigator JSON 输出 ## 免责声明 本工具旨在用于防御(蓝队)。请仅在您拥有授权的系统日志上 使用。生成的发现并非自动决策,而是**调查的起点**。 ## 许可证 MIT — 参见 [LICENSE](LICENSE)。
标签:AMSI绕过, Python, Sigma规则, URL发现, 威胁检测, 安全检测, 无后门, 目标导入, 逆向工具