0xPersist/beacon-score

GitHub: 0xPersist/beacon-score

多信号 C2 信标检测工具,通过关联 Zeek 日志与 PCAP 快速评分并排名可疑目标。

Stars: 0 | Forks: 0

# beacon-score **从 Zeek 日志或 PCAP 中进行多信号 C2 信标检测。** beacon-score 关联 `conn.log`、`dns.log` 和 `ssl.log`,生成带有各信号分解、ATT&CK 技术映射和可配置信号权重的 C2 信标候选排名列表。放入 PCAP 文件后会自动处理 Zeek 调用。 ## 为什么使用 beacon-score 大多数信标检测工具假设你已经拥有一个完整的 SIEM 堆栈。beacon-score 适用于你现有的数据:来自传感器的 PCAP 或捕获目录中的 Zeek 日志。无需数据库、无需代理、无需配置开销。在事件响应、威胁狩猎或实验室验证过程中,秒级即可运行。 评分模型会同时关联所有三种日志源的信号。某个目标在连接间隔、字节比例和自签名证书三个方面均表现出规律性特征时,其得分将显著高于仅触发单一信号的来源。单一信号检测产生噪声,而多信号关联才能带来有效发现。 ## 信号 每个信号独立评分(0.0–1.0),加权后求和得到最终信标概率分数。所有权重均可配置。 | 信号 | ATT&CK | 描述 | |---|---|---| | `interval_regularity` | T1071 | 连接间隔的变异系数较低 — 自动化来源 | | `jitter_low` | T1571 | 相对于间隔均值的平均绝对偏差 — 非人类定时 | | `byte_ratio_uniform` | T1095 | 会话间原始/响应字节比例均匀 — 编码型保持连接 | | `session_frequency` | T1071.001 | 相对于时间窗口的会话频率高 — 自动轮询循环 | | `long_connection` | T1071.004 | 长连接持续存在 — 隧道通道或保持连接 | | `sni_cert_mismatch` | T1573.002 | TLS SNI 与证书 CN/SAN 不匹配 — 域名前置或规避 | | `dns_entropy_high` | T1568.002 | 子域名标签的高香农熵 — DGA 或 DNS 隧道 | | `short_cert_lifetime` | T1587.003 | 证书有效期较短 — 攻击者颁发的临时基础设施 | | `self_signed_cert` | T1587.003 | 发行人与主题相同 — 攻击者控制的 TLS 端点 | | `low_ttl_variance` | T1568 | 目标 DNS TTL 变异度低 — 快速切换相邻行为 | 置信度等级: | 分数 | 置信度 | |---|---| | ≥ 0.80 | 严重 | | ≥ 0.60 | 高 | | ≥ 0.40 | 中 | | ≥ 0.20 | 低 | | < 0.20 | 信息 | ## 安装 需要 Python 3.10+。 ``` git clone https://github.com/0xPersist/beacon-score cd beacon-score pip install . ``` 可选的 Rich 终端输出(推荐): ``` pip install ".[rich]" ``` ## 用法 ### 从 Zeek 日志 ``` beacon-score --conn conn.log --dns dns.log --ssl ssl.log ``` 三个日志文件均为可选。缺少某个日志时,相关信号会被跳过,整体评分仍可正常进行。 ``` # 仅 conn.log — 间隔、抖动、字节比、频率、持续时间信号 beacon-score --conn conn.log # conn + dns — 增加熵评分 beacon-score --conn conn.log --dns dns.log ``` ### 从 PCAP 需要安装 Zeek 并确保其在 PATH 中。 ``` beacon-score --pcap capture.pcap ``` Zeek 会自动加载 `base/protocols/conn`、`base/protocols/dns` 和 `base/protocols/ssl`,生成日志、评分并清理临时文件。 ### 输出 ``` # 终端表格 + JSON 报告到文件 beacon-score --conn conn.log --dns dns.log --ssl ssl.log --out report.json # 每个候选者的信号分解面板 beacon-score --conn conn.log --dns dns.log --ssl ssl.log --detail # 仅 JSON(管道友好型) beacon-score --conn conn.log --json-only | jq '.beacon_candidates[0]' # 仅前 5 名,最少 10 个会话,得分阈值 beacon-score --conn conn.log --top 5 --min-sessions 10 --threshold 0.30 ``` ### 自定义权重 生成权重文件: ``` beacon-score --generate-config weights.yaml ``` 编辑权重后,在每次运行时传入: ``` beacon-score --conn conn.log --config weights.yaml ``` 权重为 0.0 到 1.0 之间的浮点数,无需总和为 1.0。将权重设为 0.0 会完全禁用该信号。 ## JSON 报告格式 ``` { "beacon_candidates": [ { "destination": "185.220.101.45", "total_score": 0.783, "confidence": "HIGH", "connection_count": 180, "first_seen": "2024-11-14 12:00:00", "last_seen": "2024-11-14 17:59:00", "ports": [443], "protocols": ["tcp"], "attack_techniques": [ {"id": "T1071", "name": "Application Layer Protocol"}, {"id": "T1587.003", "name": "Digital Certificates"} ], "signals": [ { "name": "interval_regularity", "score": 0.981, "weight": 0.25, "weighted": 0.2452, "fired": true, "evidence": "CoV=0.019, mean_interval=60.1s over 179 sessions", "attack": {"id": "T1071", "name": "Application Layer Protocol"} } ], "raw_intervals_sample": [60.1, 59.8, 60.3, 60.0] } ] } ``` ## 测试 生成合成日志并运行检测: ``` python scripts/gen_sample_logs.py beacon-score --conn sample_logs/conn.log --dns sample_logs/dns.log --ssl sample_logs/ssl.log --detail ``` 样本日志生成器会生成: - 60 秒周期的规则信标(自签名证书,预期为 HIGH/CRITICAL) - 具有中等抖动的 5 分钟信标(预期为 MEDIUM) - 高熵 DGA 风格 DNS 流量(预期为 LOW/MEDIUM) - 正常浏览噪声(预期为 INFORMATIONAL) 运行测试套件: ``` pip install pytest pytest tests/ -v ``` ## 参数标志 ``` input: --pcap FILE Raw PCAP. Zeek invoked automatically. --conn FILE Zeek conn.log (TSV or JSON, optionally gzipped) --dns FILE Zeek dns.log --ssl FILE Zeek ssl.log output: --out FILE Write JSON report to file --json-only Suppress terminal output, print JSON to stdout --detail Show per-signal breakdown for each candidate --top N Number of candidates to show (default: 20) scoring: --config FILE YAML or TOML weights config --min-sessions N Minimum session count per destination (default: 5) --include-private Include RFC1918/loopback destinations --threshold FLOAT Only output candidates >= this score utility: --generate-config FILE Write default weights config and exit --version ``` ## 日志格式支持 同时支持并自动识别以下 Zeek 日志格式: - **TSV** — 带有 `#fields` / `#types` 头的经典 Zeek 格式 - **JSON** — 每行 JSON 格式(`LogAscii::use_json=T`) - **Gzipped** — 可直接读取 `.log.gz` 文件而无需解压 ## 限制 - 加密载荷:字节比例信号在 QUIC 或 HTTP/3 上可靠性较低,因帧结构不同 - 短捕获窗口:判断间隔规律性至少需要每个目标 3 个会话 - IPv6:日志解析已支持,私有地址过滤涵盖 `::1` 和 `fe80::` - PCAP 模式依赖 Zeek;若不可用,请使用 `zeek -r capture.pcap LogAscii::use_json=T` 预生成日志 ## 相关项目 - [RITA](https://github.com/activecm/rita) — 需要 MongoDB 的完整信标分析平台 - [Zeek](https://zeek.org) — 网络分析框架 - [ATT&CK Navigator](https://mitre-attack.github.io/attack-navigator/) — 技术可视化工具 ## 许可证 MIT
标签:Beacon 检测, C2 检测, DNS 日志, IP 地址批量处理, PB级数据处理, PCAP 分析, SSL 日志, T1071, T1071.001, T1095, T1568, T1571, T1573, T1573.002, T1587, T1587.003, Zeek 日志分析, 多信号关联, 安全运维, 日志关联, 网络威胁检测, 误配置预防, 逆向工具