关于 performing-log-analysis-for-forensic-investigation
这是一项用于解析、关联和审查系统及应用日志的取证调查技能,面向需要还原事件时间线的事件响应人员。它帮助从多个日志源追踪可疑活动,并整理调查报告。
主要功能
- 01收集并保全日志来源
- 02解析 Windows EVTX 和 Linux 日志
- 03关联多个来源的事件
- 04构建事件时间线
- 05检查日志完整性及反取证迹象
适用场景
- 01根据系统日志还原事件时间线
- 02追踪入侵后的访问与横向活动
- 03调查暴力破解或内部威胁
- 04编写取证事件 chronology 报告
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ mukul975/ anthropic-cybersecurity-skills --skill performing-log-analysis-for-forensic-investigation安装后在 Claude Code 中输入/performing-log-analysis-for-forensic-investigation确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
LICENSEreferences/api-reference.mdscripts/agent.py详细介绍
执行日志分析以进行取证调查
何时使用
- 当需要从可用日志来源重建安全事件的时间线时
- 在入侵后调查期间,用于识别初始访问、横向移动和数据外泄
- 当需要关联多个系统和日志来源中的事件时
- 用于建立未授权访问或违反策略的证据
- 当需要准备要求详细事件时间顺序的取证报告时
前提条件
- 可访问已收集的日志文件(Windows 事件日志、syslog、应用程序日志)
- 日志解析工具(LogParser、jq、awk 或 ELK 堆栈)
- 了解日志格式(EVTX、syslog、JSON、CSV)
- 所有日志来源的时间戳均已通过 NTP 同步,以便进行关联
- 有足够的存储空间用于日志聚合和索引
- 时间线分析工具(log2timeline、Plaso)
工作流
步骤 1:收集并保存日志来源
# Create case log directory structure
mkdir -p /cases/case-2024-001/logs/{windows,linux,network,application,web}
# Extract Windows Event Logs from forensic image
cp /mnt/evidence/Windows/System32/winevt/Logs/*.evtx /cases/case-2024-001/logs/windows/
# Key Windows Event Logs to collect
# Security.evtx - Authentication, access control, policy changes
# System.evtx - Service starts/stops, driver loads, system errors
# Application.evtx - Application errors and events
# Microsoft-Windows-PowerShell%4Operational.evtx - PowerShell execution
# Microsoft-Windows-Sysmon%4Operational.evtx - Sysmon detailed events
# Microsoft-Windows-TaskScheduler%4Operational.evtx - Scheduled tasks
# Microsoft-Windows-TerminalServices-LocalSessionManager%4Operational.evtx - RDP
# Collect Linux logs
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/
# Collect web server logs
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/
# Hash all collected logs for integrity
find /cases/case-2024-001/logs/ -type f -exec sha256sum {} \; > /cases/case-2024-001/logs/log_hashes.txt
步骤 2:解析 Windows 事件日志
# Install python-evtx for EVTX parsing
pip install python-evtx
# Convert EVTX to XML/JSON for analysis
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
# Using 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
# Key Security Event IDs to investigate
# 4624 - Successful logon
# 4625 - Failed logon
# 4648 - Logon using explicit credentials (runas, lateral movement)
# 4672 - Special privileges assigned (admin logon)
# 4688 - Process creation (with command line if auditing enabled)
# 4697 - Service installed
# 4698/4702 - Scheduled task created/updated
# 4720 - User account created
# 4732 - Member added to security-enabled local group
# 1102 - Audit log cleared
# Extract specific events with 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}] EventID: {event_id}")
for data in root.findall('.//ns:Data', ns):
print(f" {data.get('Name')}: {data.text}")
print()
PYEOF
步骤 3:解析并分析 Linux/Syslog 条目
# Parse auth.log for SSH and sudo events
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
# Extract failed SSH login attempts
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
# Extract successful SSH logins
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
# Parse audit logs for file access and command execution
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
# Parse web access logs for suspicious requests
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
# Extract unique IP addresses from web logs
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:关联跨来源事件
# Normalize timestamps and merge log sources
python3 << 'PYEOF'
import csv
import datetime
from collections import defaultdict
events = []
# Parse Windows Security events (pre-exported to 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', '')
})
# Parse Linux auth events
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': ''
})
# Sort by timestamp
events.sort(key=lambda x: x['timestamp'])
# Write correlated timeline
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"Total correlated events: {len(events)}")
PYEOF
# Quick correlation: find events within time windows
# Look for lateral movement patterns
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:生成取证时间线报告
# Create structured investigation report
cat << 'REPORT' > /cases/case-2024-001/analysis/log_analysis_report.txt
LOG ANALYSIS FORENSIC REPORT
=============================
Case: 2024-001
Analyst: [Examiner Name]
Date: $(date -u)
LOG SOURCES ANALYZED:
- Windows Security Event Log (Security.evtx) - 245,678 events
- Windows System Event Log (System.evtx) - 45,234 events
- Windows PowerShell Operational - 12,456 events
- Linux auth.log - 34,567 entries
- Apache access.log - 567,890 entries
- Linux audit.log - 89,012 entries
KEY FINDINGS:
1. Initial Access: [timestamp] - Successful RDP login from external IP
2. Privilege Escalation: [timestamp] - New admin account created
3. Lateral Movement: [timestamp] - Pass-the-hash detected across 3 systems
4. Data Exfiltration: [timestamp] - Large data transfer to external IP
5. Log Tampering: [timestamp] - Security event log cleared (Event 1102)
TIMELINE OF EVENTS:
[See correlated_timeline.csv for complete chronology]
REPORT
# Package analysis artifacts
tar -czf /cases/case-2024-001/log_analysis_package.tar.gz \
/cases/case-2024-001/analysis/
关键概念
| 概念 | 描述 |
|---|---|
| 事件关联 | 按时间、IP、用户或会话将多个日志来源中的相关事件关联起来 |
| 日志规范化 | 将多样的日志格式转换为通用模式,以便统一分析 |
| 时间线分析 | 按时间顺序排列事件,以重建事件序列 |
| 日志完整性 | 使用哈希和证据链验证日志未被篡改 |
| 登录类型 | Windows 对身份验证方法的分类(2=交互式,3=网络,10=RDP) |
| 审核策略 | 确定哪些事件会被记录到日志中的系统配置 |
| 日志轮转 | 影响证据可用性的日志文件自动归档 |
| 反取证 | 攻击者清除或修改日志以掩盖痕迹的技术 |
工具与系统
| 工具 | 用途 |
|---|---|
| python-evtx | 用于解析 Windows EVTX 事件日志文件的 Python 库 |
| evtxexport | 来自 libevtx 的命令行 EVTX 导出实用程序 |
| LogParser | 面向 Windows 日志的 Microsoft SQL 风格查询引擎 |
| 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 和时间线,与应用程序日志关联以确认成功利用,通过系统和认证日志追踪利用后活动。
场景 4:勒索软件事件时间线 通过进程创建事件(4688)识别初始执行,通过服务安装(4697)追踪权限提升,通过网络登录(4624 Type 3)映射横向移动,从文件系统活动识别加密开始时间,找到最早的 IoC 以确定修复范围。
输出格式
Log Analysis Summary:
Investigation Period: 2024-01-15 00:00 to 2024-01-20 23:59 UTC
Total Events Analyzed: 894,567
Log Sources: 6 (3 Windows, 3 Linux)
Critical Events:
Failed Logons: 1,234 (from 5 unique IPs)
Successful Logons: 456 (3 anomalous)
Account Changes: 12 (1 unauthorized admin creation)
Process Creations: 8,234 (15 suspicious)
Log Clearings: 2 (Security log cleared at 2024-01-18 03:00 UTC)
Service Installs: 3 (1 unknown service)
Attack Timeline:
2024-01-15 14:32 - Initial access via RDP brute force
2024-01-15 14:45 - Admin account "svcbackup" created
2024-01-16 02:15 - Lateral movement to 3 servers
2024-01-17 03:00 - Data staging in C:\ProgramData\temp\
2024-01-18 01:30 - 4.2 GB exfiltrated to 185.x.x.x
2024-01-18 03:00 - Security logs cleared
Report: /cases/case-2024-001/analysis/log_analysis_report.txt
评论
支持 Markdown