mcpField
M
memory-forensics

memory-forensics

github.com/oimiragieoセキュリティ4461 回インストール17 週間前に更新
リポジトリ

memory-forensics について

インシデント対応、マルウェア分析、認可された調査でメモリダンプを取得・解析するための防御的フォレンジックスキルです。Volatility 3 などを使い、プロセスやネットワーク活動、コード注入などの痕跡を調べます。

主な機能

  1. 01メモリ取得のガイダンス
  2. 02Volatility 3 による解析手順
  3. 03プロセスとネットワークの調査
  4. 04コード注入と痕跡の分析
  5. 05YARA によるメモリスキャン

活用シーン

  1. 01インシデント対応でメモリ痕跡を調査
  2. 02認可された環境でのマルウェア分析
  3. 03プロセスとネットワークの調査結果を照合

インストール

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

$npx skills add https://github.com/oimiragieo/agent-studio --skill memory-forensics

インストール後、Claude Code で/memory-forensicsを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

commands/
memory-forensics.md
hooks/
post-execute.cjs
pre-execute.cjs
references/
research-requirements.md
rules/
memory-forensics.md
schemas/
input.schema.json
output.schema.json
scripts/
main.cjs
templates/
implementation-template.md

詳細

メモリフォレンジック

セキュリティに関する注意

許可された用途に限ります:これらのスキルは、防御目的のセキュリティ分析および許可された調査に使用するものです。

  • 適切な許可を得たインシデント対応
  • 許可された環境でのフォレンジック調査
  • 防御目的のマルウェア分析
  • CTF コンテストおよびセキュリティ調査
  • 管理された環境での教育目的

以下の目的には絶対に使用しないでください:

  • 許可のないシステムアクセスや監視
  • プライバシーの侵害
  • 知的財産の窃取
  • あらゆる違法行為

インシデント対応やマルウェア分析のために、メモリダンプからアーティファクトを取得、分析、抽出する包括的な手法を紹介します。

メモリの取得

ライブ取得ツール
Windows
# WinPmem (Recommended)
winpmem_mini_x64.exe memory.raw

# DumpIt
DumpIt.exe

# Belkasoft RAM Capturer
# GUI-based, outputs raw format

# Magnet RAM Capture
# GUI-based, outputs raw format
Linux
# LiME (Linux Memory Extractor)
sudo insmod lime.ko "path=/tmp/memory.lime format=lime"

# /dev/mem (limited, requires permissions)
sudo dd if=/dev/mem of=memory.raw bs=1M

# /proc/kcore (ELF format)
sudo cp /proc/kcore memory.elf
macOS
# osxpmem
sudo ./osxpmem -o memory.raw

# MacQuisition (commercial)
仮想マシンのメモリ
# VMware: .vmem file is raw memory
cp vm.vmem memory.raw

# VirtualBox: Use debug console
vboxmanage debugvm "VMName" dumpvmcore --filename memory.elf

# QEMU
virsh dump <domain> memory.raw --memory-only

# Hyper-V
# Checkpoint contains memory state

Volatility 3 フレームワーク

インストールとセットアップ
# Install Volatility 3
pip install volatility3

# Install symbol tables (Windows)
# Download from https://downloads.volatilityfoundation.org/volatility3/symbols/

# Basic usage
vol -f memory.raw <plugin>

# With symbol path
vol -f memory.raw -s /path/to/symbols windows.pslist
基本プラグイン
プロセス分析
# List processes
vol -f memory.raw windows.pslist

# Process tree (parent-child relationships)
vol -f memory.raw windows.pstree

# Hidden process detection
vol -f memory.raw windows.psscan

# Process memory dumps
vol -f memory.raw windows.memmap --pid <PID> --dump

# Process environment variables
vol -f memory.raw windows.envars --pid <PID>

# Command line arguments
vol -f memory.raw windows.cmdline
ネットワーク分析
# Network connections
vol -f memory.raw windows.netscan

# Network connection state
vol -f memory.raw windows.netstat
DLL とモジュールの分析
# Loaded DLLs per process
vol -f memory.raw windows.dlllist --pid <PID>

