fevra-dev/Shrike

GitHub: fevra-dev/Shrike

一款基于行为分析的 Python 网络取证工具,无需解密即可从 PCAP 中检测 C2 Beaconing、DNS 隧道、端口扫描等 20+ 威胁模式,并自动映射 MITRE ATT&CK。

Stars: 1 | Forks: 0

# Shrike **加密流量时代的网络取证工具。** [![Python](https://img.shields.io/badge/Python-3.11+-blue?style=flat-square&logo=python&logoColor=white)](https://python.org) [![License](https://img.shields.io/badge/License-MIT-green?style=flat-square)](LICENSE) [![MITRE ATT&CK](https://img.shields.io/badge/MITRE-ATT%26CK%C2%AE%20v15-red?style=flat-square)](https://attack.mitre.org) [![Tests](https://img.shields.io/badge/Tests-20%20passing-brightgreen?style=flat-square)]() Shrike 是一款 Python 网络取证工具,无需读取加密载荷即可检测 PCAP 文件中的威胁。它利用行为分析、流统计和时序模式来识别 C2 Beaconing、端口扫描、数据窃取、DNS 隧道、横向移动等——并将每项发现映射到 MITRE ATT&CK。 以[伯劳鸟](https://en.wikipedia.org/wiki/Shrike)命名——这是一种将猎物刺穿在尖刺上的猛禽。Shrike 则将威胁刺穿在证据之上。 ## 快速开始 ``` git clone https://github.com/fevra-dev/Shrike.git cd Shrike pip install -e . # 分析 PCAP shrike analyze capture.pcap # 生成交互式 HTML 报告 shrike analyze capture.pcap -o report.html # JSON 输出 shrike analyze capture.pcap --json-out -o results.json ``` ## 检测范围 | 检测模块 | 技术 | MITRE ATT&CK | |---|---|---| | **C2 Beaconing** | 到达间隔时间规律性、变异系数分析 | T1071.001, T1573 | | **端口扫描** | 通过唯一端口枚举检测 SYN/NULL/XMAS 扫描 | T1046 | | **数据窃取** | 上传/下载比例异常、流量阈值 | T1048 | | **DNS 隧道** | 熵评分、子域名长度、查询频率 | T1071.004 | | **HTTP/2 C2** | SETTINGS 帧分析、基于 ping 的隐蔽通道 | T1071.001 | | **NTLM Relay** | LLMNR 投毒、SMB 中继链检测 | T1557.001 | | **Kerberoasting** | SPN 请求异常、AS-REP Roasting 模式 | T1558 | | **云 C2** | Slack/Teams/DevTunnels webhook 滥用检测 | T1102.002 | | **IPv6 攻击** | Rogue RA、NA 投毒、SLAAC 滥用 | T1557.001 | | **OT/ICS 攻击** | Modbus 写线圈、DNP3 控制继电器、OT 扫描 | T0855, T0846 | | **WebSocket C2** | 具有 C2 模式的持久化 WebSocket 通道 | T1071.001 | | **mTLS C2** | Sliver/Mythic 双向 TLS 指纹识别 | T1573.002 | | **DNS Rebinding** | TTL 异常、IP 翻转检测 | T1557 | | **QUIC/HTTP3 C2** | 传输参数指纹识别、ALPN 分析 | T1095 | | **供应链** | 包管理器流量偏差 | T1195.002 | | **DGA 检测** | 字符 n-gram 困惑度、LLM 生成的域名评分 | T1568.002 | | **WASM 恶意软件** | HTTP 流量中的 WebAssembly 二进制检测 | T1059 | | **MCP 流量** | Model Context Protocol 异常检测 | T1071.001 | | **时序通道** | ISN 隐蔽通道、包间时序分析 | T1205 | | **CT 日志关联** | 新颁发证书的期限异常 | T1587.003 | | **Tor 出口节点检测** | 出口中继的实时共识验证 | T1090.003 | ## 架构 ``` PCAP File │ ▼ ┌────────────────────────────────┐ │ PCAP Parser │ │ Scapy (primary) + dpkt │ │ Normalized packet dicts │ └──────────────┬─────────────────┘ │ ▼ ┌────────────────────────────────┐ │ Flow Builder │ │ Bidirectional 5-tuple flows │ │ Forward/reverse tracking │ │ Payload + timestamp capture │ └──────────────┬─────────────────┘ │ ▼ ┌────────────────────────────────┐ │ Detection Registry │ │ │ │ 25+ detection modules │ │ Per-packet + per-flow analysis│ │ BaseDetector interface │ └──────────────┬─────────────────┘ │ ▼ ┌────────────────────────────────┐ │ Output │ │ Interactive HTML dashboard │ │ JSON report · CLI summary │ │ MITRE ATT&CK mapping │ │ SARIF (CI/CD integration) │ └────────────────────────────────┘ ``` ## HTML 报告 `--output report.html` 标志会生成一个独立的交互式仪表板,包含 26 个分析标签页: - **摘要** — 严重性细分、关键指标、攻击链可视化 - **发现** — 包含证据的所有检测结果,可按严重性过滤 - **时间线** — 按时间顺序重建攻击过程 - **MITRE ATT&CK** — 技术热力图及命中计数 - **网络图** — D3 力导向主机通信图 - **协议** — 使用 Chart.js 可视化的流量分布 - **指纹** — JA3/JA4/JARM/HASSH/QUIC 传输参数表 - **DNS** — 熵评分、DGA 分析、隧道检测 - **Beaconing** — 间隔分析图表、CV 评分 - **IOCs** — 妥协指标及富化数据 - **CVE 情报** — 匹配的 CVE 签名及 CISA KEV 状态 - **eBPF 归因** — 进程到流的映射(如果可用) - 以及更多:OT/ICS、云 C2、WebSocket、QUIC、IPv6、Kubernetes... ## 项目结构 ``` Shrike/ ├── shrike/ │ ├── __init__.py │ ├── cli.py # Click CLI entry point │ ├── engine.py # Analysis orchestrator │ ├── models.py # Finding, FlowRecord, Severity │ ├── core/ │ │ ├── parser.py # PCAP parsing (Scapy + dpkt) │ │ ├── flow_builder.py # Bidirectional flow aggregation │ │ └── zeek_navigator.py # Zeek log ingestion + ATT&CK Navigator │ ├── detection/ │ │ ├── base.py # BaseDetector abstract class │ │ ├── registry.py # Detector fan-out + error isolation │ │ ├── adapters.py # Built-in: port scan, exfil, beaconing │ │ ├── http2_c2.py # HTTP/2 covert channel detection │ │ ├── dns_rebinding.py # DNS rebinding attack detection │ │ ├── ntlm_relay.py # NTLM relay + LLMNR poisoning │ │ ├── cloud_c2.py # Cloud platform C2 detection │ │ ├── ot_attacks.py # OT/ICS protocol attack detection │ │ ├── k8s_attacks.py # Kubernetes attack detection │ │ ├── websocket_c2.py # WebSocket C2 detection │ │ ├── mtls_c2.py # Mutual TLS C2 fingerprinting │ │ ├── ipv6_attacks.py # IPv6 attack detection │ │ ├── quic_alpn.py # QUIC/HTTP3 C2 detection │ │ ├── mcp_traffic.py # MCP protocol anomaly detection │ │ ├── wasm_detector.py # WebAssembly malware detection │ │ ├── timing_firmware.py # Timing channel + firmware analysis │ │ └── ... # 25+ total detection modules │ ├── ml/ │ │ ├── anomaly.py # IsolationForest flow anomaly │ │ ├── clustering.py # HDBSCAN flow clustering │ │ ├── dga_detector.py # DGA + LLM-DGA scoring │ │ └── injection_scorer.py # LLM prompt injection classifier │ ├── enrichment/ │ │ ├── ct_logs.py # Certificate Transparency correlation │ │ └── tor_consensus.py # Tor exit relay verification │ ├── mitre/ │ │ └── mapper.py # ATT&CK technique lookup + enrichment │ ├── reporting/ │ │ ├── html_reporter.py # Jinja2 interactive HTML dashboard │ │ └── sarif_reporter.py # SARIF 2.1.0 output │ ├── templates/ │ │ └── report.html # 26-tab HTML report template │ ├── cve/ │ │ └── sync.py # CVE database sync │ ├── ebpf/ │ │ └── attribution.py # eBPF process-to-flow attribution │ └── fingerprinting/ │ └── quic_tp.py # QUIC transport parameter fingerprinting ├── tests/ │ ├── test_models.py # Data model unit tests │ ├── test_parser.py # PCAP parser tests │ ├── test_flow_builder.py # Flow aggregation tests │ ├── test_registry.py # Detection registry tests │ ├── test_adapters.py # Detector adapter tests │ ├── test_engine.py # Engine integration test │ ├── test_cli.py # CLI end-to-end tests │ ├── test_html_reporter.py # HTML report generation test │ ├── test_mitre_mapper.py # MITRE mapper tests │ └── test_integration.py # Full pipeline integration tests ├── pyproject.toml └── README.md ``` ## 开发 ``` # 以开发模式安装 pip install -e . # 运行测试 pytest tests/ -v # 运行特定测试 pytest tests/test_engine.py::test_engine_detects_port_scan -v ``` ### 添加检测模块 1. 在 `shrike/detection/` 目录下创建一个继承自 `BaseDetector` 的新类 2. 实现 `analyze_flow(flow: FlowRecord) -> list[Finding]` 3. 可选择实现 `analyze_packet()` 和 `finalize()` 4. 在 `shrike/detection/adapters.py` 的 `get_all_detectors()` 中注册 ``` from shrike.detection.base import BaseDetector from shrike.models import Finding, Severity, FlowRecord class MyDetector(BaseDetector): name = "my_detector" description = "Detects something suspicious" mitre_ids = ["T1234"] def analyze_flow(self, flow: FlowRecord) -> list[Finding]: if some_condition(flow): return [Finding( detector=self.name, finding_type="SUSPICIOUS_THING", severity=Severity.HIGH, src_ip=flow.src_ip, dst_ip=flow.dst_ip, ... )] return [] ``` ## 作者 **Fevra** — 安全开发者 [![GitHub](https://img.shields.io/badge/GitHub-fevra--dev-black?style=flat-square&logo=github)](https://github.com/fevra-dev) [![作品集](https://img.shields.io/badge/Portfolio-fevra.dev-orange?style=flat-square)](https://fevra.dev) ## 许可证 MIT License — 详情请参阅 [LICENSE](LICENSE)。 MITRE ATT&CK 是 The MITRE Corporation 的注册商标。
标签:AMSI绕过, C2检测, Cloudflare, DNS隧道, HTML报告, MITRE ATT&CK, PCAP分析, Python, 信标检测, 加密流量分析, 威胁检测, 插件系统, 数据渗透, 数据窃取, 数据统计, 无后门, 模拟器, 横向移动, 流量统计分析, 深度包检测, 端口扫描, 编程规范, 网络协议分析, 网络安全, 网络安全分析, 逆向工具, 隐私保护