mcpField
P
performing-log-analysis-for-forensic-investigation

performing-log-analysis-for-forensic-investigation

github.com/mukul975セキュリティ35.2k63 回インストール8 週間前に更新
リポジトリ

performing-log-analysis-for-forensic-investigation について

システムやアプリケーションのログを解析、相関、確認するフォレンジック調査スキルです。複数のログソースから事象の時系列を再構成し、不審な活動を追跡して調査報告をまとめるインシデント対応担当者向けです。

主な機能

  1. 01ログソースの収集と保全
  2. 02Windows EVTXとLinuxログの解析
  3. 03複数ソース間のイベント相関
  4. 04インシデント時系列の作成
  5. 05ログ完全性とアンチフォレンジックの確認

活用シーン

  1. 01システムログから事象の時系列を再構成
  2. 02侵害後のアクセスや横展開を追跡
  3. 03ブルートフォース攻撃や内部不正を調査
  4. 04フォレンジックの時系列報告を作成

インストール

コマンドをコピーしてターミナルで実行します。

$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 と一緒にインストールされる参考資料やスクリプト。

LICENSE
references/
api-reference.md
scripts/
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-evtxWindows EVTX イベントログファイルを解析する Python ライブラリ
evtxexportlibevtx のコマンドライン EVTX エクスポートユーティリティ
LogParserWindows ログ向けの Microsoft SQL 類似クエリエンジン
ausearchLinux 監査ログの検索ユーティリティ
jq構造化ログ形式を解析する JSON クエリツール
ELK Stackログの集約と可視化を行う Elasticsearch、Logstash、Kibana
ChainsawSigma ベースの Windows イベントログ分析ツール
Hayabusa高速な Windows イベントログのフォレンジックタイムライン生成ツール

よくあるシナリオ

シナリオ 1:ブルートフォース攻撃の検出 Security.evtx を Event 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

コメント