名称: 内存取证 描述: 掌握内存取证技术,包括使用Volatility及相关工具进行内存获取、进程分析、工件提取。适用于分析内存转储、调查事件或从RAM捕获中进行恶意软件分析。
内存取证
用于事件响应和恶意软件分析的内存转获取、分析和工件提取的综合技术。
内存获取
实时获取工具
Windows
# WinPmem(推荐)
winpmem_mini_x64.exe memory.raw
# DumpIt
DumpIt.exe
# Belkasoft RAM Capturer
# 基于GUI,输出原始格式
# Magnet RAM Capture
# 基于GUI,输出原始格式
Linux
# LiME(Linux内存提取器)
sudo insmod lime.ko "path=/tmp/memory.lime format=lime"
# /dev/mem(有限,需要权限)
sudo dd if=/dev/mem of=memory.raw bs=1M
# /proc/kcore(ELF格式)
sudo cp /proc/kcore memory.elf
macOS
# osxpmem
sudo ./osxpmem -o memory.raw
# MacQuisition(商业版)
虚拟机内存
# VMware:.vmem文件是原始内存
cp vm.vmem memory.raw
# VirtualBox:使用调试控制台
vboxmanage debugvm "VMName" dumpvmcore --filename memory.elf
# QEMU
virsh dump <domain> memory.raw --memory-only
# Hyper-V
# 检查点包含内存状态
Volatility 3框架
安装与设置
# 安装Volatility 3
pip install volatility3
# 安装符号表(Windows)
# 从 https://downloads.volatilityfoundation.org/volatility3/symbols/ 下载
# 基本用法
vol -f memory.raw <插件>
# 带符号路径
vol -f memory.raw -s /path/to/symbols windows.pslist
基本插件
进程分析
# 列出进程
vol -f memory.raw windows.pslist
# 进程树(父子关系)
vol -f memory.raw windows.pstree
# 隐藏进程检测
vol -f memory.raw windows.psscan
# 进程内存转储
vol -f memory.raw windows.memmap --pid <PID> --dump
# 进程环境变量
vol -f memory.raw windows.envars --pid <PID>
# 命令行参数
vol -f memory.raw windows.cmdline
网络分析
# 网络连接
vol -f memory.raw windows.netscan
# 网络连接状态
vol -f memory.raw windows.netstat
DLL与模块分析
# 每个进程加载的DLL
vol -f memory.raw windows.dlllist --pid <PID>
# 查找隐藏/注入的DLL
vol -f memory.raw windows.ldrmodules
# 内核模块
vol -f memory.raw windows.modules
# 模块转储
vol -f memory.raw windows.moddump --pid <PID>
内存注入检测
# 检测代码注入
vol -f memory.raw windows.malfind
# VAD(虚拟地址描述符)分析
vol -f memory.raw windows.vadinfo --pid <PID>
# 转储可疑内存区域
vol -f memory.raw windows.vadyarascan --yara-rules rules.yar
注册表分析
# 列出注册表蜂巢
vol -f memory.raw windows.registry.hivelist
# 打印注册表键
vol -f memory.raw windows.registry.printkey --key "Software\Microsoft\Windows\CurrentVersion\Run"
# 转储注册表蜂巢
vol -f memory.raw windows.registry.hivescan --dump
文件系统工件
# 扫描文件对象
vol -f memory.raw windows.filescan
# 从内存中转储文件
vol -f memory.raw windows.dumpfiles --pid <PID>
# MFT分析
vol -f memory.raw windows.mftscan
Linux分析
# 进程列表
vol -f memory.raw linux.pslist
# 进程树
vol -f memory.raw linux.pstree
# Bash历史
vol -f memory.raw linux.bash
# 网络连接
vol -f memory.raw linux.sockstat
# 加载的内核模块
vol -f memory.raw linux.lsmod
# 挂载点
vol -f memory.raw linux.mount
# 环境变量
vol -f memory.raw linux.envars
macOS分析
# 进程列表
vol -f memory.raw mac.pslist
# 进程树
vol -f memory.raw mac.pstree
# 网络连接
vol -f memory.raw mac.netstat
# 内核扩展
vol -f memory.raw mac.lsmod
分析工作流
恶意软件分析工作流
# 1. 初始进程调查
vol -f memory.raw windows.pstree > processes.txt
vol -f memory.raw windows.pslist > pslist.txt
# 2. 网络连接
vol -f memory.raw windows.netscan > network.txt
# 3. 检测注入
vol -f memory.raw windows.malfind > malfind.txt
# 4. 分析可疑进程
vol -f memory.raw windows.dlllist --pid <PID>
vol -f memory.raw windows.handles --pid <PID>
# 5. 转储可疑可执行文件
vol -f memory.raw windows.pslist --pid <PID> --dump
# 6. 从转储中提取字符串
strings -a pid.<PID>.exe > strings.txt
# 7. YARA扫描
vol -f memory.raw windows.yarascan --yara-rules malware.yar
事件响应工作流
# 1. 事件时间线
vol -f memory.raw windows.timeliner > timeline.csv
# 2. 用户活动
vol -f memory.raw windows.cmdline
vol -f memory.raw windows.consoles
# 3. 持久化机制
vol -f memory.raw windows.registry.printkey \
--key "Software\Microsoft\Windows\CurrentVersion\Run"
# 4. 服务
vol -f memory.raw windows.svcscan
# 5. 计划任务
vol -f memory.raw windows.scheduled_tasks
# 6. 最近文件
vol -f memory.raw windows.filescan | grep -i "recent"
数据结构
Windows进程结构
// EPROCESS(执行进程)
typedef struct _EPROCESS {
KPROCESS Pcb; // 内核进程块
EX_PUSH_LOCK ProcessLock;
LARGE_INTEGER CreateTime;
LARGE_INTEGER ExitTime;
// ...
LIST_ENTRY ActiveProcessLinks; // 双向链接列表
ULONG_PTR UniqueProcessId; // PID
// ...
PEB* Peb; // 进程环境块
// ...
} EPROCESS;
// PEB(进程环境块)
typedef struct _PEB {
BOOLEAN InheritedAddressSpace;
BOOLEAN ReadImageFileExecOptions;
BOOLEAN BeingDebugged; // 反调试检查
// ...
PVOID ImageBaseAddress; // 可执行文件基地址
PPEB_LDR_DATA Ldr; // 加载器数据(DLL列表)
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;
// 内存保护标志
#define PAGE_EXECUTE 0x10
#define PAGE_EXECUTE_READ 0x20
#define PAGE_EXECUTE_READWRITE 0x40
#define PAGE_EXECUTE_WRITECOPY 0x80
检测模式
进程注入指示器
# Malfind指示器
# - PAGE_EXECUTE_READWRITE保护(可疑)
# - 非映像VAD区域中的MZ头
# - 分配起始处的Shellcode模式
# 常见注入技术
# 1. 经典DLL注入
# - VirtualAllocEx + WriteProcessMemory + CreateRemoteThread
# 2. 进程空洞化
# - CreateProcess(SUSPENDED)+ NtUnmapViewOfSection + WriteProcessMemory
# 3. APC注入
# - QueueUserAPC针对可警报线程
# 4. 线程执行劫持
# - SuspendThread + SetThreadContext + ResumeThread
Rootkit检测
# 比较进程列表
vol -f memory.raw windows.pslist > pslist.txt
vol -f memory.raw windows.psscan > psscan.txt
diff pslist.txt psscan.txt # 隐藏进程
# 检查DKOM(直接内核对象操作)
vol -f memory.raw windows.callbacks
# 检测钩子函数
vol -f memory.raw windows.ssdt # 系统服务描述符表
# 驱动分析
vol -f memory.raw windows.driverscan
vol -f memory.raw windows.driverirp
凭据提取
# 转储哈希(需要先hivelist)
vol -f memory.raw windows.hashdump
# LSA秘密
vol -f memory.raw windows.lsadump
# 缓存的域凭据
vol -f memory.raw windows.cachedump
# Mimikatz风格提取
# 需要特定插件/工具
YARA集成
编写内存YARA规则
rule Suspicious_Injection
{
meta:
description = "检测常见注入Shellcode"
strings:
// 常见Shellcode模式
$mz = { 4D 5A }
$shellcode1 = { 55 8B EC 83 EC } // 函数序言
$api_hash = { 68 ?? ?? ?? ?? 68 ?? ?? ?? ?? E8 } // Push哈希,调用
condition:
$mz at 0 or any of ($shellcode*)
}
rule Cobalt_Strike_Beacon
{
meta:
description = "检测内存中的Cobalt Strike Beacon"
strings:
$config = { 00 01 00 01 00 02 }
$sleep = "sleeptime"
$beacon = "%s (admin)" wide
condition:
2 of them
}
扫描内存
# 扫描所有进程内存
vol -f memory.raw windows.yarascan --yara-rules rules.yar
# 扫描特定进程
vol -f memory.raw windows.yarascan --yara-rules rules.yar --pid 1234
# 扫描内核内存
vol -f memory.raw windows.yarascan --yara-rules rules.yar --kernel
字符串分析
提取字符串
# 基本字符串提取
strings -a memory.raw > all_strings.txt
# Unicode字符串
strings -el memory.raw >> all_strings.txt
# 从进程转储中定向提取
vol -f memory.raw windows.memmap --pid 1234 --dump
strings -a pid.1234.dmp > process_strings.txt
# 模式匹配
grep -E "(https?://|[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})" all_strings.txt
FLOSS用于混淆字符串
# FLOSS提取混淆字符串
floss malware.exe > floss_output.txt
# 从内存转储中
floss pid.1234.dmp
最佳实践
获取最佳实践
- 最小化足迹:使用轻量级获取工具
- 记录一切:记录时间、工具和捕获的哈希值
- 验证完整性:捕获后立即哈希内存转储
- 证据链:保持适当的取证处理
分析最佳实践
- 从广泛开始:深入了解前先获取概览
- 交叉参考:使用多个插件处理相同数据
- 时间线关联:将内存发现与磁盘/网络关联
- 记录发现:保持详细笔记和截图
- 验证结果:通过多种方法验证发现
常见陷阱
- 陈旧数据:内存是易失的,及时分析
- 不完整转储:验证转储大小与预期RAM匹配
- 符号问题:确保OS版本正确的符号文件
- 涂抹:获取期间内存可能变化
- 加密:某些数据可能在内存中加密