0xAnalyst/WebshellDetectionWMIYara

GitHub: 0xAnalyst/WebshellDetectionWMIYara

通过 YARA、WMI 事件订阅、Sigma 规则和进程/内存/网络多层检测,在 Windows IIS 环境中识别和关联 ASPX WebShell 行为的威胁狩猎工具包。

Stars: 8 | Forks: 3

# 0xAnalyst/WebshellDetection-WMI-Yara 使用 WMI 永久事件订阅、YARA 规则、Sigma 规则和 PowerShell 行为监控进行 ASPX webshell 检测。涵盖静态文件扫描、进程链分析、内存扫描、网络遥测和 SIEM 关联。 ![Threat Hunting](https://img.shields.io/badge/purpose-threat%20hunting-blue) ![Platform](https://img.shields.io/badge/platform-IIS%20%2F%20Windows-lightgrey) ![YARA](https://img.shields.io/badge/rules-YARA-green) ![Sigma](https://img.shields.io/badge/rules-Sigma-blue) ## 仓库结构 ``` WebshellDetection-WMI-Yara/ ├── README.md ├── index.html # GitHub Pages card view │ ├── existing/ # Original detection files │ ├── WMIWebShellmonitor.ps1 │ └── rules.yar │ ├── yara/ # Static YARA rules │ ├── aspx_dinvoke.yar │ ├── aspx_assembly_load.yar │ ├── aspx_etw_amsi_patch.yar │ ├── aspx_syscall_stub.yar │ └── aspx_roslyn_eval.yar │ ├── wmi/ # WMI behavioral monitors │ ├── WMIWebShellmonitor.ps1 # Enhanced original │ ├── WMIProcessChainMonitor.ps1 │ └── WMINetworkMonitor.ps1 │ ├── process-chain/ # Process lineage rules │ ├── w3wp_child_process.yar │ ├── lolbin_from_iis.yar │ └── impersonation_from_iis.yar │ ├── memory/ # In-memory scanning rules │ ├── reflective_pe_memory.yar │ └── ntdll_unhook_memory.yar │ ├── network/ # Network-based detection │ ├── doh_c2_detection.yar │ └── websocket_persistence.yar │ └── sigma/ # Sigma rules for SIEM ├── webshell_process_chain.yml ├── iis_outbound_connection.yml └── etw_amsi_tamper.yml ``` ## 检测层 | 检测层 | 方法 | 文件 | 识别内容 | |-------|--------|-------|-----------------| | 静态 | YARA 文件扫描 | `yara/` | 动态 P/Invoke、Assembly.Load、ETW/AMSI 补丁、syscall stub、Roslyn eval | | 行为 | WMI 事件订阅 | `wmi/` | 文件生成、异常子进程、意外出站连接 | | 进程链 | YARA + Sysmon | `process-chain/` | w3wp.exe 衍生 shell、LOLBin 滥用、token 模拟 | | 内存 | YARA -p (进程扫描) | `memory/` | 反射式 PE 加载、ntdll unhooking、非映像内存中的 MZ | | 网络 | YARA + NetFlow | `network/` | DoH C2 流量、来自 IIS 的长连接 WebSocket | | SIEM | Sigma 规则 | `sigma/` | 跨事件关联:Splunk/Elastic/Sentinel 中的进程链 + 网络 + 篡改 | ## YARA 规则 ### 静态文件规则 — `yara/` | 规则文件 | 检测内容 | ATT&CK | |-----------|---------|--------| | `aspx_dinvoke.yar` | 通过 GetProcAddress 进行动态 P/Invoke,无 DllImport | T1106 · T1027 | | `aspx_assembly_load.yar` | Assembly.Load() + XOR 解码循环 | T1027 · T1620 | | `aspx_etw_amsi_patch.yar` | EtwEventWrite / AmsiScanBuffer 字节补丁序列 | T1562.001 · T1562.006 | | `aspx_syscall_stub.yar` | 直接 syscall stub,Heaven's Gate 模式 | T1055 · T1562.006 | | `aspx_roslyn_eval.yar` | CSharpScript.EvaluateAsync,Microsoft.CodeAnalysis 导入 | T1027.010 | ### 进程链规则 — `process-chain/` | 规则文件 | 检测内容 | ATT&CK | |-----------|---------|--------| | `w3wp_child_process.yar` | 作为 w3wp.exe 子进程的 cmd.exe / powershell.exe / wscript.exe | T1059.001 · T1059.003 | | `lolbin_from_iis.yar` | 源自 IIS 的 MSBuild、regsvr32、mshta、certutil、bitsadmin | T1127.001 · T1218 | | `impersonation_from_iis.yar` | 来自 IIS 上下文的 token 模拟、CreateProcessAsUser | T1134.001 · T1548.002 | ### 内存规则 — `memory/` | 规则文件 | 检测内容 | ATT&CK | |-----------|---------|--------| | `reflective_pe_memory.yar` | w3wp.exe 非映像内存区域中的 MZ/PE 头 | T1620 · T1055 | | `ntdll_unhook_memory.yar` | 同一进程中的两个 ntdll 基址(新映射的副本) | T1562.001 · T1055 | ### 网络规则 — `network/` | 规则文件 | 检测内容 | ATT&CK | |-----------|---------|--------| | `doh_c2_detection.yar` | 端口 443 上 DoH 查询中的高熵 DNS 名称 | T1071.004 | | `websocket_persistence.yar` | 从 w3wp.exe 到外部主机的长连接 WebSocket 升级 | T1071.001 | ## WMI 监控器 — `wmi/` | 脚本 | 触发条件 | 告警 | |--------|---------|-------| | `WMIWebShellmonitor.ps1` | Web 根目录中出现新的 ASP/ASPX 文件 | YARA 匹配 → 记录日志 + 可选 webhook | | `WMIProcessChainMonitor.ps1` | w3wp.exe 创建子进程 | 异常子进程 → 记录日志 + 告警 | | `WMINetworkMonitor.ps1` | 来自 IIS PID 的出站网络连接 | 外部连接 → 记录日志 + 告警 | ### 设置 ``` # 设置您的路径 $YaraPath = "C:\tools\yara\yara64.exe" $RulesPath = "C:\WebshellDetection\yara\" $WebRoot = "C:\inetpub\wwwroot" $LogFile = "C:\logs\webshell_detections.txt" $WebhookUrl = "https://hooks.slack.com/services/YOUR/WEBHOOK" # optional # 运行 monitor(以 Administrator 身份运行) .\wmi\WMIWebShellmonitor.ps1 ``` ## Sigma 规则 — `sigma/` | 规则文件 | 日志源 | 关联内容 | SIEM 目标 | |-----------|-----------|------------|--------------| | `webshell_process_chain.yml` | Sysmon EID 1 | w3wp.exe → 衍生 shell/LOLBin | Splunk, Elastic, Sentinel | | `iis_outbound_connection.yml` | Sysmon EID 3 | w3wp.exe → 外部出站 | Splunk, Elastic, Sentinel | | `etw_amsi_tamper.yml` | Security EID 4656/4657 | AMSI 注册表访问 + ETW 会话修改 | Splunk, Elastic, Sentinel | ### 将 Sigma 转换为您的 SIEM ``` # Splunk sigma convert -t splunk sigma/webshell_process_chain.yml # Elastic sigma convert -t eql sigma/iis_outbound_connection.yml # Microsoft Sentinel sigma convert -t kusto sigma/etw_amsi_tamper.yml ``` ## 对比 Webshell 仓库的覆盖图 | Webshell 技术 | 检测方法 | 规则 | |-------------------|-----------------|------| | `CreateProcess_Dynamic.aspx` | 静态 YARA | `aspx_dinvoke.yar` | | `WinExec_Syscall.aspx` | 静态 YARA | `aspx_syscall_stub.yar` | | `ShellExecuteEx_Runas.aspx` | 进程链 | `impersonation_from_iis.yar` | | `NtCreateProcess_Unhook.aspx` | 内存扫描 | `ntdll_unhook_memory.yar` | | `CreateProcessAsUser_Impersonate.aspx` | 进程链 | `impersonation_from_iis.yar` | | `WMI_Com_ETW_AMSI_Patch.aspx` | 静态 YARA | `aspx_etw_amsi_patch.yar` | | `InMemory_Assembly_XOR.aspx` | 静态 YARA | `aspx_assembly_load.yar` | | `COMShell.aspx` | 行为 WMI | `WMIProcessChainMonitor.ps1` | | `DoHShell.aspx` | 网络 YARA | `doh_c2_detection.yar` | | `WebSocketShell.aspx` | 网络 YARA | `websocket_persistence.yar` | | `ETWPatchShell.aspx` | 静态 YARA | `aspx_etw_amsi_patch.yar` | | `ReflectivePEShell.aspx` | 内存扫描 | `reflective_pe_memory.yar` | ## 参考 - [MITRE ATT&CK — Web Shell T1505.003](https://attack.mitre.org/techniques/T1505/003/) - [Sigma 规则 — SigmaHQ](https://github.com/SigmaHQ/sigma) - [YARA 文档](https://yara.readthedocs.io/) - [NSA/CISA Web Shell 警报](https://media.defense.gov/2020/Jun/09/2002313081/-1/-1/0/CSI-DETECT-AND-PREVENT-WEB-SHELL-MALWARE-20200422.PDF) - [Sysmon 配置 — SwiftOnSecurity](https://github.com/SwiftOnSecurity/sysmon-config)
标签:AI合规, OpenCanary, Sigma规则, Webshell检测, WMI事件订阅, YARA, 云资产可视化, 安全, 目标导入, 超时处理