| name | hunting-for-anomalous-powershell-execution |
| description | 通过分析脚本块日志(事件 4104)、模块日志(事件 4103)和进程创建事件,狩猎恶意 PowerShell 活动。 分析员解析 Windows 事件日志 EVTX 文件,检测混淆命令、AMSI 绕过尝试、编码 payload、 凭据转储关键词和可疑下载器(download cradles)。适用于涉及 PowerShell 威胁狩猎、脚本块分析、 编码命令检测或 AMSI 绕过识别的场景。
|
| domain | cybersecurity |
| subdomain | threat-hunting |
| tags | ["powershell","script-block-logging","event-4104","amsi","threat-hunting","evtx","obfuscation"] |
| version | 1.0 |
| author | mahipal |
| license | Apache-2.0 |
狩猎异常 PowerShell 执行
概述
PowerShell 脚本块日志记录(事件 ID 4104)会记录在 Windows 终端上执行的完整去混淆脚本文本,使其成为狩猎恶意 PowerShell 的主要数据源。结合模块日志(4103)和进程创建事件,分析员即使在攻击者使用混淆层的情况下,也能检测编码命令、AMSI 绕过模式、下载器(download cradles)、凭据窃取工具和无文件攻击技术。
前置条件
- 来自 Microsoft-Windows-PowerShell/Operational 的 Windows 事件日志导出(.evtx)
- Python 3.8+ 及 python-evtx 和 lxml 库
- 通过组策略启用的脚本块日志记录
- 了解常见的 PowerShell 攻击技术
步骤
- 解析 EVTX 文件,提取事件 4104 的脚本块文本和元数据
- 使用 ScriptBlock ID 关联重组多部分脚本块
- 扫描脚本文本中的 AMSI 绕过指标和混淆模式
- 检测编码命令执行和 Base64 payload
- 识别下载器(download cradles)、凭据转储和横向移动命令
- 按威胁严重程度对发现结果评分并排序
预期输出
{
"total_events": 1247,
"suspicious_events": 23,
"amsi_bypass_attempts": 2,
"encoded_commands": 8,
"download_cradles": 5,
"credential_access": 3
}