# Find hidden/injected DLLs
vol -f memory.raw windows.ldrmodules

# Kernel modules
vol -f memory.raw windows.modules

# Module dumps
vol -f memory.raw windows.moddump --pid <PID>
メモリインジェクションの検出
# Detect code injection
vol -f memory.raw windows.malfind

# VAD (Virtual Address Descriptor) analysis
vol -f memory.raw windows.vadinfo --pid <PID>

# Dump suspicious memory regions
vol -f memory.raw windows.vadyarascan --yara-rules rules.yar
レジストリ分析
# List registry hives
vol -f memory.raw windows.registry.hivelist

# Print registry key
vol -f memory.raw windows.registry.printkey --key "Software\Microsoft\Windows\CurrentVersion\Run"

# Dump registry hive
vol -f memory.raw windows.registry.hivescan --dump
ファイルシステムのアーティファクト
# Scan for file objects
vol -f memory.raw windows.filescan

# Dump files from memory
vol -f memory.raw windows.dumpfiles --pid <PID>

# MFT analysis
vol -f memory.raw windows.mftscan
Linux の分析
# Process listing
vol -f memory.raw linux.pslist

# Process tree
vol -f memory.raw linux.pstree

# Bash history
vol -f memory.raw linux.bash

# Network connections
vol -f memory.raw linux.sockstat

# Loaded kernel modules
vol -f memory.raw linux.lsmod

# Mount points
vol -f memory.raw linux.mount

# Environment variables
vol -f memory.raw linux.envars
macOS の分析
# Process listing
vol -f memory.raw mac.pslist

# Process tree
vol -f memory.raw mac.pstree

# Network connections
vol -f memory.raw mac.netstat

# Kernel extensions
vol -f memory.raw mac.lsmod

分析ワークフロー

マルウェア分析ワークフロー
# 1. Initial process survey
vol -f memory.raw windows.pstree > processes.txt
vol -f memory.raw windows.pslist > pslist.txt

# 2. Network connections
vol -f memory.raw windows.netscan > network.txt

# 3. Detect injection
vol -f memory.raw windows.malfind > malfind.txt

# 4. Analyze suspicious processes
vol -f memory.raw windows.dlllist --pid <PID>
vol -f memory.raw windows.handles --pid <PID>

# 5. Dump suspicious executables
vol -f memory.raw windows.pslist --pid <PID> --dump

# 6. Extract strings from dumps
strings -a pid.<PID>.exe > strings.txt

# 7. YARA scanning
vol -f memory.raw windows.yarascan --yara-rules malware.yar
インシデント対応ワークフロー
# 1. Timeline of events
vol -f memory.raw windows.timeliner > timeline.csv

# 2. User activity
vol -f memory.raw windows.cmdline
vol -f memory.raw windows.consoles

# 3. Persistence mechanisms
vol -f memory.raw windows.registry.printkey \
    --key "Software\Microsoft\Windows\CurrentVersion\Run"

# 4. Services
vol -f memory.raw windows.svcscan

# 5. Scheduled tasks
vol -f memory.raw windows.scheduled_tasks

# 6. Recent files
vol -f memory.raw windows.filescan | grep -i "recent"

データ構造

Windows プロセス構造
// EPROCESS (Executive Process)
typedef struct _EPROCESS {
    KPROCESS Pcb;                    // Kernel process block
    EX_PUSH_LOCK ProcessLock;
    LARGE_INTEGER CreateTime;
    LARGE_INTEGER ExitTime;
    // ...
    LIST_ENTRY ActiveProcessLinks;   // Doubly-linked list
    ULONG_PTR UniqueProcessId;       // PID
    // ...
    PEB* Peb;                        // Process Environment Block
    // ...
} EPROCESS;

