关于 extracting-windows-event-logs-artifacts
用于在事件响应、威胁狩猎和取证中分析 Windows EVTX 日志的安全技能,结合 Sigma 检测、时间线生成和事件解析来调查可疑活动。
主要功能
- 01收集 EVTX 文件
- 02使用 Chainsaw 进行 Sigma 检测
- 03使用 Hayabusa 生成时间线
- 04用 Python 解析事件
- 05调查攻击模式
适用场景
- 01狩猎横向移动行为
- 02调查权限提升
- 03分析 PowerShell 活动
- 04重建勒索软件事件经过
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ mukul975/ anthropic-cybersecurity-skills --skill extracting-windows-event-logs-artifacts安装后在 Claude Code 中输入/extracting-windows-event-logs-artifacts确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
LICENSEreferences/api-reference.mdscripts/agent.py详细介绍
提取 Windows 事件日志工件
适用场景
- 通过分析事件日志调查 Windows 系统上的安全事件
- 检测横向移动、权限提升和持久化机制
- 对 Windows 事件日志数据进行威胁狩猎
- 在需要审查身份验证和访问事件的合规性审计期间
- 根据 Windows 系统活动构建取证时间线
前提条件
- 来自取证映像或在线系统的 Windows 事件日志文件(EVTX 格式)
- 用于解析和检测的 Chainsaw、Hayabusa 或 EvtxECmd
- 用于自动化威胁检测的 Sigma 规则
- 了解重要的 Windows 事件 ID
- 用于自定义解析的 Python,以及 python-evtx 或 evtx 库
- 用于在线系统分析的 PowerShell(如适用)
工作流
步骤 1:收集 Windows 事件日志文件
# Extract EVTX files from forensic image
mount -o ro,loop,offset=$((2048*512)) /cases/case-2024-001/images/evidence.dd /mnt/evidence
mkdir -p /cases/case-2024-001/evtx/
cp /mnt/evidence/Windows/System32/winevt/Logs/*.evtx /cases/case-2024-001/evtx/
# Key event logs to prioritize
# Security.evtx - Authentication, authorization, audit events
# System.evtx - System services, drivers, hardware events
# Application.evtx - Application errors and events
# Microsoft-Windows-Sysmon%4Operational.evtx - Detailed process/network monitoring
# Microsoft-Windows-PowerShell%4Operational.evtx - PowerShell activity
# Microsoft-Windows-TerminalServices-LocalSessionManager%4Operational.evtx - RDP sessions
# Microsoft-Windows-TaskScheduler%4Operational.evtx - Scheduled tasks
# Microsoft-Windows-WinRM%4Operational.evtx - Windows Remote Management
# Microsoft-Windows-Bits-Client%4Operational.evtx - BITS transfers
# Microsoft-Windows-Windows Defender%4Operational.evtx - AV detections
# List available log files and sizes
ls -lhS /cases/case-2024-001/evtx/ | head -20
# Hash for integrity
sha256sum /cases/case-2024-001/evtx/*.evtx > /cases/case-2024-001/evtx/evtx_hashes.txt
步骤 2:运行 Chainsaw 进行基于 Sigma 的检测
# Install Chainsaw
wget https://github.com/WithSecureLabs/chainsaw/releases/latest/download/chainsaw_all_platforms+rules.zip
unzip chainsaw_all_platforms+rules.zip -d /opt/chainsaw
# Run Chainsaw with bundled Sigma rules
/opt/chainsaw/chainsaw hunt /cases/case-2024-001/evtx/ \
-s /opt/chainsaw/sigma/rules/ \
--mapping /opt/chainsaw/mappings/sigma-event-logs-all.yml \
--output /cases/case-2024-001/analysis/chainsaw_results.txt
# Run with CSV output for easier analysis
/opt/chainsaw/chainsaw hunt /cases/case-2024-001/evtx/ \
-s /opt/chainsaw/sigma/rules/ \
--mapping /opt/chainsaw/mappings/sigma-event-logs-all.yml \
--csv \
--output /cases/case-2024-001/analysis/chainsaw_results/
# Run with JSON output
/opt/chainsaw/chainsaw hunt /cases/case-2024-001/evtx/ \
-s /opt/chainsaw/sigma/rules/ \
--mapping /opt/chainsaw/mappings/sigma-event-logs-all.yml \
--json \
--output /cases/case-2024-001/analysis/chainsaw_results.json
# Search for specific keywords
/opt/chainsaw/chainsaw search /cases/case-2024-001/evtx/ \
-s "mimikatz" --json
# Search for specific event IDs
/opt/chainsaw/chainsaw search /cases/case-2024-001/evtx/ \
-e 4688 --json | head -100
步骤 3:运行 Hayabusa 快速生成时间线
# Install Hayabusa
wget https://github.com/Yamato-Security/hayabusa/releases/latest/download/hayabusa-linux-x64-musl.zip
unzip hayabusa-linux-x64-musl.zip -d /opt/hayabusa
# Generate CSV timeline with all detection rules
/opt/hayabusa/hayabusa csv-timeline \
-d /cases/case-2024-001/evtx/ \
-o /cases/case-2024-001/analysis/hayabusa_timeline.csv \
-p verbose
# Generate JSON timeline
/opt/hayabusa/hayabusa json-timeline \
-d /cases/case-2024-001/evtx/ \
-o /cases/case-2024-001/analysis/hayabusa_timeline.json
# Run with only critical and high severity detections
/opt/hayabusa/hayabusa csv-timeline \
-d /cases/case-2024-001/evtx/ \
-o /cases/case-2024-001/analysis/hayabusa_critical.csv \
-p verbose \
--min-level critical
# Generate detection summary (metrics)
/opt/hayabusa/hayabusa metrics \
-d /cases/case-2024-001/evtx/ \
-o /cases/case-2024-001/analysis/hayabusa_metrics.csv
# Logon summary
/opt/hayabusa/hayabusa logon-summary \
-d /cases/case-2024-001/evtx/ \
-o /cases/case-2024-001/analysis/logon_summary.csv
步骤 4:解析特定的重要事件 ID
# Extract authentication events with python-evtx
pip install evtx
python3 << 'PYEOF'
import json
from evtx import PyEvtxParser
parser = PyEvtxParser("/cases/case-2024-001/evtx/Security.evtx")
# Critical Event IDs mapping
critical_events = {
'4624': 'Successful Logon',
'4625': 'Failed Logon',
'4634': 'Logoff',
'4648': 'Explicit Credential Logon',
'4672': 'Special Privileges Assigned',
'4688': 'Process Created',
'4689': 'Process Exited',
'4697': 'Service Installed',
'4698': 'Scheduled Task Created',
'4720': 'User Account Created',
'4724': 'Password Reset Attempted',
'4728': 'Member Added to Global Group',
'4732': 'Member Added to Local Group',
'4756': 'Member Added to Universal Group',
'1102': 'Audit Log Cleared',
'4688': 'New Process Created'
}
results = {eid: [] for eid in critical_events}
for record in parser.records_json():
data = json.loads(record['data'])
event_id = str(data['Event']['System']['EventID'])
if event_id in critical_events:
event_data = data['Event'].get('EventData', {})
results[event_id].append({
'timestamp': data['Event']['System']['TimeCreated']['#attributes']['SystemTime'],
'event_id': event_id,
'description': critical_events[event_id],
'data': event_data
})
# Print summary
for eid, events in results.items():
if events:
print(f"\n[{eid}] {critical_events[eid]}: {len(events)} events")
for e in events[:3]:
print(f" {e['timestamp']}: {json.dumps(e['data'], default=str)[:200]}")
if len(events) > 3:
print(f" ... and {len(events)-3} more")
# Save full results
with open('/cases/case-2024-001/analysis/critical_events.json', 'w') as f:
json.dump(results, f, indent=2, default=str)
PYEOF
步骤 5:检测特定攻击模式
# Detect Pass-the-Hash (Logon Type 9 with NTLM)
python3 << 'PYEOF'
import json
from evtx import PyEvtxParser
parser = PyEvtxParser("/cases/case-2024-001/evtx/Security.evtx")
print("=== PASS-THE-HASH INDICATORS ===")
print("Looking for: Event 4624, Logon Type 9, NTLM authentication\n")
for record in parser.records_json():
data = json.loads(record['data'])
event_id = str(data['Event']['System']['EventID'])
if event_id == '4624':
event_data = data['Event'].get('EventData', {})
logon_type = str(event_data.get('LogonType', ''))
auth_package = str(event_data.get('AuthenticationPackageName', ''))
logon_process = str(event_data.get('LogonProcessName', ''))
# Pass-the-Hash indicators
if logon_type == '9' and 'NTLM' in auth_package:
timestamp = data['Event']['System']['TimeCreated']['#attributes']['SystemTime']
target = event_data.get('TargetUserName', 'Unknown')
source_ip = event_data.get('IpAddress', 'N/A')
print(f" [{timestamp}] PtH: User={target}, IP={source_ip}, Auth={auth_package}")
# Network logon with NTLM (lateral movement)
if logon_type == '3' and 'NTLM' in auth_package:
timestamp = data['Event']['System']['TimeCreated']['#attributes']['SystemTime']
target = event_data.get('TargetUserName', 'Unknown')
source_ip = event_data.get('IpAddress', 'N/A')
workstation = event_data.get('WorkstationName', 'N/A')
print(f" [{timestamp}] Network NTLM: User={target}, IP={source_ip}, WS={workstation}")
PYEOF
# Detect log clearing / anti-forensics
python3 << 'PYEOF'
import json
from evtx import PyEvtxParser
for log_file in ['Security.evtx', 'System.evtx']:
path = f"/cases/case-2024-001/evtx/{log_file}"
try:
parser = PyEvtxParser(path)
for record in parser.records_json():
data = json.loads(record['data'])
event_id = str(data['Event']['System']['EventID'])
if event_id in ('1102', '104'): # Security log cleared, System log cleared
timestamp = data['Event']['System']['TimeCreated']['#attributes']['SystemTime']
print(f"LOG CLEARED: [{timestamp}] EventID {event_id} in {log_file}")
except Exception as e:
print(f"Error parsing {log_file}: {e}")
PYEOF
核心概念
| 概念 | 描述 |
|---|---|
| EVTX 格式 | Vista/Server 2008 引入的基于二进制 XML 的 Windows 事件日志格式 |
| 事件 ID | 特定事件类型的数字标识符(例如,4624 = 登录成功) |
| 登录类型 | 身份验证方式的分类(2 = 交互式,3 = 网络,10 = RDP) |
| Sigma 规则 | 可映射到特定 SIEM/日志查询的通用检测特征 |
| Sysmon | 提供详细进程和网络事件的 Microsoft 系统监控驱动程序 |
| 审核策略 | 用于控制 Windows 记录哪些事件的 GPO 设置 |
| 事件转发(WEF) | Windows 用于集中收集事件日志的机制 |
| EVTX 通道 | 为不同事件类别和应用程序单独设置的日志文件 |
工具和系统
| 工具 | 用途 |
|---|---|
| Chainsaw | 基于 Sigma 的 EVTX 分析和威胁狩猎工具 |
| Hayabusa | 快速生成 Windows 事件日志取证时间线的工具 |
| EvtxECmd | Eric Zimmerman 的命令行 EVTX 解析器,可输出 CSV/JSON |
| python-evtx | 用于解析 EVTX 文件的 Python 库 |
| LogParser | 用于 Windows 日志的类 Microsoft SQL 查询引擎 |
| Event Log Explorer | 用于浏览和分析 EVTX 文件的 GUI 工具 |
| KAPE | 包含事件日志在内的自动化分诊收集工具 |
| Velociraptor | 包含 EVTX 收集和狩猎工件的端点 Agent |
常见场景
场景 1:检测横向移动 筛选登录类型为 3(网络)和 10(RDP)的事件 4624,识别异常的源和目标组合,检查事件 4648(显式凭据)以确认是否存在哈希传递,并将其与目标系统上的进程创建事件(4688)进行关联。
场景 2:检测权限提升 搜索意外用户的事件 4672(已分配特殊权限),检查事件 4728/4732(组成员身份变更)是否将用户添加到管理员组,查找可能表明获得新的系统级访问权限的事件 4697(服务已安装),并与事件 4720(帐户创建)进行关联。
场景 3:检测 PowerShell 攻击 分析 PowerShell Operational 日志中的脚本块日志记录(事件 4104),搜索事件 4688(包含命令行的进程创建)中的编码命令,检测 AMSI 绕过尝试,识别下载器和已知攻击工具的调用。
场景 4:重建勒索软件事件 从初始访问开始构建时间线(来自外部 IP 的 4624),追踪通过组成员身份变更进行的权限提升,识别用于持久化的服务安装,查找加密可执行文件的进程创建事件,并检测 System 日志中的卷影副本删除事件。
输出格式
Windows Event Log Analysis Summary:
System: DC01.corp.local (Windows Server 2019)
Log Files Analyzed: 15 EVTX files
Total Events: 2,456,789
Analysis Period: 2024-01-10 to 2024-01-20
Chainsaw Detections:
Critical: 12 (Mimikatz usage, PsExec, log clearing)
High: 34 (Network NTLM logons, encoded PowerShell)
Medium: 89 (Unusual service installations, scheduled tasks)
Low: 234 (Informational)
Hayabusa Timeline:
Total Alerts: 369
Unique Rules Triggered: 45
Top Rules:
- Suspicious NTLM Authentication (34 hits)
- PowerShell Download Cradle (12 hits)
- Service Installation Suspicious Path (8 hits)
Critical Findings:
2024-01-15 14:32 - RDP brute force (234 failed, 1 success from 203.0.113.45)
2024-01-15 14:45 - Admin account created (svcbackup) - Event 4720
2024-01-16 02:30 - PsExec service installed on DC01 - Event 4697
2024-01-18 03:00 - Security log cleared - Event 1102
Reports:
Chainsaw: /analysis/chainsaw_results/
Hayabusa: /analysis/hayabusa_timeline.csv
Critical Events: /analysis/critical_events.json
评论
支持 Markdown