关于 analyzing-powershell-script-block-logging
面向 SOC 分析师的安全分析技能,用于调查 PowerShell 脚本块日志并制定检测或威胁狩猎流程。它指导解析 Event ID 4104、重组分段脚本并评估可疑模式。
主要功能
- 01解析 Event ID 4104 日志
- 02重组多段脚本
- 03检测编码与下载模式
- 04识别 AMSI 绕过和混淆
- 05生成风险与 ATT&CK 报告
适用场景
- 01调查 PowerShell 相关安全事件
- 02制定检测规则和狩猎查询
- 03检查攻击技术的监控覆盖情况
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ mukul975/ anthropic-cybersecurity-skills --skill analyzing-powershell-script-block-logging安装后在 Claude Code 中输入/analyzing-powershell-script-block-logging确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
LICENSEreferences/api-reference.mdscripts/agent.py详细介绍
分析 PowerShell 脚本块日志记录
何时使用
- 调查需要分析 PowerShell 脚本块日志记录的安全事件时
- 为该领域构建检测规则或威胁狩猎查询时
- SOC 分析师需要针对此类分析的结构化流程时
- 验证相关攻击技术的安全监控覆盖范围时
前置条件
- 熟悉安全运营概念与工具
- 可访问测试或实验环境以安全执行
- 已安装所需依赖的 Python 3.8+
- 任何测试活动均获得适当授权
操作说明
- 安装依赖:
pip install python-evtx lxml - 收集 PowerShell 操作日志:
Microsoft-Windows-PowerShell%4Operational.evtx - 使用 python-evtx 解析事件 ID 4104 条目,提取 ScriptBlockText、ScriptBlockId 以及 MessageNumber/MessageTotal,以重建多段脚本。
- 应用检测启发式规则:
- Base64 编码命令(
-EncodedCommand、FromBase64String) - 下载载体(
DownloadString、DownloadFile、Invoke-WebRequest、Net.WebClient) - AMSI 绕过模式(
AmsiUtils、amsiInitFailed) - 混淆指标(高熵、插入反引号、字符串拼接)
- Base64 编码命令(
- 生成包含重建脚本、风险评分和 MITRE ATT&CK 映射的报告。
python scripts/agent.py --evtx-file /path/to/PowerShell-Operational.evtx --output ps_analysis.json
示例
检测编码命令执行
import base64
if "-encodedcommand" in script_text.lower():
encoded = script_text.split()[-1]
decoded = base64.b64decode(encoded).decode("utf-16-le")
重建多块脚本
分散在多个 4104 事件中的脚本共享同一个 ScriptBlockId。按 MessageNumber 排序并拼接各块,即可恢复完整脚本。
评论
支持 Markdown