K-naulita/Wazuh-Rules-Task2

GitHub: K-naulita/Wazuh-Rules-Task2

这是一个基于 Wazuh SIEM 的完整实验文档,涵盖了环境部署、Agent 连接验证以及针对多种攻击场景的自定义安全检测规则编写。

Stars: 0 | Forks: 0

# Wazuh SIEM – 模块 2 | NRP | Nama | |:-----------:|:-----------------:| | 5025241021 | Kartika Nana Naulita | ## 作业 1. 在基于 Linux 的虚拟机(推荐 Ubuntu/Debian)上安装 Wazuh Manager。 2. 在另一台设备上安装 Wazuh Agent,可以使用 Windows 或 Linux 操作系统。 3. 确保 agent 成功连接到 manager,方法是从 agent 检查默认事件/日志是否已进入并在 Wazuh 仪表板中可见。 4. 创建/查找并实施至少 5 条自定义规则/自定义警报。 5. 创建文档,说明你是如何完成模块 2 任务的,包括 manager 和 agent 的安装步骤、部署流程/可视化图表、agent-manager 连接验证、添加的每条自定义规则的说明,以及显示这些规则在 Github 仓库中处于活动状态的仪表板/警报截图。 ## 回答 ### 环境规格 | 组件 | 详情 | |----------|--------| | **Manager** | VM Azure – IP: `20.195.8.104` | | **Agent** | WSL – Ubuntu | | **Dashboard** | https://20.195.8.104 | ## 1. 安装 Wazuh Manager 使用 Wazuh 官方 all-in-one 脚本进行安装(Manager + Indexer + Dashboard): ``` curl -sO https://packages.wazuh.com/4.7/wazuh-install.sh curl -sO https://packages.wazuh.com/4.7/config.yml sudo bash wazuh-install.sh -a ``` 验证: ``` sudo systemctl status wazuh-manager sudo systemctl status wazuh-indexer sudo systemctl status wazuh-dashboard ``` 仪表板可通过以下地址访问:`https://20.195.8.104` ![img](https://i.imgur.com/bpAnMeZ.png) ![img](https://i.imgur.com/CpKvkgb.png) ![img](https://i.imgur.com/MqyoXGg.png) ![img](https://i.imgur.com/2nvAIyA.png) ## 2. 安装 Wazuh Agent Agent 安装在 WSL (Windows Subsystem for Linux) 上: ``` wget https://packages.wazuh.com/4.x/apt/pool/main/w/wazuh-agent/wazuh-agent_4.7.5-1_amd64.deb && sudo WAZUH_MANAGER='20.195.8.104' WAZUH_AGENT_NAME='naulita' dpkg -i ./wazuh-agent_4.7.5-1_amd64.deb sudo systemctl daemon-reload sudo systemctl enable wazuh-agent sudo systemctl start wazuh-agent ``` ## ![img](https://i.imgur.com/jKGwprN.png) ![img](https://i.imgur.com/8T4C430.png) ![img](https://i.imgur.com/bLJy7tr.png) ![img](https://i.imgur.com/EKbhQft.png) ## 3. 验证 Agent-Manager 连接 从 Manager 端检查: ``` sudo /var/ossec/bin/agent_control -l ``` ![img](https://i.imgur.com/tbk0U4B.png) ## 4. 自定义规则 所有规则均添加在 Manager 的以下文件中: ``` sudo nano /var/ossec/etc/rules/local_rules.xml ``` 添加或更改规则后,务必重启 manager: ``` sudo systemctl restart wazuh-manager ``` ### 规则 1 – SSH 暴力破解检测 (ID: 100001) **描述:** 检测来自同一 IP 的重复 SSH 登录失败尝试(60 秒内 ≥5 次)。 ``` 5710 SSH brute force: multiple failed logins from $(srcip) T1110 authentication_failures,pci_dss_10.2.4, ``` **测试步骤:** 1. 将规则添加到 `local_rules.xml`,重启 manager 2. 从另一台机器运行失败的 SSH 循环: ``` for i in $(seq 1 10); do ssh -o BatchMode=yes -o ConnectTimeout=5 fakeuser@20.195.8.104; done ``` 3. 检查仪表板:`rule.id:100001` ## ![img](https://i.imgur.com/wUM5eZI.png) ![img](https://i.imgur.com/ue3SaeL.png) ![img](https://i.imgur.com/a7oZlg5.png) ### 规则 2 – Sudo 提权检测 (ID: 100002) **描述:** 检测非 sudoers 组用户尝试使用 sudo 运行命令。 ``` 5400 NOT in sudoers Sudo: unauthorized user tried to run a command as root T1548.003 privilege_escalation,pci_dss_10.2.5, ``` **测试步骤:** 1. 将规则添加到 `local_rules.xml`,重启 manager 2. 在 agent 上创建普通用户: ``` sudo adduser testuser ``` 3. 以 testuser 身份登录: ``` su - testuser ``` 4. 尝试运行 sudo: ``` sudo whoami ``` 出现提示:`testuser is not in the sudoers file. This incident will be reported.` 5. 检查仪表板:`rule.id:100002` 6. 删除测试用户: ``` sudo userdel -r testuser ``` ## ![img](https://i.imgur.com/aqBrNlU.png) ![img](https://i.imgur.com/2F2QGhp.png) ![img](https://i.imgur.com/6It7NCQ.png) ![img](https://i.imgur.com/BPovhwA.png) ### 规则 3 – FIM 关键文件修改检测 (ID: 100003) **描述:** 使用 Wazuh 的 Syscheck (FIM) 模块检测对 `/etc/passwd`、`/etc/shadow` 或 `/etc/sudoers` 的修改。 ``` 550 /etc/passwd|/etc/shadow|/etc/sudoers FIM: Critical auth file modified: $(file) T1098T1003 pci_dss_11.5,gdpr_II_5.1.f, ``` **测试步骤:** 1. 确保 agent 的 `ossec.conf` 中启用了 FIM 实时监控: ``` /etc ``` 2. 重启 agent: ``` sudo systemctl restart wazuh-agent ``` 3. 添加规则,重启 manager 4. 在 agent 上触发: ``` sudo bash -c 'echo "#test" >> /etc/passwd' ``` 5. 检查仪表板:`rule.id:100003` 6. 清理: ``` sudo sed -i '/#test/d' /etc/passwd ``` ## ![img](https://i.imgur.com/iHedMUH.png) ### 规则 4 – SQL 注入检测 (ID: 100004) **描述:** 检测 Apache 访问日志 URL 中的 SQL 注入模式。 ``` 31103 select|union|insert|drop|update|1=1|-- Web attack: possible SQL injection in request URL T1190 attack,sql_injection,pci_dss_6.5.1, ``` **测试步骤:** 1. 在 agent 上安装 Apache: ``` sudo apt install apache2 -y sudo systemctl enable --now apache2 ``` 2. 将 Apache 日志添加到 agent 的 `ossec.conf`: ``` apache /var/log/apache2/access.log ``` 3. 修复权限: ``` sudo usermod -aG adm wazuh sudo systemctl restart wazuh-agent ``` 4. 添加规则,重启 manager 5. 从 agent 触发: ``` curl 'http://localhost/page?id=1%20UNION%20SELECT%201,2,3--' ``` 6. 检查仪表板:`rule.id:100004` ![img](https://i.imgur.com/d0R7YGj.png) ![img](https://i.imgur.com/wg5mtUr.png) ![img](https://i.imgur.com/uO4GoGs.png) ### 规则 5 – 反向 Shell 检测 (ID: 100005) **描述:** 使用 Linux Audit (auditd) 检测反向 shell 命令的执行,例如 `bash -i`。 ``` 80700,80710,80711,80792 bash|sh|nc|python|perl -i|-e|-c Audit: possible reverse shell execution detected T1059.004T1105 attack,shell_injection, ``` **测试步骤:** 1. 在 agent 上安装 auditd: ``` sudo apt install auditd -y sudo systemctl enable --now auditd ``` 2. 将 audit 日志添加到 agent 的 `ossec.conf`: ``` audit /var/log/audit/audit.log ``` 3. 修复权限: ``` sudo usermod -aG adm wazuh sudo systemctl restart wazuh-agent ``` 4. 添加 audit 规则: ``` sudo nano /etc/audit/rules.d/audit.rules ``` 添加: ``` -a always,exit -F arch=b64 -S execve -k shell_commands -a always,exit -F arch=b32 -S execve -k shell_commands ``` 加载规则: ``` sudo augenrules --load ``` 5. 在 manager 上添加规则,重启 manager 6. 测试反向 shell(2 个终端): 终端 1: ``` nc -lvp 4444 ``` 终端 2: ``` bash -i >& /dev/tcp/127.0.0.1/4444 0>&1 ``` 7. 检查仪表板:`rule.id:100005` ![img](https://i.imgur.com/1Uxg4q4.png) ![img](https://i.imgur.com/suzYwdU.png) ![img](https://i.imgur.com/trDByU1.png) ![img](https://i.imgur.com/tYR0V6W.png) ### 规则 6 – 检测到新建用户账户 (ID: 100007) **描述:** 检测通过 `useradd/adduser` 在 Linux 上创建新用户账户,作为后门账户的指示。 ``` 5902 New user account created: $(dstuser) T1136.001 account_management,pci_dss_10.2.5,gpg13_4.13, ``` **测试步骤:** 1. 添加规则,重启 manager 2. 确保 `auth.log` 被监控: ``` sudo grep -A2 "auth.log" /var/ossec/etc/ossec.conf ``` 3. 在 agent 上触发: ``` sudo useradd -m backdooruser ``` 4. 检查仪表板:`rule.id:100007` 5. 删除测试用户: ``` sudo userdel -r backdooruser ``` ## ![img](https://i.imgur.com/pIjfPsy.png) ![img](https://i.imgur.com/qnv0AsV.png) ### 规则 7 – Rootkit/Trojan 检测 (ID: 100008) **描述:** 使用 Wazuh 的 Rootcheck 模块检测隐藏进程、隐藏端口或 Trojan 签名。 ``` 510,511,512,513 Process hiding|Rootkit|Trojan Rootcheck: possible rootkit/trojan on agent $(agent.name) T1014 rootkit,gdpr_IV_35.7.d,pci_dss_11.4, ``` **测试步骤:** 1. 添加规则,重启 manager 2. 确保 agent 的 `ossec.conf` 中启用了 rootcheck: ``` no yes yes yes yes ``` 3. 重启 agent: ``` sudo systemctl restart wazuh-agent ``` 4. 从 manager 强制扫描: ``` sudo /var/ossec/bin/agent_control -r -a ``` 5. 检查仪表板:`rule.id:100008` ![img](https://i.imgur.com/cHbaGm8.png) ![img](https://i.imgur.com/Liv41Zp.png) ## 5. 模块 2 任务完成说明文档 *部署图* ``` ┌───────────────────────────────────────┐ │ WAZUH SERVER (Manager) | │ VPS Azure | │ IP: 20.195.8.104 │ │ ┌──────────┐ ┌────────┐ ┌─────────┐ │ │ │ Indexer │ │Manager │ │Dashboard│ │ │ │ :9200 │ │ :1514 │ │ :443 │ │ │ └──────────┘ └────────┘ └─────────┘ │ └──────────────────┬────────────────────┘ │ TCP 1514 ┌────────┴────────┐ │ WAZUH AGENT │ │ WSL (Local) │ │ 192.168.83.135 │ └─────────────────┘ ^ │ ┌────────┴────────┐ │ ATTACKER/Client │ └─────────────────┘ - Agent mengirim log ke manager - Manager menganalisis menggunakan rules - Dashboard menampilkan alert ``` ## 参考资料 - https://documentation.wazuh.com/current/installation-guide/wazuh-agent/wazuh-agent-package-linux.html - https://github.com/wazuh/wazuh.git - https://chatgpt.com/share/69d4ce4c-d79c-8323-a0dd-5360b8c3db44
标签:Azure, BurpSuite集成, Cybersecurity, Redis利用, Wazuh, Wazuh Agent, Wazuh Manager, Windows Subsystem for Linux, x64dbg, 代理支持, 告警, 安全信息与事件管理, 安全运营, 应用安全, 扫描框架, 搜索引擎爬取, 生成式AI安全, 自定义规则, 虚拟机, 部署