performing-log-analysis-for-forensic-investigation
收集、解析和关联系统、应用程序及安全日志,以在取证调查期间重建事件并建立时间线。
Best use case
performing-log-analysis-for-forensic-investigation is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
收集、解析和关联系统、应用程序及安全日志,以在取证调查期间重建事件并建立时间线。
Teams using performing-log-analysis-for-forensic-investigation should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/performing-log-analysis-for-forensic-investigation/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How performing-log-analysis-for-forensic-investigation Compares
| Feature / Agent | performing-log-analysis-for-forensic-investigation | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
收集、解析和关联系统、应用程序及安全日志,以在取证调查期间重建事件并建立时间线。
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# 执行取证调查的日志分析
## 适用场景
- 从可用日志来源重建安全事件时间线时
- 后渗透调查期间识别初始访问、横向移动和数据外泄时
- 跨多个系统和日志来源关联事件时
- 建立未授权访问或违规行为的证据时
- 准备需要详细事件编年记录的取证报告时
## 前置条件
- 能够访问已收集的日志文件(Windows 事件日志、syslog、应用程序日志)
- 日志解析工具(LogParser、jq、awk 或 ELK Stack)
- 了解日志格式(EVTX、syslog、JSON、CSV)
- 所有日志来源的 NTP 同步时间戳(用于关联)
- 用于日志聚合和索引的充足存储空间
- 时间线分析工具(log2timeline、Plaso)
## 工作流程
### 步骤 1:收集并保全日志来源
```bash
# 创建案例日志目录结构
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
```
### 步骤 2:解析 Windows 事件日志
```bash
# 安装 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
```
### 步骤 3:解析和分析 Linux/Syslog 条目
```bash
# 解析 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
```
### 步骤 4:跨来源关联事件
```bash
# 规范化时间戳并合并日志来源
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
```
### 步骤 5:生成取证时间线报告
```bash
# 创建结构化调查报告
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
```Related Skills
performing-yara-rule-development-for-detection
通过识别可执行文件中的唯一字节模式、字符串和行为指标,开发精准的 YARA 恶意软件检测规则,同时将误报率降至最低。
performing-wireless-security-assessment-with-kismet
使用 Kismet 通过被动射频监控进行无线网络安全评估,检测流氓接入点(Rogue AP)、隐藏 SSID、弱加密和未授权客户端。
performing-wireless-network-penetration-test
执行无线网络渗透测试,通过捕获握手包、破解 WPA2/WPA3 密钥、检测流氓接入点以及使用 Aircrack-ng 和相关工具测试无线网络分段,评估 WiFi 安全性。
performing-windows-artifact-analysis-with-eric-zimmerman-tools
使用 Eric Zimmerman 的开源 EZ Tools 套件(包括 KAPE、MFTECmd、PECmd、LECmd、JLECmd 和 Timeline Explorer)执行全面的 Windows 取证制品分析,解析注册表 hive、预取文件、事件日志和文件系统元数据。
performing-wifi-password-cracking-with-aircrack
在授权无线安全评估中捕获 WPA/WPA2 握手包,并使用 aircrack-ng、hashcat 和字典攻击进行离线密码破解, 以评估密码短语强度和无线网络安全状况。
performing-web-cache-poisoning-attack
在授权安全测试期间,通过未纳入缓存键的头部和参数毒化缓存响应,利用 Web 缓存机制向其他用户投递恶意内容。
performing-web-cache-deception-attack
通过利用 CDN 缓存层与源服务器之间的路径规范化差异,执行 Web 缓存欺骗攻击,从而缓存并获取敏感的已认证内容。
performing-web-application-vulnerability-triage
使用 OWASP 风险评级方法论对 DAST/SAST 扫描器的 Web 应用程序漏洞发现进行分类,区分真阳性和假阳性,并确定修复优先级。
performing-web-application-scanning-with-nikto
Nikto 是一款开源 Web 服务器和 Web 应用程序扫描器,可针对超过 7,000 个潜在危险文件/程序进行测试,检查超过 1,250 个服务器的过期版本,并识别超过 270 个服务器的版本特定问题。
performing-web-application-penetration-test
遵循 OWASP Web 安全测试指南(WSTG)方法论,对 Web 应用程序执行系统化安全测试,识别认证、授权、 输入验证、会话管理和业务逻辑中的漏洞。测试人员以 Burp Suite 作为主要拦截代理,结合手动测试技术 发现自动化扫描器遗漏的缺陷。适用于 Web 应用渗透测试、OWASP 测试、应用安全评估或 Web 漏洞测试等请求场景。
performing-web-application-firewall-bypass
使用编码技术、HTTP 方法操控、参数污染和载荷混淆绕过 Web 应用防火墙保护,将 SQL 注入、XSS 及其他攻击载荷穿透 WAF 检测规则。
performing-vulnerability-scanning-with-nessus
使用 Tenable Nessus 执行认证和未认证漏洞扫描,识别网络基础设施、服务器和应用程序中的已知漏洞、 错误配置、默认凭据和缺失补丁。扫描器将发现与 CVE 数据库和 CVSS 评分关联,生成优先级修复指导。 适用于漏洞扫描、Nessus 评估、补丁合规检查或自动化漏洞检测等请求场景。