4161726f6e/mirage

GitHub: 4161726f6e/mirage

Mirage 是一款企业网络流量模拟工具,通过生成带有 MITRE ATT&CK 标签的合成 PCAP 文件及配套 Sigma/Suricata/Zeek/Windows 日志,为蓝队训练和检测工程提供完整的数据支撑。

Stars: 0 | Forks: 0

# Mirage 用于蓝队训练、检测工程和桌面演练的企业网络流量模拟工具。 Mirage 可以通过单条命令生成逼真的合成 PCAP 捕获数据,并附带一套完整的检测工件 —— 包括 Sigma 规则、Suricata 规则、Zeek 日志以及相关的 Windows 事件日志。每个数据包都标记了 MITRE ATT&CK 元数据,每个攻击事件都有对应的端点日志条目,每个规则文件都引用了其源自捕获数据中的真实 IP 和 TTP。 ``` python3 -m mirage --mode both --users 100 --threat-actor APT29 --output exercise.pcapng ``` 一条命令即可生成: | 文件 | 描述 | |------|-------------| | `exercise.pcapng` | 包含编码 MITRE 标签的 EPB 帧注释的 PCAPNG 文件 | | `exercise.json` | 清单:拓扑、数据包计数、完整攻击事件日志 | | `exercise_report.pdf` | 15 页的分析报告 | | `exercise.sigma.yml` | Sigma 规则 —— 每个 TTP 包含一个 SPECIFIC + 一个 GENERIC 规则 | | `exercise.rules` | Suricata IDS 规则 (SID 9000000+) | | `exercise_rules.md` | 包含误报说明的分析师指南 | | `exercise_conn.log` | Zeek conn.log (包含 `label`/`mitre_phase`/`mitre_ttp` 列) | | `exercise_dns.log` | Zeek dns.log | | `exercise_http.log` | Zeek http.log | | `exercise_ssl.log` | Zeek ssl.log | | `exercise_notice.log` | Zeek notice.log (每个攻击阶段一条记录) | | `exercise_events.json` | Windows 安全 + 系统事件 (NDJSON) | | `exercise_sysmon.json` | Sysmon Operational 事件 (NDJSON) | ## 安装说明 **选项 A —— pip 安装 (推荐)** ``` pip install mirage mirage --mode both --users 100 --output exercise.pcapng ``` **选项 B —— 从源码运行,无需安装** 解压发布归档文件,然后在 `mirage/` 目录内执行: ``` # 推荐 — 通过绝对路径可在任何工作目录中运行: python3 /path/to/mirage/run.py --mode both --users 100 --output exercise.pcapng # 当你的 shell 已经处于 mirage/ 根目录时也可运行: python3 run.py --mode both --users 100 --output exercise.pcapng python3 -m mirage --mode both --users 100 --output exercise.pcapng ``` **环境要求**: Python ≥ 3.8, scapy ≥ 2.5.0, reportlab ≥ 4.0.0, PyYAML ≥ 6.0 ``` pip install scapy reportlab PyYAML ``` 在 Linux 上,Scapy 需要原始套接字访问权限才能生成数据包: ``` sudo setcap cap_net_raw+eip $(which python3) # 或使用 sudo 运行 ``` ## 快速开始 ``` # 仅限良性企业流量 — 用于 SIEM 基线训练 mirage --mode benign --users 200 --duration 28800 --output monday.pcapng # 完整攻击链 — 通用 9 阶段入侵 mirage --mode both --users 100 --seed 42 --output exercise.pcapng # 命名威胁行为者配置文件 mirage --mode both --users 100 --threat-actor APT29 --output apt29.pcapng # 将攻击注入到现有的真实捕获中 mirage --blend-pcap monday.pcapng --blend-attack \ --threat-actor Lazarus --output monday_plus_lazarus.pcapng # 列出所有可用的威胁行为者配置文件 mirage --list-actors # 跳过检测输出(速度更快,仅生成 PCAP + PDF) mirage --mode both --no-detections --output quick.pcapng ``` ## 威胁行为者画像 五个内置画像模拟了真实威胁行为者的攻击手法: | 行为者 | 来源 | 关键 TTP | Beacon | |-------|--------|--------------|--------| | APT29 | 俄罗斯 SVR | 被动 LDAP 侦察, DCSync, 无端口扫描 | HTTPS 60 min ±30% | | Lazarus | 朝鲜 RGB | EternalBlue 蠕虫, 快速 C2, 批量数据外发 | HTTPS 5 min ±15% | | FIN7 | 俄罗斯/乌克兰 | Cobalt Strike, Kerberoasting, 针对 POS | HTTPS 60 s ±15% | | VoltTyphoon | 中国 MSS | 仅 LOLBin, WMI 执行, 2 小时 DNS C2 | DNS 2 h ±50% | | LAPSUS$ | 南非/英国 | MFA 推送轰炸, OAuth 盗窃, 无恶意软件 | HTTPS 30 s ±5% | ### 自定义剧本 无需修改 Python 代码即可添加新的威胁行为者。只需将 YAML 文件放入 `playbooks/` 目录: ``` name: BlackCat aliases: [ALPHV, Noberus] origin: "Russia (criminal)" motivation: "Ransomware-as-a-service" description: "RaaS group using Rust-based ransomware..." mitre_group_id: G1016 references: - https://www.cisa.gov/news-events/cybersecurity-advisories/aa23-061a beacon_protocol: https beacon_interval_s: 45 beacon_jitter_pct: 0.20 c2_domains: ["{rand}.onion-proxy.net"] c2_user_agents: ["Mozilla/5.0 ...Chrome/121..."] persistence_mech: "Scheduled task + registry run key" phase_offsets: recon: 0.03 initial_access: 0.06 command_and_control: 0.10 credential_access: 0.25 lateral_movement: 0.40 exfiltration: 0.70 chain: - phase: recon ttp: T1046 mitre_key: nmap_syn note: "SYN scan targeting RDP and SMB" wireshark_filter: "tcp.flags.syn==1 and ip.src=={attacker_ip}" analyst_note: "Nmap-style scan. Look for SYN-only from single source." steps: - generator: gen_nmap_syn src: attacker dst: targets target_count: 4 - phase: exfiltration ttp: T1041 mitre_key: exfil_https note: "Pre-encryption exfil for double-extortion" wireshark_filter: "ssl and ip.src=={pivot_ip} and ip.dst=={c2_ip}" analyst_note: "High-volume outbound HTTPS to raw IP." steps: - generator: gen_exfil_https src: pivot dst: c2 ``` ``` mirage --threat-actor BlackCat --playbooks-dir ./my_playbooks/ --output blackcat.pcapng ``` 完整的 YAML schema 和生成器参考请参阅 `docs/playbook_authoring.md`。 ## 检测工程输出 ### Sigma 规则 每个攻击阶段都会在 `exercise.sigma.yml` 中生成两条规则: - **SPECIFIC**: 使用本次运行的真实 IP —— 可直接用作针对生成 PCAP 的回归测试 - **GENERIC**: 与 IP 无关的 TTP 类检测 —— 可直接投入你的 SIEM 生产环境 ``` # SPECIFIC — 匹配此确切捕获 title: 'APT29 credential_access (T1558.003) — Specific' logsource: product: windows service: security detection: selection: EventID: 4769 TicketEncryptionType: '0x17' IpAddress: '10.2.0.7' condition: selection level: high # GENERIC — 匹配任何 Kerberoasting title: 'MITRE T1558.003 — Credential Access Detection' detection: selection: EventID: 4769 TicketEncryptionType: '0x17' |count() by IpAddress > 3 condition: selection level: medium ``` 使用 [pySigma](https://github.com/SigmaHQ/pySigma) 转换为你的 SIEM 格式: ``` sigma convert -t splunk -p splunk_windows exercise.sigma.yml sigma convert -t elastic -p ecs_windows exercise.sigma.yml ``` ### Suricata 规则 ``` # 针对生成的捕获测试规则 suricata -r exercise.pcapng -S exercise.rules -l /tmp/suricata_logs cat /tmp/suricata_logs/fast.log ``` 规则采用了协议级精确的字节匹配模式:Kerberoasting 针对 UDP/88 端口并带有 RC4 etype 签名,EternalBlue 针对 TCP/445 端口并带有 SMBv1 魔数,DNS 隧道使用 `dsize: >80` 并带有 TXT qtype 阈值。 ### Zeek 日志 这五个 Zeek 日志文件在每行末尾包含三个非标准列:`label`、`mitre_phase` 和 `mitre_ttp`。它们为 SIEM 训练提供了真实标注。 ``` # Splunk:查找所有恶意流及其 TTPs index=zeek sourcetype=bro_conn label=malicious | stats count by mitre_phase mitre_ttp id.orig_h id.resp_h # 检测 DNS 隧道 index=zeek sourcetype=bro_dns mitre_ttp=T1071.004 | table ts id.orig_h query answers # Zeek notice.log 条目 — 每个攻击阶段一条 index=zeek sourcetype=bro_notice | table ts note msg src dst ``` ### Windows 事件日志 `_events.json` 和 `_sysmon.json` 文件采用 NDJSON 格式 —— 每行一个 JSON 对象 —— 兼容 Splunk Universal Forwarder、Elastic/winlogbeat 和 Microsoft Sentinel。 ``` # Splunk:查找 Kerberoasting 事件 index=endpoint EventID=4769 TicketEncryptionType="0x17" label=malicious | table TimeCreated Computer EventData.TargetUserName EventData.ServiceName correlation_id # 使用 correlation_id 向网络进行 Pivot # correlation_id 的值是一个 Wireshark display filter: # "kerberos and ip.src==10.2.0.7 and kerberos.msg_type==12" ``` 每个恶意端点事件上的 `correlation_id` 字段包含了来自对应网络事件的 Wireshark 显示过滤器,从而实现直接的跨源关联。 ## 协议覆盖范围 49 个数据包生成器,涵盖: **企业基线**: ARP, STP, LLDP, DHCP, DHCPv6, DNS (包含基于 TTL 的缓存模型和三峰延迟), ICMP, ICMPv6 ND, NetBIOS, LLMNR, mDNS, SSDP, IGMP, NTP, SNMP, Syslog, HTTP (包含响应多样性 200/304/301/206/404), HTTP/2, TLS (包含会话恢复/0-RTT), TLS-resumed, SMTP STARTTLS, IMAP IDLE, SMB2, SSH, Kerberos, LDAP, WinRM, OCSP, IPP **攻击链**: ICMP 扫描, SYN 扫描, RDP 暴力破解, EternalBlue (MS17-010), Kerberoasting, Mimikatz/LSASS, Pass-the-Hash, PsExec, HTTP C2, DNS 隧道, HTTPS 数据外发, LDAP 侦察 (BloodHound 风格), DCSync, WMI 远程执行, MFA 疲劳攻击, 慢速 DNS C2, 长间隔 HTTPS C2 **数据包保真度**: 针对每台主机的 IP.id 计数器带有区分操作系统的步长,符合操作系统特征的 TCP SYN 选项 (Linux 对比 Windows),基于 DNS TTL 的缓存抑制,TLS 会话票据恢复,HTTP/2 二进制分帧,TCP 重传注入 (默认 0.2%),延迟 ACK 合并 (40% 的纯 ACK),IP 分片,外部流量的 TTL 跳数递减 ## CLI 参考 ``` # 在 pip install 之后: mirage [options] # 从源码(在任何地方运行 run.py,或者在 mirage/ 根目录下使用 -m): python3 run.py [options] mirage [options] Simulation: --mode {benign,malicious,both,report-only} --users N simulated workstation users (default: 100) --servers N additional server hosts (default: 10) --duration S capture duration in seconds (default: 3600) --day-offset H hour of day for simulation start (default: 8) --subnets {1-6} number of subnets to simulate --vlan enable 802.1Q VLAN tagging --seed N random seed for reproducibility --retrans-rate R TCP retransmission rate (default: 0.002) Threat actors: --threat-actor NAME profile name: APT29, Lazarus, FIN7, VoltTyphoon, LAPSUS --playbooks-dir DIR directory of additional .yaml playbook files --list-actors list all available profiles and exit Blend mode: --blend-pcap FILE path to existing PCAP to augment --blend-attack inject synthetic attack into the blend --blend-noise add synthetic benign traffic to the blend Output: --output FILE output PCAPNG path (default: enterprise_output.pcapng) --no-report skip PDF report generation --no-detections skip Sigma/Suricata/Zeek/Windows event generation ``` ## 编程 API ``` from mirage import ( build_enterprise, write_pcapng, AttackContext, generate_sigma_rules, generate_suricata_rules, export_zeek_logs, generate_windows_events, load_playbook, load_all_playbooks, ) # 构建模拟 ctx = AttackContext(seed=42, mode="both", n_users=100, n_subnets=4, use_vlan=False, duration_s=3600, day_offset=8, output_file="exercise.pcapng", threat_actor="APT29") labeled, topo, ctx = build_enterprise( n_users=100, n_servers=10, duration=3600, day_offset=8, n_subnets=4, use_vlan=False, seed=42, mode="both", attack_ctx=ctx, threat_actor="APT29", ) # 写入输出 write_pcapng(labeled, "exercise.pcapng", topo) generate_sigma_rules(ctx, "exercise.pcapng") generate_suricata_rules(ctx, labeled, "exercise.pcapng") export_zeek_logs(labeled, ctx, "exercise.pcapng") generate_windows_events(ctx, labeled, "exercise.pcapng") # 检查结果 malicious = [lp for lp in labeled if lp.label == "malicious"] print(f"Attack phases: {set(lp.phase for lp in malicious)}") print(f"TTPs: {set(lp.ttp for lp in malicious)}") # 加载自定义 playbook profile = load_playbook("my_playbooks/BlackCat.yaml") print(f"Beacon: {profile.beacon_protocol} every {profile.beacon_interval_s}s") ``` ## 开发 ``` git clone https://github.com/YOUR_ORG/mirage cd mirage pip install -e ".[dev]" # 验证其是否有效 python3 run.py --list-actors # 运行测试 pytest tests/ -v # 附带覆盖率运行 pytest tests/ --cov=mirage --cov-report=term-missing # Lint ruff check mirage/ ``` ### 添加新生成器 1. 在 `generator.py` 中添加 `def gen_(pkts, attacker, ...) -> List[object]:` 2. 它将自动在 YAML 剧本中以 `generator: gen_` 的形式可用 3. 在 `tests/test_generators.py` 中添加测试 ### 添加新威胁行为者 在 `playbooks/` 目录中放入一个 YAML 文件。完整 schema 请参阅 `docs/playbook_authoring.md`。 ## 开源协议 MIT —— 详见 `LICENSE`。
标签:IP 地址批量处理, Python, 威胁情报, 开发者工具, 恶意代码分类, 无后门, 流量仿真, 漏洞靶场, 逆向工具, 防御检测