// PEB (Process Environment Block)
typedef struct _PEB {
    BOOLEAN InheritedAddressSpace;
    BOOLEAN ReadImageFileExecOptions;
    BOOLEAN BeingDebugged;           // Anti-debug check
    // ...
    PVOID ImageBaseAddress;          // Base address of executable
    PPEB_LDR_DATA Ldr;              // Loader data (DLL list)
    PRTL_USER_PROCESS_PARAMETERS ProcessParameters;
    // ...
} PEB;
VAD(仮想アドレス記述子)
typedef struct _MMVAD {
    MMVAD_SHORT Core;
    union {
        ULONG LongFlags;
        MMVAD_FLAGS VadFlags;
    } u;
    // ...
    PVOID FirstPrototypePte;
    PVOID LastContiguousPte;
    // ...
    PFILE_OBJECT FileObject;
} MMVAD;

// Memory protection flags
#define PAGE_EXECUTE           0x10
#define PAGE_EXECUTE_READ      0x20
#define PAGE_EXECUTE_READWRITE 0x40
#define PAGE_EXECUTE_WRITECOPY 0x80

検出パターン

プロセスインジェクションの兆候
# Malfind indicators
# - PAGE_EXECUTE_READWRITE protection (suspicious)
# - MZ header in non-image VAD region
# - Shellcode patterns at allocation start

# Common injection techniques
# 1. Classic DLL Injection
#    - VirtualAllocEx + WriteProcessMemory + CreateRemoteThread

# 2. Process Hollowing
#    - CreateProcess (SUSPENDED) + NtUnmapViewOfSection + WriteProcessMemory

# 3. APC Injection
#    - QueueUserAPC targeting alertable threads

# 4. Thread Execution Hijacking
#    - SuspendThread + SetThreadContext + ResumeThread
ルートキットの検出
# Compare process lists
vol -f memory.raw windows.pslist > pslist.txt
vol -f memory.raw windows.psscan > psscan.txt
diff pslist.txt psscan.txt  # Hidden processes

# Check for DKOM (Direct Kernel Object Manipulation)
vol -f memory.raw windows.callbacks

# Detect hooked functions
vol -f memory.raw windows.ssdt  # System Service Descriptor Table

# Driver analysis
vol -f memory.raw windows.driverscan
vol -f memory.raw windows.driverirp
認証情報の抽出
# Dump hashes (requires hivelist first)
vol -f memory.raw windows.hashdump

# LSA secrets
vol -f memory.raw windows.lsadump

# Cached domain credentials
vol -f memory.raw windows.cachedump

# Mimikatz-style extraction
# Requires specific plugins/tools

YARA との統合

メモリ用 YARA ルールの作成
rule Suspicious_Injection
{
    meta:
        description = "Detects common injection shellcode"

    strings:
        // Common shellcode patterns
        $mz = { 4D 5A }
        $shellcode1 = { 55 8B EC 83 EC }  // Function prologue
        $api_hash = { 68 ?? ?? ?? ?? 68 ?? ?? ?? ?? E8 }  // Push hash, call

    condition:
        $mz at 0 or any of ($shellcode*)
}

rule Cobalt_Strike_Beacon
{
    meta:
        description = "Detects Cobalt Strike beacon in memory"

    strings:
        $config = { 00 01 00 01 00 02 }
        $sleep = "sleeptime"
        $beacon = "%s (admin)" wide

    condition:
        2 of them
}
メモリのスキャン
# Scan all process memory
vol -f memory.raw windows.yarascan --yara-rules rules.yar

# Scan specific process
vol -f memory.raw windows.yarascan --yara-rules rules.yar --pid 1234

# Scan kernel memory
vol -f memory.raw windows.yarascan --yara-rules rules.yar --kernel

文字列分析

文字列の抽出
# Basic string extraction
strings -a memory.raw > all_strings.txt

# Unicode strings
strings -el memory.raw >> all_strings.txt

# Targeted extraction from process dump
vol -f memory.raw windows.memmap --pid 1234 --dump
strings -a pid.1234.dmp > process_strings.txt

# Pattern matching
grep -E "(https?://|[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})" all_strings.txt
難読化された文字列に対する FLOSS
# FLOSS extracts obfuscated strings
floss malware.exe > floss_output.txt

# From memory dump
floss pid.1234.dmp

ベストプラクティス

