内存取证
RAM 内存取证分析是数字调查中一门关键且专业的学科, 专注于提取和分析仅在系统运行时存在的易失性数据。与检查存储在硬盘或 SSD 上 的持久数据的传统磁盘取证不同,内存取证捕获 采集时刻系统的精确状态,揭示正在运行的进程、活动的网络 连接、内存中的凭据、加密密钥、无文件恶意软件以及 老练的攻击者为逃避检测而故意仅留在 RAM 中的证物。该 技术在调查高级威胁 (APT)、现代勒索软件 以及使用 living-off-the-land 技术的攻击中已变得不可或缺,在这些攻击中,入侵者 仅在内存中使用操作系统的合法工具进行操作。采集的时间 窗口至关重要:一旦系统被关闭、重启或进入 休眠模式,这些易失性证物便会不可挽回地丢失,因而 采集的速度与方法成为取证调查成功与否的决定性因素。
为何进行内存取证
易失性证物在关机时丢失。内存包含:
- 正在运行的进程: 无文件恶意软件、代码注入
- 网络连接: C2 active connections、打开的 sockets
- 凭据: 明文密码、缓存的 NTLM 哈希
- 加密: 内存中的加密密钥
- Registry hives: 未持久化的修改
- Handles 和 DLL: 注入、hooking、rootkits
内存采集
采集工具
- FTK Imager: AccessData 的免费工具,图形界面
- DumpIt: 单行命令的便携式可执行文件,快速
- WinPmem: Open-source,支持 kernel memory 采集
- Magnet RAM Capture: Free tool,易于使用
- LiME (Linux): 适用于 Linux systems 的 Loadable Kernel Module
- Belkasoft RAM Capturer: 即使在 anti-dumping 下也能工作
采集注意事项
- 在调查之前采集内存——分析会改变状态
- 在线系统:使用最小化 footprint 的工具
- 虚拟系统:对 VM 进行 snapshot 或提取 .vmem
- 物理系统:考虑通过 FireWire/Thunderbolt DMA 进行采集
- 记录采集的精确时间以用于 timeline
使用 Volatility 进行分析
Volatility Framework 是内存分析的 open-source 黄金标准工具, 支持 Windows、Linux、macOS 及多种 dump 格式。
基本命令
# Identify the system profile
vol.py -f memory.dmp imageinfo
# List processes
vol.py -f memory.dmp --profile=Win10x64 pslist
vol.py -f memory.dmp --profile=Win10x64 pstree
# Hidden processes (DKOM)
vol.py -f memory.dmp --profile=Win10x64 psxview
# Network connections
vol.py -f memory.dmp --profile=Win10x64 netscan
# Loaded DLLs
vol.py -f memory.dmp --profile=Win10x64 dlllist -p <PID>
# Process command line
vol.py -f memory.dmp --profile=Win10x64 cmdline
# Process dumps
vol.py -f memory.dmp --profile=Win10x64 procdump -p <PID> -D output/
# Credential extraction
vol.py -f memory.dmp --profile=Win10x64 hashdump
vol.py -f memory.dmp --profile=Win10x64 lsadump
无文件恶意软件分析
无文件恶意软件仅驻留在内存中,使用合法工具(PowerShell、 WMI)来逃避 AV。检测技术:
- Process injection: 查找 RWX 内存、remote threads
- PowerShell 分析: console history 中的可疑命令
- Hollowing: 代码被替换的合法进程
- Reflective DLL Injection: 未在磁盘上映射的 DLL
示例:检测 Process Injection
# Look for suspicious VADs (RWX memory)
vol.py -f memory.dmp --profile=Win10x64 malfind
# List code injections
vol.py -f memory.dmp --profile=Win10x64 hollowfind
# Analyze suspicious handles
vol.py -f memory.dmp --profile=Win10x64 handles -p <PID> -t Process,Thread
凭据提取
内存中经常包含明文或易于破解的凭据:
- LSASS dump: NT hashes、Kerberos tickets、明文密码
- Registry hives: 用于 offline hashdump 的 SAM、SYSTEM
- Browser memory: 表单密码、会话 cookies
- 应用专属: 应用的凭据(email、VPN 等)
Timeline 重建
将内存事件与其他证物进行关联:
# Timeline of processes and connections
vol.py -f memory.dmp --profile=Win10x64 timeliner --output=body --output-file=timeline.body
# Convert to a readable format
mactime -b timeline.body -d > timeline.csv
Rootkits 与 DKOM
Direct Kernel Object Manipulation (DKOM) 通过修改 kernel structures 来隐藏进程。 通过比较多个来源进行检测:
- psxview: 比较 pslist、psscan、thrdproc 等
- driverirp: 列出 drivers 及其 IRP hooks
- ssdt: System Service Descriptor Table hooks
- idt: Interrupt Descriptor Table modifications
高级 Volatility 插件
- yarascan: 使用 YARA 规则扫描内存
- strings: 从特定进程提取 strings
- clipboard: Windows 剪贴板内容
- notepad: 打开的 Notepad 窗口中的文本
- mftparser: 从内存恢复 $MFT
- svcscan: 列出 Windows services
辅助工具
- Rekall: 具有附加 features 的 Volatility fork
- Redline: FireEye 用于分析的图形界面
- MemProcFS: 将 memory dump 挂载为 filesystem
- Bulk Extractor: 批量提取 features
挑战
- 大型 dumps(16GB+ RAM)分析缓慢
- anti-forensics 技术可能损坏 dumps
- Encrypted memory 需要 keys 才能分析
- kernel 结构在不同 OS versions 之间会发生变化
最终建议
内存取证对于调查高级攻击和无文件恶意软件至关重要。 通过 EDR 在可疑事件中自动执行内存采集。使用公开的 memory dumps(DFIRScience、Volatility Foundation)练习分析。务必将 内存发现与 disk forensics 和 network forensics 进行关联,以全面了解事件。
