从 Windows 内存转储中提取线程的堆栈

逆向工程 数字取证 调用栈 线 过程
2021-07-05 09:49:41

我有一个运行 Windows Server 2012 R2 的 VM 的内存转储。转储是整个 RAM (4 GB)。

我想从这个转储中提取尽可能多的特征。主要是我想提取机器上运行的所有线程的所有堆栈并存在于内存中。或者,我想提取所有线程的调用序列。

是否有任何工具/教程/书籍等可以帮助我执行此任务?

我熟悉 Volatility 和 Rekall,是否有任何特定的插件可以帮助我实现我的目标?

2个回答

我不确定你在找什么让我试试

我有一个虚拟机的转储文件 MEMORY.dmp 来自运行 xp sp3 的虚拟机,该虚拟机使用 .crash 从附加到它的内核调试器创建

我使用windbg加载它如下

windbg -z memory.dmp 

现在我想我会计算有多少线程正在运行,所以我做了这样的事情

kd> r $t0 = 0; !for_each_thread "r $t0= @$t0+1" ; ? @$t0
Evaluate expression: 306 = 00000132

现在让我看看所有线程的调用堆栈,所以我这样做

kd> !for_each_thread  ".thread @#Thread ; k2"

它吐出来

Implicit thread is now 812915b8
 # ChildEBP RetAddr  
00 fc8d37b4 804dc0f7 nt!KiSwapContext+0x2e
01 fc8d37c0 804e3b7d nt!KiSwapThread+0x46
Implicit thread is now 8128eda8
 # ChildEBP RetAddr  
00 fc8e3d34 804dc0f7 nt!KiSwapContext+0x2e
01 fc8e3d40 804e407e nt!KiSwapThread+0x46
Implicit thread is now 8128eb30
 # ChildEBP RetAddr  
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

好的,而不是 k2 我做 ki 得到一个完整的堆栈跟踪

Implicit thread is now 810efda8
  *** Stack trace for last set context - .thread/.cxr resets it
 # ChildEBP RetAddr  
00 f8ad3c38 804dc0f7 nt!KiSwapContext+0x2e
01 f8ad3c44 804dc143 nt!KiSwapThread+0x46
02 f8ad3c6c bf802f52 nt!KeWaitForSingleObject+0x1c2
03 f8ad3ca8 bf801b2a win32k!xxxSleepThread+0x192
04 f8ad3cec bf819e6c win32k!xxxRealInternalGetMessage+0x418
05 f8ad3d4c 804de7ec win32k!NtUserGetMessage+0x27
06 f8ad3d4c 7c90e4f4 nt!KiFastCallEntry+0xf8
07 0007fe24 7e4191be ntdll!KiFastSystemCallRet
08 0007fe44 0100a740 USER32!NtUserGetMessage+0xc
09 0007fe80 0100c216 wmiprvse!WindowsDispatch+0x31
0a 0007ff14 0100c314 wmiprvse!Process+0x225
0b 0007ff1c 010247aa wmiprvse!WinMain+0x4e
0c 0007ffc0 7c817067 wmiprvse!WinMainCRTStartup+0x174
0d 0007fff0 00000000 kernel32!BaseProcessStart+0x23
Implicit thread is now 8113b960
  *** Stack trace for last set context - .thread/.cxr resets it

XXXXXXXXXXXXXXXX

希望您的查询得到回答,如果没有请解释您所说的调用序列是什么意思

处理 Igor Skochinsky 的评论

如果文件的格式是原始的,比如用 matthieu suiches 捕获,现在已经不存在的 win32dd.exe 可以使用波动性的插件 raw2dmp 并在windbg 中使用生成的与windbg 兼容的dmpfile 如上所述

vol25 -f foo.dmp --profile=Win7SP1x86 图像信息

Volatility Foundation Volatility Framework 2.5
INFO    : volatility.debug    : Determining profile based on KDBG search...
          Suggested Profile(s) : Win7SP0x86, Win7SP1x86
                     AS Layer1 : IA32PagedMemoryPae (Kernel AS)
                     AS Layer2 : FileAddressSpace (E:\vola\foo.dmp)
                      PAE type : PAE
                           DTB : 0x185000L
                          KDBG : 0x82d32c28L
          Number of Processors : 1
     Image Type (Service Pack) : 1
                KPCR for CPU 0 : 0x82d33c00L
             KUSER_SHARED_DATA : 0xffdf0000L
           Image date and time : 2016-06-02 18:08:14 UTC+0000

vol25 -f foo.dmp --profile=Win7SP1x86 raw2dmp --output-image=foowind.dmp

Volatility Foundation Volatility Framework 2.5
Writing data (5.00 MB chunks): |.....

dumpchk.exe foowind.dmp

Loading dump file foowind.dmp

Microsoft (R) Windows Debugger Version 10.0.10586.567 X86
Copyright (c) Microsoft Corporation. All rights reserved.

Loading Dump File [xxx\foowind.dmp]
Kernel Complete Dump File: Full address space is available

Comment: 'File was converted with Volatility'
xxxxxxxxxxxxxxxxxxxxxxx
*** ERROR: Module load completed but symbols could not be loaded for win32dd.exe
Cannot find frame 0x6c, previous scope unchanged
*** ERROR: Module load completed but symbols could not be loaded for win32dd.sys
Probably caused by : win32dd.exe ( win32dd!Unknown )
  • 为每个进程提取完整的内存区域
  • 在每个进程中为进程中的每个线程获取 TIB
  • TIB将帮助您到达每个线程的堆栈内存区域的开始/底部
  • 您可以使用 Rekall 的波动性完成上述所有操作。仔细阅读插件的相关文档(pstree、threads、procdump)
  • 操作系统内部结构也将有所帮助

现在,如果您能详细说明您要查找的内容。我可能会给出更具体的说明。

祝你好运。