取得時のベストプラクティス
  1. 痕跡を最小限に抑える:軽量な取得ツールを使用します
  2. すべてを記録する:取得時刻、ツール、キャプチャのハッシュを記録します
  3. 完全性を検証する:キャプチャ直後にメモリダンプのハッシュを計算します
  4. 証拠保全の連鎖:適切なフォレンジック取り扱いを維持します
分析時のベストプラクティス
  1. 広く調べる:詳細な調査に入る前に、全体像を把握します
  2. 相互参照する:同じデータに複数のプラグインを使用します
  3. タイムラインを照合する:メモリの調査結果をディスクやネットワークの情報と照合します
  4. 調査結果を記録する:詳細なメモとスクリーンショットを残します
  5. 結果を検証する:複数の方法で調査結果を確認します
よくある落とし穴
  • 古いデータ:メモリは揮発性です。速やかに分析してください
  • 不完全なダンプ:ダンプのサイズが想定される RAM と一致することを確認してください
  • シンボルの問題:OS バージョンに合ったシンボルファイルを使用してください
  • スメア:取得中にメモリが変化する場合があります
  • 暗号化:メモリ内の一部のデータは暗号化されている場合があります

絶対遵守事項

  1. メモリを取得したら必ず直ちにダンプのハッシュを計算してください。メモリは揮発性であり、取得後にダンプが改変されていないことを証明する暗号学的な完全性記録がなければ、法廷で異議を申し立てられる可能性があります。
  2. ダンプを生成したライブシステム上では絶対に分析しないでください。分析ツールのアーティファクトを疑わしいシステムに書き込むと、揮発性証拠が汚染され、フォレンジックにおける証拠保全の連鎖が無効になります。
  3. プラグインを実行する前に、OS プロファイルを必ず確認してください。誤ったプロファイルでは、誤りに気づかないまま不正確な結果が出力されます。プラグインの出力を信頼する前に、vol -f memory.raw windows.info で OS バージョンを確認する必要があります。
  4. 発見事項の確認に単一のプラグインを絶対に使用しないでください。pslist では DKOM によって隠されたプロセスを見落とします。プロセスを隠しプロセスとして報告する前に、psscan と pstree を使って相互検証してください。
  5. 元のダンプではなく、必ずフォレンジックコピーを使って作業してください。分析ではすべて、作業ディレクトリに出力ファイルが書き込まれます。元のダンプを使うと、証拠アーティファクトを誤って改変するおそれがあります。

アンチパターン

アンチパターン失敗する理由正しいアプローチ
取得時のハッシュを省略するダンプの完全性を法廷やピアレビューで証明できず、異議申し立てによってすべての調査結果が無効になります解析を始める前に、ただちにハッシュを計算します:sha256sum memory.raw > memory.raw.sha256
OS プロファイルを間違えるオフセットが不正だとエラーなしに出力がでたらめになり、調査結果は有効に見えても捏造されたものになりますまず vol -f memory.raw windows.info を実行し、ほかのプラグインを使う前に OS のバージョンとビルドを確認します
容疑者の稼働中システムで解析するツールのアーティファクトが揮発性証拠を汚染し、ファイルのタイムスタンプが変わり、ライブレスポンスツールが RAM の状態を変更しますダンプを取得して隔離された解析ワークステーションに転送し、コピーのみを解析します
単一のプラグインを信頼するDKOM ルートキットは pslist のリンクリスト走査では隠れますが、psscan のプールスキャンでは検出されます報告前に、少なくとも pslist、psscan、pstree でプロセス一覧を相互検証します
タイムラインとの相関を見落とすメモリのアーティファクトだけでは、ディスクやネットワークのコンテキストがないため、因果関係や攻撃者のタイムラインを確立できませんインシデントレポートを作成する前に、メモリの調査結果をイベントログおよび PCAP と相関させます

メモリプロトコル(必須)

開始前: .claude/context/memory/learnings.md を読みます

完了後:

  • 新しいパターン -> .claude/context/memory/learnings.md
  • 発見した問題 -> .claude/context/memory/issues.md
  • 決定事項 -> .claude/context/memory/decisions.md

中断されることを前提とします:メモリに記録されていなければ、起きていないものとして扱います。

コメント