前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >如何使用dumpulator模拟内存转储

如何使用dumpulator模拟内存转储

作者头像
FB客服
发布2023-08-08 13:52:56
1960
发布2023-08-08 13:52:56
举报
文章被收录于专栏:FreeBuf

关于dumpulator

dumpulator是一款功能强大且易于使用的代码库,广大研究人员可以使用dumpulator来模拟内存转储,并将该技术用于恶意软件分析和动态代码分析等场景。

工具下载

广大研究人员可以使用下列命令将该项目源码克隆至本地:

代码语言:javascript
复制
git clone https://github.com/mrexodia/dumpulator.git

或者直接访问该项目的Releases页面下载该工具的预编译版本。

除此之外,我们也可以直接通过PyPI安装:

代码语言:javascript
复制
python -m pip install dumpulator

然后执行安装脚本:

代码语言:javascript
复制
python setup.py install

工具使用

调用函数

代码语言:javascript
复制


from dumpulator import Dumpulator



dp = Dumpulator("StringEncryptionFun_x64.dmp")

temp_addr = dp.allocate(256)

dp.call(0x140001000, [temp_addr, 0x140017000])

decrypted = dp.read_str(temp_addr)

print(f"decrypted: '{decrypted}'")

执行跟踪

代码语言:javascript
复制


from dumpulator import Dumpulator



dp = Dumpulator("StringEncryptionFun_x64.dmp", trace=True)

dp.start(dp.regs.rip)

读取UTF-16字符串

代码语言:javascript
复制
from dumpulator import Dumpulator



dp = Dumpulator("my.dmp")

buf = dp.call(0x140001000)

dp.read_str(buf, encoding='utf-16')

自定义syscall实现

我们可以使用@syscall修饰符来实现syscall:

代码语言:javascript
复制
from dumpulator import *

from dumpulator.native import *

from dumpulator.handles import *

from dumpulator.memory import *



@syscall

def ZwQueryVolumeInformationFile(dp: Dumpulator,

                                 FileHandle: HANDLE,

                                 IoStatusBlock: P[IO_STATUS_BLOCK],

                                 FsInformation: PVOID,

                                 Length: ULONG,

                                 FsInformationClass: FSINFOCLASS

                                 ):

return STATUS_NOT_IMPLEMENTED
(向右滑动,查看更多)

所有的syscall函数原型都可以在ntsyscalls.py中找到。

如需给一个现有的syscall实现一个钩子,可以参照下列例子:

代码语言:javascript
复制
import dumpulator.ntsyscalls as ntsyscalls



@syscall

def ZwOpenProcess(dp: Dumpulator,

                  ProcessHandle: Annotated[P[HANDLE], SAL("_Out_")],

                  DesiredAccess: Annotated[ACCESS_MASK, SAL("_In_")],

                  ObjectAttributes: Annotated[P[OBJECT_ATTRIBUTES], SAL("_In_")],

                  ClientId: Annotated[P[CLIENT_ID], SAL("_In_opt_")]

                  ):

    process_id = ClientId.read_ptr()

    assert process_id == dp.parent_process_id

    ProcessHandle.write_ptr(0x1337)

    return STATUS_SUCCESS



@syscall

def ZwQueryInformationProcess(dp: Dumpulator,

                              ProcessHandle: Annotated[HANDLE, SAL("_In_")],

                              ProcessInformationClass: Annotated[PROCESSINFOCLASS, SAL("_In_")],

                              ProcessInformation: Annotated[PVOID, SAL("_Out_writes_bytes_(ProcessInformationLength)")],

                              ProcessInformationLength: Annotated[ULONG, SAL("_In_")],

                              ReturnLength: Annotated[P[ULONG], SAL("_Out_opt_")]

                              ):

    if ProcessInformationClass == PROCESSINFOCLASS.ProcessImageFileNameWin32:

        if ProcessHandle == dp.NtCurrentProcess():

            main_module = dp.modules[dp.modules.main]

            image_path = main_module.path

        elif ProcessHandle == 0x1337:

            image_path = R"C:\Windows\explorer.exe"

        else:

            raise NotImplementedError()

        buffer = UNICODE_STRING.create_buffer(image_path, ProcessInformation)

        assert ProcessInformationLength >= len(buffer)

        if ReturnLength.ptr:

            dp.write_ulong(ReturnLength.ptr, len(buffer))

        ProcessInformation.write(buffer)

        return STATUS_SUCCESS

    return ntsyscalls.ZwQueryInformationProcess(dp,

                                                ProcessHandle,

                                                ProcessInformationClass,

                                                ProcessInformation,

                                                ProcessInformationLength,

                                                ReturnLength

                                                )
