ahmetfkoc/attack-detection-homelab

GitHub: ahmetfkoc/attack-detection-homelab

一个基于 Elastic SIEM 和自定义 Sigma 规则的攻击检测家庭实验室,通过六个真实攻击场景的完整模拟与检测闭环,帮助安全从业者提升蓝队检测分析与红队攻击模拟能力。

Stars: 0 | Forks: 0

# 攻击检测家庭实验室 — Elastic SIEM + 自定义 Sigma 规则 这是一个文档齐全的家庭实验室,在其中会对 Windows Server 受害者虚拟机模拟真实攻击,使用 Elastic SIEM 8.x 进行检测,并且每个场景都由一个自定义的 Sigma 检测规则覆盖。每个场景都遵循一致的 **攻击 → 日志证据 → 检测规则 → 修复** 格式。 ## 实验室架构 ``` ┌──────────────────────────────────────────────────────────────────┐ │ Host Machine │ │ ┌─────────────────┐ ┌──────────────────┐ ┌────────────────┐ │ │ │ Kali Linux │ │ Windows Server │ │ Ubuntu SIEM │ │ │ │ (Attacker) │ │ 2019 (Victim) │ │ Elastic Stack │ │ │ │ 192.168.56.10 │ │ 192.168.56.20 │ │ 192.168.56.30 │ │ │ └────────┬────────┘ └────────┬─────────┘ └───────┬────────┘ │ │ └────────────────────┴─────────────────────┘ │ │ Host-Only Network (vboxnet0) │ └──────────────────────────────────────────────────────────────────┘ ``` | VM | OS | 角色 | IP | |---|---|---|---| | Attacker | Kali Linux 2024.x | 红队行动 | 192.168.56.10 | | Victim | Windows Server 2019 Eval | 目标 (Sysmon + Winlogbeat) | 192.168.56.20 | | SIEM | Ubuntu 22.04 LTS | Elastic Stack 8.x | 192.168.56.30 | ## 攻击场景 | # | 场景 | MITRE ATT&CK | Sigma 规则 | 检测 | |---|---|---|---|---| | 01 | 网络端口扫描 | [T1046](https://attack.mitre.org/techniques/T1046/) — 网络服务发现 | `port_scan_detection.yml` | Sysmon 事件 3 数量 | | 02 | 凭据转储 (Mimikatz/Procdump) | [T1003.001](https://attack.mitre.org/techniques/T1003/001/) — LSASS 内存 | `credential_dumping_lsass.yml` | Sysmon 事件 10 | | 03 | 反向 Shell (PowerShell + Meterpreter) | [T1059.001](https://attack.mitre.org/techniques/T1059/001/) — PowerShell | `reverse_shell_powershell.yml` | PS 事件 4104 | | 04 | 横向移动 (Pass-the-Hash) | [T1550.002](https://attack.mitre.org/techniques/T1550/002/) — Pass the Hash | `lateral_movement_pth.yml` | 安全事件 4624 | | 05 | 权限提升 (PrintSpoofer) | [T1134.001](https://attack.mitre.org/techniques/T1134/001/) — Token 窃取 | `privilege_escalation_token.yml` | Sysmon 事件 1 | | 06 | C2 Beaconing (HTTP beacon 模拟) | [T1071.001](https://attack.mitre.org/techniques/T1071/001/) — Web 协议 | `c2_beaconing.yml` | Sysmon 事件 3 模式 | 每个场景在 `attack-scenarios/NN_name/WRITEUP.md` 中都有专门的详细说明,涵盖了所有四个部分。 ## 快速开始 ### 前置条件 - [VirtualBox 7.x](https://www.virtualbox.org/wiki/Downloads) - 为虚拟机分配 12 GB 可用内存(建议 16 GB 以上) - [Windows Server 2019 Evaluation ISO](https://www.microsoft.com/en-us/evalcenter/evaluate-windows-server-2019)(免费,无需许可证) - [Kali Linux VirtualBox OVA](https://www.kali.org/get-kali/#kali-virtual-machines)(预构建版本) ### 步骤 1 — 设置 SIEM 虚拟机 (Ubuntu + Elastic Stack 8.x) ``` # 在 Ubuntu SIEM 虚拟机 (192.168.56.30) 上 chmod +x setup/setup_elastic.sh sudo ./setup/setup_elastic.sh # 访问 Kibana 地址:http://192.168.56.30:5601 ``` ### 步骤 2 — 配置 Windows 受害机 (Sysmon + Winlogbeat) ``` # 在 Windows Server 2019 虚拟机上 — 以管理员身份运行 .\setup\setup_windows_victim.ps1 -SiemIP 192.168.56.30 ``` 此步骤将安装: - 带有 SwiftOnSecurity 检测配置的 **Sysmon 15.x** - 转发至 SIEM 上 Logstash 的 **Winlogbeat 8.x** - 详细的审计策略 + PowerShell ScriptBlock/Module 日志 ### 步骤 3 — 准备 Kali 攻击机 ``` # 在 Kali 虚拟机 (192.168.56.10) 上 chmod +x setup/setup_kali.sh sudo ./setup/setup_kali.sh 192.168.56.20 192.168.56.30 192.168.56.10 ``` ### 步骤 4 — 导入 Kibana 仪表盘 ``` curl -X POST "http://192.168.56.30:5601/api/saved_objects/_import?overwrite=true" \ -H "kbn-xsrf: true" \ -u "elastic:$(sudo cat /root/.elastic_password)" \ --form file=@dashboards/homelab_dashboard.ndjson ``` ### 步骤 5 — 运行攻击场景 ``` # 示例:端口扫描 ./attack-scenarios/01_port_scan/run_attack.sh 192.168.56.20 # 示例:模拟 C2 beaconing(两个终端) ./attack-scenarios/06_c2_communication/run_attack.sh server 192.168.56.10 443 ./attack-scenarios/06_c2_communication/run_attack.sh client 192.168.56.10 443 10 ``` 然后检查 Kibana 中的相应告警。有关准确的 KQL 查询,请参阅每个场景的 `WRITEUP.md`。 ### 步骤 6 — 生成 HTML 事件报告 ``` cd reports pip install -r requirements.txt python3 generate_report.py # 打开:reports/homelab_report_.html ``` ## 目录结构 ``` project2-homelab/ ├── README.md ├── setup/ │ ├── setup_elastic.sh # Elastic Stack 8.x on Ubuntu │ ├── setup_windows_victim.ps1 # Sysmon + Winlogbeat on Windows │ └── setup_kali.sh # Attack tools on Kali ├── attack-scenarios/ │ ├── 01_port_scan/ │ │ ├── run_attack.sh # Nmap scan commands │ │ └── WRITEUP.md # Attack → Logs → Rule → Remediation │ ├── 02_credential_dumping/ │ ├── 03_reverse_shell/ │ ├── 04_lateral_movement/ │ ├── 05_privilege_escalation/ │ └── 06_c2_communication/ ├── sigma-rules/ │ ├── port_scan_detection.yml │ ├── credential_dumping_lsass.yml │ ├── reverse_shell_powershell.yml │ ├── lateral_movement_pth.yml │ ├── privilege_escalation_token.yml │ └── c2_beaconing.yml ├── reports/ │ ├── report_template.html # Jinja2 dark-themed template │ ├── generate_report.py # Render HTML from scenario data │ └── requirements.txt ├── dashboards/ │ └── homelab_dashboard.ndjson # Kibana dashboard (importable) └── docs/ └── lab_setup_guide.md # Full step-by-step VirtualBox guide ``` ## Sigma 规则 所有六个检测规则均位于 `sigma-rules/` 目录中,并遵循 [Sigma 规范](https://github.com/SigmaHQ/sigma)。它们可以使用 `sigma-cli` 转换为任何 SIEM 查询语言: ``` pip install sigma-cli sigma plugin install elasticsearch # for Kibana KQL/EQL sigma plugin install splunk # for Splunk SPL sigma plugin install kusto # for Microsoft Sentinel # 示例转换 sigma convert -t elasticsearch-dsl sigma-rules/credential_dumping_lsass.yml sigma convert -t splunk sigma-rules/lateral_movement_pth.yml sigma convert -t kusto sigma-rules/c2_beaconing.yml ``` ## 关键 Windows 事件 ID | 事件 ID | 来源 | 触发原因 | |---|---|---| | 4624 | Security | 成功登录 (类型 3 = 网络 — PtH 指标) | | 4648 | Security | 显式凭据登录 | | 4672 | Security | 分配特殊权限 | | 4688 | Security | 进程创建 (带有命令行审计) | | 4104 | PowerShell | 脚本块执行 (捕获混淆的 PS) | | 7045 | System | 安装新服务 (psexec 指标) | | 1 | Sysmon | 进程创建 | | 3 | Sysmon | 网络连接 | | 7 | Sysmon | 镜像 (DLL) 加载 | | 10 | Sysmon | 进程访问 — LSASS 凭据转储的关键 | | 22 | Sysmon | DNS 查询 | ## MITRE ATT&CK 覆盖范围 | 战术 | 技术 | 场景 | |---|---|---| | 侦察 | T1046 — 网络服务发现 | 01 端口扫描 | | 凭据访问 | T1003.001 — LSASS 内存 | 02 凭据转储 | | 执行 | T1059.001 — PowerShell | 03 反向 Shell | | 命令与控制 | T1071.001 — Web 协议, T1105 | 03, 06 | | 横向移动 | T1550.002 — Pass the Hash | 04 横向移动 | | 权限提升 | T1134.001 — Token 窃取 | 05 权限提升 | | 命令与控制 | T1132.001 — 标准编码 | 06 C2 Beaconing | ## 技术栈 - **VirtualBox 7.x** — 虚拟机监控程序 - **Elastic Stack 8.x** (Elasticsearch, Kibana, Logstash) — SIEM 和日志分析 - **Sysmon 15.x + SwiftOnSecurity 配置** — 端点遥测 - **Winlogbeat 8.x** — Windows 日志转发器 - **Kali Linux 2024.x** — 攻击者 VM (Metasploit, CrackMapExec, Impacket, Mimikatz) - **Sigma** — 供应商无关的检测规则格式 - **Python 3 + Jinja2** — HTML 报告生成 ## 详细设置指南 有关完整的演练,请参阅 [`docs/lab_setup_guide.md`](docs/lab_setup_guide.md),其中包括: - VirtualBox Host-Only 网络配置 - 每个虚拟机的硬件规格和 ISO 来源 - 每个虚拟机上的静态 IP 设置 - 常见问题排查
标签:AI合规, AMSI绕过, C2信标, Cloudflare, Elastic SIEM, Elastic Stack, HTML报告, IP 地址批量处理, MITRE ATT&CK, PB级数据处理, PE 加载器, PFX证书, Sigma规则, Sysmon, TGT, Windows Server, Winlogbeat, 凭证转储, 威胁检测, 安全模拟, 安全运维, 实验环境架构, 家庭实验室, 插件系统, 攻击检测, 攻防演练, 横向移动, 流量重放, 目标导入, 编程规范, 网络安全, 网络安全审计, 隐私保护