关于 memory-forensics
面向事件响应、恶意软件分析及授权研究的防御性取证技能,介绍内存转储的采集与分析。内容以 Volatility 3 等工具为基础,检查进程、网络活动、注入代码等痕迹。
主要功能
- 01内存采集指导
- 02Volatility 3 分析流程
- 03进程与网络检查
- 04注入与痕迹分析
- 05基于 YARA 的内存扫描
适用场景
- 01调查事件响应中的内存痕迹
- 02在授权环境中分析恶意软件
- 03关联进程与网络分析结果
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ oimiragieo/ agent-studio --skill memory-forensics安装后在 Claude Code 中输入/memory-forensics确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
commands/memory-forensics.mdhooks/post-execute.cjspre-execute.cjsreferences/research-requirements.mdrules/memory-forensics.mdschemas/input.schema.jsonoutput.schema.jsonscripts/main.cjstemplates/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
Rootkit 检测
# 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
最佳实践
采集最佳实践
- 尽量减少影响:使用轻量级采集工具
- 记录一切:记录采集时间、工具和哈希值
- 验证完整性:采集后立即对内存转储进行哈希计算
- 证据保管链:遵循规范的取证处理流程
分析最佳实践
- 先广泛分析:深入分析前先了解整体情况
- 交叉引用:对同一数据使用多个插件
- 时间线关联:将内存发现与磁盘/网络信息关联起来
- 记录发现:保存详细笔记和屏幕截图
- 验证结果:通过多种方法验证发现
常见陷阱
- 数据过时:内存具有易失性,应及时分析
- 转储不完整:确认转储大小与预期 RAM 容量相符
- 符号问题:确保使用与 OS 版本匹配的符号文件
- 数据变化:采集期间内存可能发生变化
- 加密:内存中的部分数据可能已加密
铁律
- 务必在采集后立即对内存转储进行哈希计算——内存具有易失性;若没有加密完整性记录证明转储在采集后未被修改,法庭上可能会对其提出质疑。
- 切勿在生成转储的实时系统上进行分析——将分析工具的伪影写入嫌疑系统会污染易失性证据,并破坏取证证据保管链。
- 务必在运行插件前验证 OS 配置——错误的配置文件会导致结果悄然出错;在信任任何插件输出前,必须通过
vol -f memory.raw windows.info确认 OS 版本。 - 切勿仅使用一个插件确认发现——
pslist会漏掉通过 DKOM 隐藏的进程;报告任何进程为隐藏进程前,应使用psscan和pstree交叉验证。 - 务必使用取证副本进行分析,绝不使用原始转储——所有分析都会将输出文件写入工作目录;在原始转储上操作可能会意外修改证据。
反模式
| 反模式 | 失败原因 | 正确做法 |
|---|---|---|
| 跳过采集哈希 | 无法在法庭或同行评审中证明转储的完整性;质疑会使所有发现失效 | 立即计算哈希:在任何分析之前运行 sha256sum memory.raw > memory.raw.sha256 |
| OS 配置文件错误 | 错误的偏移量会产生无意义的输出,且不会报错——发现看似有效,实则是伪造的 | 首先运行 vol -f memory.raw windows.info;在使用其他插件前确认 OS 版本和构建版本 |
| 在正在运行的嫌疑系统上分析 | 工具产生的痕迹会污染易失性证据;文件时间戳会改变;实时响应工具会修改 RAM 状态 | 获取转储,将其传输到隔离的分析工作站,只分析副本 |
| 只信任单个插件 | DKOM rootkit 会从 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
假设工作可能中断:如果没有记录在记忆中,就等于没有发生。
评论
支持 Markdown