analyzing-prefetch-files-for-execution-history について
Windows Prefetch ファイルからプログラムの実行履歴を再構成するフォレンジック分析スキルです。インシデント対応担当者向けに、収集、解析、不審な実行の調査、タイムライン作成を案内します。
主な機能
- 01フォレンジックイメージからの Prefetch ファイル収集
- 02PECmd または Python による解析
- 03不審な実行証拠の確認
- 04実行タイムラインの作成
- 05他のフォレンジック証跡との照合
活用シーン
- 01不審なバイナリの実行確認
- 02攻撃ツール使用順序の再構成
- 03データのステージングと転送の調査
- 04アンチフォレンジックツールの実行記録の確認
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ mukul975/ anthropic-cybersecurity-skills --skill analyzing-prefetch-files-for-execution-historyインストール後、Claude Code で/analyzing-prefetch-files-for-execution-historyを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
LICENSEreferences/api-reference.mdscripts/agent.py詳細
実行履歴を調べるための Prefetch ファイルの分析
使用するタイミング
- Windows システム上で、どのプログラムがいつ実行されたかを特定するとき
- マルウェア調査で、不審なバイナリの実行を確認するとき
- インシデント発生中のアプリケーション使用状況のタイムラインを作成するとき
- プログラムの実行と他のフォレンジックアーティファクトを関連付けるとき
- 実行されたアンチフォレンジックツールや未承認ソフトウェアを特定するとき
前提条件
- フォレンジックイメージから Windows の Prefetch ディレクトリ(C:\Windows\Prefetch\)にアクセスできること
- PECmd(Eric Zimmerman)、WinPrefetchView、または python-prefetch パーサー
- Prefetch ファイル形式(バージョン 17、23、26、30)の理解
- Prefetch が有効になっている Windows システム(クライアント OS ではデフォルトで有効、サーバーでは無効)
- Prefetch の命名規則(APPNAME-HASH.pf)の知識
ワークフロー
ステップ 1:フォレンジックイメージから Prefetch ファイルを抽出する
# Mount the forensic image
mount -o ro,loop,offset=$((2048*512)) /cases/case-2024-001/images/evidence.dd /mnt/evidence
# Copy all prefetch files
mkdir -p /cases/case-2024-001/prefetch/
cp /mnt/evidence/Windows/Prefetch/*.pf /cases/case-2024-001/prefetch/
# Count and list prefetch files
ls -la /cases/case-2024-001/prefetch/ | wc -l
ls -la /cases/case-2024-001/prefetch/ | head -30
# Hash all prefetch files for integrity
sha256sum /cases/case-2024-001/prefetch/*.pf > /cases/case-2024-001/prefetch/pf_hashes.txt
# Note: Prefetch filename format is EXECUTABLE_NAME-XXXXXXXX.pf
# The hash (XXXXXXXX) is based on the executable path
# Same executable from different paths creates different prefetch files
ステップ 2:PECmd で Prefetch ファイルを解析する
# Using Eric Zimmerman's PECmd (Windows or via Mono/Wine on Linux)
# Download from https://ericzimmerman.github.io/
# Parse a single prefetch file
PECmd.exe -f "C:\cases\prefetch\POWERSHELL.EXE-A]B2C3D4.pf"
# Parse all prefetch files and output to CSV
PECmd.exe -d "C:\cases\prefetch\" --csv "C:\cases\analysis\" --csvf prefetch_results.csv
# Parse with JSON output
PECmd.exe -d "C:\cases\prefetch\" --json "C:\cases\analysis\" --jsonf prefetch_results.json
# Output includes for each file:
# - Executable name and path
# - Run count
# - Last run time (up to 8 timestamps in Windows 10)
# - Files and directories referenced during execution
# - Volume information (serial number, creation date)
# - Prefetch file creation time
ステップ 3:Linux ベースの分析で Python を使用して解析する
pip install prefetch
python3 << 'PYEOF'
import os
import json
from datetime import datetime
# Parse prefetch files using python
import struct
def parse_prefetch(filepath):
"""Parse a Windows Prefetch file."""
with open(filepath, 'rb') as f:
data = f.read()
# Check for MAM compressed format (Windows 10)
if data[:4] == b'MAM\x04':
import lznt1 # or use DecompressBuffer
# Windows 10 prefetch files are compressed
print(f" [Compressed Win10 format - use PECmd for full parsing]")
return None
# Version 17 (XP), 23 (Vista/7), 26 (8.1), 30 (10)
version = struct.unpack('<I', data[0:4])[0]
signature = data[4:8]
if signature != b'SCCA':
print(f" Invalid prefetch signature")
return None
file_size = struct.unpack('<I', data[8:12])[0]
exec_name = data[16:76].decode('utf-16-le').strip('\x00')
run_count = struct.unpack('<I', data[208:212])[0] if version >= 23 else struct.unpack('<I', data[144:148])[0]
result = {
'version': version,
'executable': exec_name,
'file_size': file_size,
'run_count': run_count,
}
# Extract last execution timestamps
if version == 23: # Vista/7 - 1 timestamp
ts = struct.unpack('<Q', data[128:136])[0]
result['last_run'] = filetime_to_datetime(ts)
elif version >= 26: # Win8+ - up to 8 timestamps
timestamps = []
for i in range(8):
ts = struct.unpack('<Q', data[128+i*8:136+i*8])[0]
if ts > 0:
timestamps.append(filetime_to_datetime(ts))
result['last_run_times'] = timestamps
return result
def filetime_to_datetime(ft):
"""Convert Windows FILETIME to datetime string."""
if ft == 0:
return None
timestamp = (ft - 116444736000000000) / 10000000
try:
return datetime.utcfromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S UTC')
except (OSError, ValueError):
return None
# Process all prefetch files
prefetch_dir = '/cases/case-2024-001/prefetch/'
results = []
for filename in sorted(os.listdir(prefetch_dir)):
if filename.lower().endswith('.pf'):
filepath = os.path.join(prefetch_dir, filename)
print(f"\n=== {filename} ===")
result = parse_prefetch(filepath)
if result:
print(f" Executable: {result['executable']}")
print(f" Run Count: {result['run_count']}")
if 'last_run' in result:
print(f" Last Run: {result['last_run']}")
elif 'last_run_times' in result:
for i, ts in enumerate(result['last_run_times']):
print(f" Run Time {i+1}: {ts}")
results.append(result)
# Save results
with open('/cases/case-2024-001/analysis/prefetch_analysis.json', 'w') as f:
json.dump(results, f, indent=2)
PYEOF
ステップ 4:不審な実行の証拠を特定する
# Search for known malicious tool names in prefetch
ls /cases/case-2024-001/prefetch/ | grep -iE \
'(MIMIKATZ|PSEXEC|WMIC|COBALT|BEACON|PWDUMP|PROCDUMP|LAZAGNE|RUBEUS|BLOODHOUND|SHARPHOUND|CERTUTIL|BITSADMIN)'
# Search for script interpreters (potential malicious execution)
ls /cases/case-2024-001/prefetch/ | grep -iE \
'(POWERSHELL|CMD\.EXE|WSCRIPT|CSCRIPT|MSHTA|REGSVR32|RUNDLL32|MSIEXEC)'
# Search for remote access tools
ls /cases/case-2024-001/prefetch/ | grep -iE \
'(TEAMVIEWER|ANYDESK|LOGMEIN|VNC|SPLASHTOP|SCREENCONNECT|AMMYY)'
# Search for data exfiltration tools
ls /cases/case-2024-001/prefetch/ | grep -iE \
'(RAR|7Z|ZIP|RCLONE|MEGA|DROPBOX|ONEDRIVE|GDRIVE|FTP|CURL|WGET)'
# Find recently created prefetch files (newest executables run)
ls -lt /cases/case-2024-001/prefetch/ | head -20
# Cross-reference with Shimcache and Amcache for confirmation
# Prefetch existence = program was executed at least once
ステップ 5:実行タイムラインを作成する
# Create timeline from prefetch data
python3 << 'PYEOF'
import json
import csv
with open('/cases/case-2024-001/analysis/prefetch_analysis.json') as f:
data = json.load(f)
timeline = []
for entry in data:
if 'last_run_times' in entry:
for ts in entry['last_run_times']:
if ts:
timeline.append({
'timestamp': ts,
'executable': entry['executable'],
'run_count': entry['run_count'],
'source': 'Prefetch'
})
elif 'last_run' in entry and entry['last_run']:
timeline.append({
'timestamp': entry['last_run'],
'executable': entry['executable'],
'run_count': entry['run_count'],
'source': 'Prefetch'
})
# Sort chronologically
timeline.sort(key=lambda x: x['timestamp'])
# Write timeline CSV
with open('/cases/case-2024-001/analysis/execution_timeline.csv', 'w', newline='') as f:
writer = csv.DictWriter(f, fieldnames=['timestamp', 'executable', 'run_count', 'source'])
writer.writeheader()
writer.writerows(timeline)
# Print suspicious time window
for entry in timeline:
if '2024-01-15' in entry['timestamp'] or '2024-01-16' in entry['timestamp']:
print(f" {entry['timestamp']} | {entry['executable']} (x{entry['run_count']})")
PYEOF
主な概念
| 概念 | 説明 |
|---|---|
| Prefetch | アプリケーションデータを事前に読み込み、実行状況を追跡する Windows のパフォーマンス最適化機能 |
| SCCA シグネチャ | 有効な Prefetch ファイルを識別するマジックバイト |
| パスハッシュ | 実行ファイルのパスから生成され、.pf ファイル名の一部となる CRC ベースのハッシュ |
| 実行回数 | 実行ファイルが起動された回数(上限に達すると折り返す場合があります) |
| 最終実行タイムスタンプ | Windows 8 以降では、直近の実行タイムスタンプを最大 8 件保存します |
| 参照ファイル | 実行開始後 10 秒間にアクセスされたファイルとディレクトリの一覧 |
| ボリューム情報 | ソースボリュームを識別するドライブのシリアル番号と作成日 |
| MAM 圧縮 | Windows 10 の Prefetch ファイルで使用される MAM4 圧縮。解析前に解凍が必要です |
ツールとシステム
| ツール | 目的 |
|---|---|
| PECmd | Eric Zimmerman の Prefetch パーサー。CSV/JSON 出力に対応 |
| WinPrefetchView | Prefetch ファイルを表示する NirSoft の GUI ツール |
| python-prefetch | Prefetch ファイルを解析する Python ライブラリ |
| Prefetch Hash Calculator | 実行ファイルのパスから想定されるハッシュを計算するツール |
| KAPE | Prefetch を含むアーティファクトを自動収集 |
| Autopsy | Prefetch 分析モジュールを備えたフォレンジックプラットフォーム |
| Plaso/log2timeline | Prefetch パーサーを含むスーパータイムラインツール |
| Velociraptor | Prefetch の収集および分析用アーティファクトを備えたエンドポイントエージェント |
よくあるシナリオ
シナリオ 1:マルウェアの実行確認 Prefetch ディレクトリでマルウェアの実行ファイル名を検索し、Prefetch ファイルの存在によって実行を確認します。実行回数と最終実行時刻を抽出し、参照 DLL を特定してマルウェアの動作を把握し、レジストリの自動起動エントリと関連付けます。
シナリオ 2:攻撃者ツール使用のタイムライン PsExec、Mimikatz、BloodHound などの攻撃者ツールに対応する Prefetch ファイルを特定し、ツール実行の時系列を作成します。偵察、認証情報の窃取、ラテラルムーブメントなど、攻撃の順序を判断し、タイムスタンプをネットワーク接続ログと照合します。
シナリオ 3:データのステージングと流出 圧縮ツール(7z、WinRAR、zip)の Prefetch エントリを探し、ファイル転送ユーティリティ(rclone、FTP クライアント)の実行を特定します。クラウドストレージクライアントの実行を確認し、データのステージングと転送が行われた時刻をタイムラインにまとめます。
シナリオ 4:アンチフォレンジックの検出 既知のアンチフォレンジックツール(CCleaner、Eraser、SDelete)の実行を確認します。アクティブなシステムとして予想されるよりもファイル数が少ない場合は、Prefetch ディレクトリが最近消去されたかどうかを特定し、他の証拠と照らしてアンチフォレンジックツールの実行時刻を記録します。
出力形式
Prefetch Analysis Summary:
System: Windows 10 Pro (Build 19041)
Prefetch Files: 234
Analysis Period: All available execution history
Execution Statistics:
Total unique executables: 234
First execution: 2023-06-15 (system install)
Latest execution: 2024-01-18 23:45 UTC
Suspicious Executions:
MIMIKATZ.EXE-5F2A3B1C.pf
Run Count: 3 | Last: 2024-01-16 02:30:15 UTC
PSEXEC.EXE-AD70946C.pf
Run Count: 7 | Last: 2024-01-16 02:45:30 UTC
RCLONE.EXE-1F3E5A2B.pf
Run Count: 2 | Last: 2024-01-17 03:15:00 UTC
POWERSHELL.EXE-022A1004.pf
Run Count: 145 | Last: 2024-01-18 14:00:00 UTC
Attack Timeline (from Prefetch):
2024-01-15 14:32 - POWERSHELL.EXE (initial access)
2024-01-16 02:30 - MIMIKATZ.EXE (credential theft)
2024-01-16 02:45 - PSEXEC.EXE (lateral movement)
2024-01-17 03:15 - RCLONE.EXE (data exfiltration)
Report: /cases/case-2024-001/analysis/execution_timeline.csv