(向右滑动,查看更多)

自定义结构体

该工具支持声明你自己的结构体:

代码语言:javascript
复制
from dumpulator.native import *



class PROCESS_BASIC_INFORMATION(Struct):

    ExitStatus: ULONG

    PebBaseAddress: PVOID

    AffinityMask: KAFFINITY

    BasePriority: KPRIORITY

    UniqueProcessId: ULONG_PTR

InheritedFromUniqueProcessId: ULONG_PTR

如需初始化这些结构体,则需要使用到一个Dumpulator实例:

代码语言:javascript
复制
pbi = PROCESS_BASIC_INFORMATION(dp)

assert ProcessInformationLength == Struct.sizeof(pbi)

pbi.ExitStatus = 259  # STILL_ACTIVE

pbi.PebBaseAddress = dp.peb

pbi.AffinityMask = 0xFFFF

pbi.BasePriority = 8

pbi.UniqueProcessId = dp.process_id

pbi.InheritedFromUniqueProcessId = dp.parent_process_id

ProcessInformation.write(bytes(pbi))

if ReturnLength.ptr:

    dp.write_ulong(ReturnLength.ptr, Struct.sizeof(pbi))

return STATUS_SUCCESS
(向右滑动,查看更多)

如果你将一个指针值作为第二个参数传递,那么结构体将会从内存中被读取。

我们可以使用myptr: P[MY_STRUCT]声明指针并使用myptr[0]来引用他们。

收集转储

从2022年10月10日起minidump命令就整合进了x64dbg中,如需创建一个转储,可以暂停工具的执行,并运行下列命令命令。

代码语言:javascript
复制
MiniDump my.dmp

许可证协议

本项目的开发与发布遵循BSL-1.0开源许可证协议。

项目地址

dumpulator:

https://github.com/mrexodia/dumpulator

https://oalabs.openanalysis.net/ https://youtu.be/4Pfu98Xx9Yo https://rioasmara.com/2022/07/23/emulating-malware-with-dumpulator/ https://research.openanalysis.net/emotet/emulation/config/dumpulator/malware/2022/05/19/emotet_x64_emulation.html https://research.checkpoint.com/2022/native-function-and-assembly-code-invocation/ https://research.openanalysis.net/guloader/emulation/dumpulator/veh/exceptions/2023/01/15/dumpulator-veh.html https://research.openanalysis.net/rhadamanthys/config/ida/shifted%20pointers/peb/_list_entry/_ldr_data_table_entry/2023/01/19/rhadamanthys.html https://kienmanowar.wordpress.com/2023/05/22/case-study-decrypt-strings-using-dumpulator/

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2023-07-04,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 FreeBuf 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 工具下载
  • 工具使用
    • 调用函数
      • 执行跟踪
        • 读取UTF-16字符串
          • 自定义syscall实现
            • 自定义结构体
              • 收集转储
              • 许可证协议
              • 项目地址
              相关产品与服务
              腾讯云代码分析
              腾讯云代码分析(内部代号CodeDog)是集众多代码分析工具的云原生、分布式、高性能的代码综合分析跟踪管理平台,其主要功能是持续跟踪分析代码,观测项目代码质量,支撑团队传承代码文化。
              领券
              问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档