JamesBasele/wazuh-siem-homelab

GitHub: JamesBasele/wazuh-siem-homelab

一个基于 VirtualBox 和 Wazuh 构建的 SOC 家庭实验室项目,通过完整的 SIEM 部署、自定义检测规则和攻击模拟来展示安全运营实操技能。

Stars: 0 | Forks: 0

# 🛡️ SOC 家庭实验室 — VirtualBox 上的 Wazuh SIEM ![Wazuh](https://img.shields.io/badge/Wazuh-4.7.5-blue) ![Ubuntu](https://img.shields.io/badge/Ubuntu-22.04_LTS-orange) ![Windows](https://img.shields.io/badge/Windows-10_Pro-0078D6) ![VirtualBox](https://img.shields.io/badge/VirtualBox-7.x-183A61) ![Status](https://img.shields.io/badge/Status-Complete-brightgreen) 一个功能完备、可 hands-on(实操)的安全运营中心(SOC)家庭实验室,使用在 **VirtualBox** 中的 **Ubuntu Server 22.04** 上部署的 **Wazuh SIEM** 构建,并以 **Windows 10** 终端作为受监控的 agent。该实验室从零开始构建,作为作品集项目,旨在展示在 SIEM 部署、日志接入、检测工程、威胁模拟和事件分析方面的实际技能。 ## 📋 目录 - [实验室概述](#lab-overview) - [架构](#architecture) - [前置条件](#prerequisites) - [环境配置](#environment-setup) - [Wazuh 安装](#wazuh-installation) - [Agent 部署](#agent-deployment) - [自定义检测规则](#custom-detection-rules) - [攻击模拟](#attack-simulations) - [仪表板与可视化](#dashboard--visualizations) - [挑战与故障排除](#challenges--troubleshooting) - [关键要点](#key-takeaways) - [截图](#screenshots) - [展示技能](#skills-demonstrated) ## 实验室概述 | 组件 | 详情 | |---|---| | **SIEM 平台** | Wazuh 4.7.5 (All-in-One) | | **服务器操作系统** | Ubuntu Server 22.04 LTS | | **终端操作系统** | Windows 10 Pro (64 位) | | **Hypervisor** | Oracle VirtualBox 7.x | | **网络** | VirtualBox Host-Only (192.168.56.0/24) | | **主机分配内存** | 6GB (Wazuh Server VM) | | **主机分配 vCPU** | 2 vCPU (Wazuh Server VM) | | **磁盘** | 50GB 动态分配 VDI | ### 本实验室涵盖内容 - 从零开始部署企业级开源 SIEM - 通过 Wazuh agent 从 Windows 终端接入日志 - 编写基于 XML 的自定义检测规则 - 模拟真实攻击场景(暴力破解、权限提升、端口扫描、日志篡改) - 构建 SOC 仪表板和可视化 - 事件响应和根本原因分析 ## 架构 ``` Host PC (Windows) │ ├── VirtualBox Host-Only Network: 192.168.56.0/24 │ ├── VM 1: Wazuh Server (Ubuntu 22.04) │ IP: 192.168.56.101 │ ├── Wazuh Manager ← Detection engine & rule processing │ ├── Wazuh Indexer ← OpenSearch data storage (JVM-based) │ └── Wazuh Dashboard ← Web UI (https://192.168.56.101) │ └── VM 2: Windows 10 Endpoint IP: 192.168.56.102 └── Wazuh Agent ← Forwards logs/events to Wazuh Server ``` **数据流向:** ``` Windows Event Logs → Wazuh Agent → Wazuh Manager → Rule Engine → Wazuh Indexer → Dashboard ``` ## 前置条件 ### 软件下载 | 工具 | 版本 | 用途 | |---|---|---| | [VirtualBox](https://www.virtualbox.org/wiki/Downloads) | 7.x | Hypervisor | | [Ubuntu Server ISO](https://ubuntu.com/download/server) | 22.04 LTS | Wazuh Server OS | | [Windows 10 ISO](https://www.microsoft.com/software-download/windows10) | 最新版 | 受监控终端 | ### 主机最低配置要求 | 资源 | 最低配置 | 推荐配置 | |---|---|---| | 内存 | 8GB | 16GB | | CPU 核心数 | 4 | 8 | | 可用磁盘空间 | 80GB | 120GB | | 操作系统 | Windows 10/11, macOS, Linux | — | ## 环境配置 ### VirtualBox Host-Only 网络 在创建 VM 之前,配置了一个专用的 Host-Only 网络,以允许宿主机和两台 VM 之间进行通信,而不会将它们暴露给外部网络。 **步骤:** 1. VirtualBox → 文件 → 工具 → 网络管理器 2. Host-only 网络 → 创建 3. 网络范围:`192.168.56.0/24` ### VM 规格 **Wazuh Server VM:** - 内存:6144 MB (6GB) - vCPU:2 - 存储:50GB VDI(动态分配) - 网络适配器 1:NAT(安装期间用于互联网访问) - 网络适配器 2:Host-only (192.168.56.x) **Windows 终端 VM:** - 内存:2048 MB (2GB) - vCPU:1 - 存储:40GB VDI(动态分配) - 网络适配器 1:NAT - 网络适配器 2:Host-only (192.168.56.x) ## Wazuh 安装 Wazuh 使用官方的一体化安装脚本进行部署,该脚本会在单节点上安装 Manager、Indexer 和 Dashboard。 ``` # 更新系统 sudo apt update && sudo apt upgrade -y # 下载并运行 Wazuh 安装脚本 curl -sO https://packages.wazuh.com/4.7/wazuh-install.sh sudo bash wazuh-install.sh -a -i ``` ### 安装后服务管理 ``` # 按正确顺序启动服务(indexer 必须首先启动) sudo systemctl start wazuh-indexer sleep 30 sudo systemctl start wazuh-manager sleep 20 sudo systemctl start wazuh-dashboard # 设置开机启动 sudo systemctl enable wazuh-indexer wazuh-manager wazuh-dashboard ``` ### 仪表板访问 安装完成后,可通过以下地址访问仪表板: ``` https://192.168.56.101 Username: admin Password: ``` ## Agent 部署 在 Windows 10 VM 上安装了 Wazuh agent,以将安全事件转发给 Wazuh Manager。 ### Windows Agent 安装 1. 下载:`https://packages.wazuh.com/4.x/windows/wazuh-agent-4.7.0-1.msi` 2. 在安装过程中,将 **Manager IP** 设置为:`192.168.56.101` 3. 启动 agent 服务: ``` NET START WazuhSvc ``` ### 验证 Agent 连接 在 Wazuh 仪表板中 → **Agents** → 确认 Windows 终端显示状态为:**Active** ## 自定义检测规则 自定义规则以 XML 格式编写,并保存到 `/var/ossec/etc/rules/local_rules.xml`。 ``` windows net user Possible new user account created via command line account_creation,attack 60122 Brute force attack: 5+ failed logins in 2 minutes authentication_failures,attack syscheck C:\\Users\\.*\\AppData\\Local\\Temp File created in Temp directory - possible malware dropper suspicious_file,attack ``` 保存后,重启 manager 以应用规则: ``` sudo systemctl restart wazuh-manager ``` ### 在仪表板中按自定义规则过滤告警 ``` # 按 rule ID rule.id: 100001 OR rule.id: 100002 OR rule.id: 100003 # 按 shared group tag rule.groups: attack # 按 severity level rule.level >= 8 ``` ## 攻击模拟 ### 可视化 1 — 身份验证失败随时间变化趋势 **攻击 1:RDP/SMB 暴力破解 (CMD)** ``` for /L %i in (1,1,20) do net use \\localhost\IPC$ /user:Administrator wrongpassword ``` **攻击 2:PowerShell 身份验证失败** ``` 1..15 | ForEach-Object { net use \\localhost\IPC$ /user:Administrator wrongpass } ``` **攻击 3:SSH 暴力破解 (Ubuntu VM)** ``` # 安装 Hydra sudo apt install hydra -y # 创建密码列表 cat > /tmp/passwords.txt << EOF password 123456 admin letmein qwerty wrongpass EOF # 运行 brute force hydra -l wazuhuser -P /tmp/passwords.txt ssh://127.0.0.1 -t 4 -V ``` ### 可视化 2 — 触发最多的规则(饼图) **攻击 1:恶意软件文件释放模拟** ``` $locations = @( "C:\Users\labuser\AppData\Local\Temp\payload.exe", "C:\Users\labuser\AppData\Local\Temp\update.bat", "C:\Users\labuser\AppData\Local\Temp\svchost32.exe" ) foreach ($path in $locations) { New-Item -Path $path -ItemType File -Force Add-Content -Path $path -Value "Simulated malware file" Start-Sleep -Seconds 2 } ``` **攻击 2:注册表持久化模拟** ``` $regPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run" Set-ItemProperty -Path $regPath -Name "WindowsUpdate32" -Value "C:\Temp\malware.exe" Set-ItemProperty -Path $regPath -Name "SvcHost64" -Value "C:\Windows\Temp\backdoor.exe" Start-Sleep -Seconds 5 # 清理 Remove-ItemProperty -Path $regPath -Name "WindowsUpdate32" Remove-ItemProperty -Path $regPath -Name "SvcHost64" ``` **攻击 3:日志篡改(攻击者掩盖痕迹)** ``` # Wazuh 检测日志清除尝试 wevtutil cl System wevtutil cl Application wevtutil cl Security ``` **攻击 4:端口扫描 (Ubuntu → Windows)** ``` sudo nmap -sS 192.168.56.102 -p 1-1000 sudo nmap -sV 192.168.56.102 sudo nmap -A 192.168.56.102 ``` ### 可视化 3 — 告警最多的 Agent(柱状图) **攻击 1:批量用户创建与删除** ``` :: Create 10 fake backdoor accounts for /L %i in (1,1,10) do net user hacker%i Password123! /add for /L %i in (1,1,5) do net localgroup administrators hacker%i /add timeout /t 30 for /L %i in (1,1,10) do net user hacker%i /delete ``` **攻击 2:计划任务持久化** ``` 1..5 | ForEach-Object { schtasks /create /tn "WindowsUpdate$_" /tr "C:\Temp\malware$_.exe" /sc minute /mo 5 /f Start-Sleep -Seconds 3 } # 清理 1..5 | ForEach-Object { schtasks /delete /tn "WindowsUpdate$_" /f } ``` **攻击 3:文件完整性监控 — 大规模文件修改(勒索软件模拟)** ``` New-Item -Path "C:\TestFiles" -ItemType Directory -Force 1..20 | ForEach-Object { Set-Content "C:\TestFiles\document$_.txt" -Value "Original $_" } Start-Sleep -Seconds 10 # 模拟加密 1..20 | ForEach-Object { Set-Content "C:\TestFiles\document$_.txt" -Value "ENCRYPTED_$([System.Guid]::NewGuid())" Start-Sleep -Milliseconds 500 } ``` ## 仪表板与可视化 在 Wazuh 仪表板中,于一个名为 **"SOC Home Lab Overview"** 的自定义工作簿下构建了三个可视化: | 面板 | 索引 | 字段/过滤器 | 图表类型 | |---|---|---|---| | 身份验证失败随时间变化趋势 | `wazuh-alerts-*` | `rule.groups: authentication_failures` | 时间轴图表 | | 触发最多的规则 | `wazuh-alerts-*` | `rule.description` | 饼图 | | 告警最多的 Agent | `wazuh-alerts-*` | `agent.name` | 柱状图 | ## 挑战与故障排除 本部分记录了构建过程中遇到的每一个重大挑战,以及根本原因和解决方案。这些都是来自真实构建的实际问题——而不是一次顺利运行的演练。 ### 挑战 1:Wazuh 安装期间操作系统兼容性检查失败 **错误:** ``` ERROR: The recommended systems are: Red Hat Enterprise Linux 7, 8, 9; CentOS 7, 8; Amazon Linux 2; Ubuntu 16... The current system does not match this list. ``` **根本原因:** Wazuh 4.7.5 的安装脚本执行了操作系统版本检查,但该检查的已验证列表中未包含 Ubuntu 22.04,尽管实际上它可以在此系统上正常安装。 **解决方案:** 添加 `-i` 标志以绕过检查: ``` sudo bash wazuh-install.sh -a -i ``` ### 挑战 2:忘记 VM 终端密码 **情况:** 在实验过程中忘记了 Ubuntu VM 的登录密码。 **解决方案:** 通过 GRUB 引导进入 Ubuntu 恢复模式,进入 root shell,并重置密码: ``` mount -o remount,rw / passwd wazuhuser reboot ``` ### 挑战 3:未安装 VirtualBox Guest Additions(拖拽/剪贴板) **错误:** `DnD: Error: Drag and drop to guest not possible — VBOX_E_DND_ERROR` **根本原因:** 两台 VM 均未安装 VirtualBox Guest Additions,导致无法在宿主机和客户机之间使用共享剪贴板和拖放功能。 **解决方案 (Ubuntu VM):** ``` sudo apt install build-essential dkms linux-headers-$(uname -r) -y sudo mount /dev/sr0 /mnt/cdrom sudo bash /mnt/cdrom/VBoxLinuxAdditions.run sudo reboot ``` **解决方案 (Windows VM):** 通过 VirtualBox 菜单插入 Guest Additions CD → 在 Windows VM 内运行 `VBoxWindowsAdditions-amd64.exe` → 重启。 **注意:** 挂载警告 `WARNING: source write-protected, mounted read-only` 是 CD-ROM 设备的正常行为,并非错误。 ### 挑战 4:Wazuh Dashboard SSL 证书缺失 **错误:** ``` errno: -2, syscall: 'open', code: 'ENOENT', path: '/etc/wazuh-dashboard/certs/dashboard-key.pem' ``` **根本原因:** 仪表板的 SSL 证书文件存在,但名称(`wazuh-dashboard-key.pem`)与配置中期望的名称(`dashboard-key.pem`)不同。这是由于安装脚本运行了两次(第一次尝试由于上述挑战 1 而失败)导致证书引用不匹配。 **解决方案:** 将现有证书复制为期望的文件名并修复权限: ``` sudo cp /etc/wazuh-dashboard/certs/wazuh-dashboard-key.pem /etc/wazuh-dashboard/certs/dashboard-key.pem sudo cp /etc/wazuh-dashboard/certs/wazuh-dashboard.pem /etc/wazuh-dashboard/certs/dashboard.pem sudo chown wazuh-dashboard:wazuh-dashboard /etc/wazuh-dashboard/certs/dashboard-key.pem /etc/wazuh-dashboard/certs/dashboard.pem sudo chmod 400 /etc/wazuh-dashboard/certs/dashboard-key.pem /etc/wazuh-dashboard/certs/dashboard.pem ``` ### 挑战 5:Wazuh Indexer 启动超时 **错误:** ``` wazuh-indexer.service: start operation timed out. Terminating. wazuh-indexer.service: Failed with result 'timeout'. Mem peak: 895.7M (swap: 741.3M) ``` **根本原因:** Wazuh Indexer (OpenSearch/JVM) 在资源受限的 VM 上初始化速度较慢。systemd 的默认启动超时时间过短,导致其在进程完成启动之前就将其杀死。大量的 swap 使用表明存在内存压力。 **解决方案 1 — 增加 systemd 启动超时时间:** ``` sudo systemctl edit wazuh-indexer # 添加: [Service] TimeoutStartSec=300 sudo systemctl daemon-reload ``` **解决方案 2 — 减小 JVM 堆内存:** ``` sudo nano /etc/wazuh-indexer/jvm.options # 将 -Xms1g / -Xmx1g 更改为: -Xms512m -Xmx512m ``` **解决方案 3 — 通过 VirtualBox 设置将 VM 内存** 从 4GB 增加到 6GB。 ### 挑战 6:自定义规则文件 XML 错误 **情况:** 添加自定义检测规则后,`sudo systemctl restart wazuh-manager` 失败。 **根本原因:** `local_rules.xml` 中存在多个 XML 语法错误: - 重复的规则 ID(`100001` 被使用了两次) - 属性中缺少 `=`:`timeframe"120"` 写成了 `timeframe="120"` - XML 标签内包含空格:``、``、`account_creat ion` - 格式错误的 XML 注释:`