Collects, parses Windows EVTX and Linux syslogs, and correlates logs to reconstruct security event timelines during forensic investigations.
npx claudepluginhub killvxk/cybersecurity-skills-zhThis skill uses the workspace's default tool permissions.
- 从可用日志来源重建安全事件时间线时
Collects, parses EVTX/JSON/syslog logs from Windows, Linux, and web servers; correlates events to build forensic timelines for incident reconstruction.
Guides collection, parsing, and correlation of Windows Event Logs, syslog, and app logs to reconstruct timelines in digital forensic investigations.
Extracts, parses, and analyzes Windows event logs (EVTX) using Chainsaw, Hayabusa, and EvtxECmd to detect lateral movement, persistence, and privilege escalation in forensics.
Share bugs, ideas, or general feedback.
# 创建案例日志目录结构
mkdir -p /cases/case-2024-001/logs/{windows,linux,network,application,web}
# 从取证镜像中提取 Windows 事件日志
cp /mnt/evidence/Windows/System32/winevt/Logs/*.evtx /cases/case-2024-001/logs/windows/
# 需要收集的关键 Windows 事件日志
# Security.evtx - 认证、访问控制、策略更改
# System.evtx - 服务启停、驱动加载、系统错误
# Application.evtx - 应用程序错误和事件
# Microsoft-Windows-PowerShell%4Operational.evtx - PowerShell 执行
# Microsoft-Windows-Sysmon%4Operational.evtx - Sysmon 详细事件
# Microsoft-Windows-TaskScheduler%4Operational.evtx - 计划任务
# Microsoft-Windows-TerminalServices-LocalSessionManager%4Operational.evtx - RDP
# 收集 Linux 日志
cp /mnt/evidence/var/log/auth.log* /cases/case-2024-001/logs/linux/
cp /mnt/evidence/var/log/syslog* /cases/case-2024-001/logs/linux/
cp /mnt/evidence/var/log/kern.log* /cases/case-2024-001/logs/linux/
cp /mnt/evidence/var/log/secure* /cases/case-2024-001/logs/linux/
cp /mnt/evidence/var/log/audit/audit.log* /cases/case-2024-001/logs/linux/
# 收集 Web 服务器日志
cp /mnt/evidence/var/log/apache2/access.log* /cases/case-2024-001/logs/web/
cp /mnt/evidence/var/log/nginx/access.log* /cases/case-2024-001/logs/web/
# 对所有收集的日志计算哈希以验证完整性
find /cases/case-2024-001/logs/ -type f -exec sha256sum {} \; > /cases/case-2024-001/logs/log_hashes.txt
# 安装 python-evtx 用于 EVTX 解析
pip install python-evtx
# 将 EVTX 转换为 XML/JSON 以便分析
python3 -c "
import Evtx.Evtx as evtx
import json, xml.etree.ElementTree as ET
with evtx.Evtx('/cases/case-2024-001/logs/windows/Security.evtx') as log:
for record in log.records():
print(record.xml())
" > /cases/case-2024-001/logs/windows/Security_parsed.xml
# 使用 evtxexport(libevtx-utils)
sudo apt-get install libevtx-utils
evtxexport /cases/case-2024-001/logs/windows/Security.evtx \
> /cases/case-2024-001/logs/windows/Security_exported.txt
# 需要调查的关键安全事件 ID
# 4624 - 成功登录
# 4625 - 登录失败
# 4648 - 使用显式凭据登录(runas、横向移动)
# 4672 - 分配了特殊权限(管理员登录)
# 4688 - 进程创建(如果启用了审计则含命令行)
# 4697 - 服务已安装
# 4698/4702 - 计划任务已创建/更新
# 4720 - 用户账户已创建
# 4732 - 成员已添加到安全性已启用的本地组
# 1102 - 审计日志已清除
# 使用 python-evtx 提取特定事件
python3 << 'PYEOF'
import Evtx.Evtx as evtx
import xml.etree.ElementTree as ET
target_events = ['4624', '4625', '4648', '4672', '4688', '4697', '1102']
with evtx.Evtx('/cases/case-2024-001/logs/windows/Security.evtx') as log:
for record in log.records():
root = ET.fromstring(record.xml())
ns = {'ns': 'http://schemas.microsoft.com/win/2004/08/events/event'}
event_id = root.find('.//ns:EventID', ns).text
if event_id in target_events:
time = root.find('.//ns:TimeCreated', ns).get('SystemTime')
print(f"[{time}] 事件 ID: {event_id}")
for data in root.findall('.//ns:Data', ns):
print(f" {data.get('Name')}: {data.text}")
print()
PYEOF
# 解析 auth.log 中的 SSH 和 sudo 事件
grep -E '(sshd|sudo|su\[|passwd|useradd|usermod)' \
/cases/case-2024-001/logs/linux/auth.log* | \
sort > /cases/case-2024-001/analysis/auth_events.txt
# 提取 SSH 登录失败记录
grep 'Failed password' /cases/case-2024-001/logs/linux/auth.log* | \
awk '{print $1,$2,$3,$9,$11}' | sort | uniq -c | sort -rn \
> /cases/case-2024-001/analysis/failed_ssh.txt
# 提取成功的 SSH 登录
grep 'Accepted' /cases/case-2024-001/logs/linux/auth.log* | \
awk '{print $1,$2,$3,$9,$11}' > /cases/case-2024-001/analysis/successful_ssh.txt
# 解析审计日志中的文件访问和命令执行
ausearch -if /cases/case-2024-001/logs/linux/audit.log \
--start 2024-01-15 --end 2024-01-20 \
-m EXECVE > /cases/case-2024-001/analysis/audit_commands.txt
ausearch -if /cases/case-2024-001/logs/linux/audit.log \
-m USER_AUTH,USER_LOGIN,USER_CMD \
> /cases/case-2024-001/analysis/audit_auth.txt
# 解析 Web 访问日志中的可疑请求
cat /cases/case-2024-001/logs/web/access.log* | \
grep -iE '(union.*select|<script|\.\.\/|cmd\.exe|/etc/passwd)' \
> /cases/case-2024-001/analysis/web_attacks.txt
# 从 Web 日志中提取唯一 IP 地址
awk '{print $1}' /cases/case-2024-001/logs/web/access.log* | \
sort | uniq -c | sort -rn > /cases/case-2024-001/analysis/web_ips.txt
# 规范化时间戳并合并日志来源
python3 << 'PYEOF'
import csv
import datetime
from collections import defaultdict
events = []
# 解析 Windows 安全事件(预先导出为 CSV)
with open('/cases/case-2024-001/analysis/windows_events.csv') as f:
reader = csv.DictReader(f)
for row in reader:
events.append({
'timestamp': row['TimeCreated'],
'source': 'Windows-Security',
'event_id': row['EventID'],
'description': row['Description'],
'details': row.get('Details', '')
})
# 解析 Linux auth 事件
with open('/cases/case-2024-001/analysis/auth_events.txt') as f:
for line in f:
parts = line.strip().split()
if len(parts) >= 6:
events.append({
'timestamp': ' '.join(parts[:3]),
'source': 'Linux-Auth',
'event_id': parts[4].rstrip(':'),
'description': ' '.join(parts[5:]),
'details': ''
})
# 按时间戳排序
events.sort(key=lambda x: x['timestamp'])
# 写入关联时间线
with open('/cases/case-2024-001/analysis/correlated_timeline.csv', 'w', newline='') as f:
writer = csv.DictWriter(f, fieldnames=['timestamp', 'source', 'event_id', 'description', 'details'])
writer.writeheader()
writer.writerows(events)
print(f"关联事件总数:{len(events)}")
PYEOF
# 快速关联:查找时间窗口内的事件
# 查找横向移动模式
grep "4648\|4624.*Type.*3\|4624.*Type.*10" /cases/case-2024-001/analysis/windows_events.csv | \
sort > /cases/case-2024-001/analysis/lateral_movement.txt
# 创建结构化调查报告
cat << 'REPORT' > /cases/case-2024-001/analysis/log_analysis_report.txt
日志分析取证报告
=============================
案例:2024-001
分析员:[检查员姓名]
日期:$(date -u)
已分析的日志来源:
- Windows 安全事件日志(Security.evtx)- 245,678 个事件
- Windows 系统事件日志(System.evtx)- 45,234 个事件
- Windows PowerShell Operational - 12,456 个事件
- Linux auth.log - 34,567 条记录
- Apache access.log - 567,890 条记录
- Linux audit.log - 89,012 条记录
关键发现:
1. 初始访问:[时间戳] - 来自外部 IP 的成功 RDP 登录
2. 权限提升:[时间戳] - 新建管理员账户
3. 横向移动:[时间戳] - 检测到跨 3 个系统的哈希传递攻击
4. 数据外泄:[时间戳] - 大量数据传输至外部 IP
5. 日志篡改:[时间戳] - 安全事件日志已清除(事件 1102)
事件时间线:
[完整的时间线见 correlated_timeline.csv]
REPORT
# 打包分析制品
tar -czf /cases/case-2024-001/log_analysis_package.tar.gz \
/cases/case-2024-001/analysis/
| 概念 | 描述 |
|---|---|
| 事件关联(Event correlation) | 通过时间、IP、用户或会话将多个日志来源的相关事件关联起来 |
| 日志规范化(Log normalization) | 将多种日志格式转换为统一模式以进行一致性分析 |
| 时间线分析(Timeline analysis) | 按时间顺序排列事件以重建事件序列 |
| 日志完整性(Log integrity) | 使用哈希和证据链验证日志未被篡改 |
| 登录类型(Logon types) | Windows 认证方法分类(2=交互式、3=网络、10=RDP) |
| 审计策略(Audit policy) | 系统配置,决定哪些事件会被记录在日志中 |
| 日志轮转(Log rotation) | 自动归档日志文件,影响证据可用性 |
| 反取证(Anti-forensics) | 攻击者清除或修改日志以掩盖踪迹的技术 |
| 工具 | 用途 |
|---|---|
| python-evtx | 解析 Windows EVTX 事件日志文件的 Python 库 |
| evtxexport | libevtx 提供的命令行 EVTX 导出工具 |
| LogParser | 微软基于 SQL 的 Windows 日志查询引擎 |
| ausearch | Linux 审计日志搜索工具 |
| jq | 用于解析结构化日志格式的 JSON 查询工具 |
| ELK Stack | 用于日志聚合和可视化的 Elasticsearch、Logstash、Kibana |
| Chainsaw | 基于 Sigma 规则的 Windows 事件日志分析工具 |
| Hayabusa | 快速 Windows 事件日志取证时间线生成器 |
场景 1:暴力破解攻击检测 过滤 Security.evtx 中的事件 ID 4625(登录失败),按来源 IP 和目标账户分组,识别快速连续失败的模式,找到随后的成功登录(4624),追踪被入侵账户的后续活动。
场景 2:内部威胁调查 收集嫌疑人工作站和已访问服务器的所有日志来源,将文件访问事件与认证事件关联,建立非工作时间数据访问的时间线,识别向外部介质或云存储的数据传输。
场景 3:Web 应用程序入侵 解析 Web 服务器访问日志中的 SQLi、XSS 和路径遍历模式,识别攻击 IP 和时间线,关联应用程序日志确认成功利用,通过系统和 auth 日志追踪后渗透活动。
场景 4:勒索软件事件时间线 通过进程创建事件(4688)识别初始执行,通过服务安装(4697)追踪权限提升,通过网络登录(4624 Type 3)绘制横向移动路线,从文件系统活动中识别加密开始时间,找到最早的 IoC 以确定修复范围。
日志分析摘要:
调查期间:2024-01-15 00:00 至 2024-01-20 23:59 UTC
已分析事件总数:894,567
日志来源:6 个(3 个 Windows,3 个 Linux)
关键事件:
登录失败: 1,234 次(来自 5 个唯一 IP)
成功登录: 456 次(3 次异常)
账户更改: 12 次(1 次未授权管理员创建)
进程创建: 8,234 次(15 次可疑)
日志清除: 2 次(安全日志于 2024-01-18 03:00 UTC 被清除)
服务安装: 3 次(1 个未知服务)
攻击时间线:
2024-01-15 14:32 - 通过 RDP 暴力破解实现初始访问
2024-01-15 14:45 - 管理员账户 "svcbackup" 已创建
2024-01-16 02:15 - 横向移动至 3 台服务器
2024-01-17 03:00 - 数据暂存于 C:\ProgramData\temp\
2024-01-18 01:30 - 4.2 GB 数据外泄至 185.x.x.x
2024-01-18 03:00 - 安全日志已清除
报告:/cases/case-2024-001/analysis/log_analysis_report.txt