Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 编写自定义GetModuleHandle函数的原因是什么?_C++_Windows_Winapi_Assembly_Malware - Fatal编程技术网

C++ 编写自定义GetModuleHandle函数的原因是什么?

C++ 编写自定义GetModuleHandle函数的原因是什么?,c++,windows,winapi,assembly,malware,C++,Windows,Winapi,Assembly,Malware,我在看宙斯的恶意软件,我遇到了这件事: 逻辑如下: 读取fs段寄存器32位Windows存储TEB 获取指向PEB的指针 获取指向PEB_LDR_数据的指针,该数据包含有关进程加载模块的信息 遍历InMemoryOrder列表 使用自定义自制哈希函数将模块名与kernel32.dll进行比较 为什么GetModuleHandle的使用不合适呢?代码段试图获取模块句柄,即kernel32.dll的基址,可能是因为它还没有这个模块的句柄。从kernel32.dll导出。如果不知道函数的地址,则无法调

我在看宙斯的恶意软件,我遇到了这件事:

逻辑如下:

读取fs段寄存器32位Windows存储TEB 获取指向PEB的指针 获取指向PEB_LDR_数据的指针,该数据包含有关进程加载模块的信息 遍历InMemoryOrder列表 使用自定义自制哈希函数将模块名与kernel32.dll进行比较
为什么GetModuleHandle的使用不合适呢?

代码段试图获取模块句柄,即kernel32.dll的基址,可能是因为它还没有这个模块的句柄。从kernel32.dll导出。如果不知道函数的地址,则无法调用该函数。

代码段试图获取模块句柄,即kernel32.dll的基址,可能是因为它还没有此模块的句柄。从kernel32.dll导出。如果不知道函数的地址,则无法调用该函数。

通常会将恶意软件注入到进程中,从而很难从Windows DLL链接到外部函数。这样的代码可能是为了避免链接到外部函数而编写的。@DavidHeffernan另一方面,由于重要进程的崩溃,依赖这样繁琐的代码可能会发现恶意软件。他的散列函数不是很好,如果进程加载了很多小库,那么冲突的风险很高。无论如何,这个问题可能是基于观点的,应该关闭,特别是当你似乎想把它交给讨论时。IInspectable在你接受的答案中说的和我一样……链接Windows DLL对我来说似乎很清楚。通常,恶意软件以一种难以从Windows DLL链接到外部功能的方式注入进程。这样的代码可能是为了避免链接到外部函数而编写的。@DavidHeffernan另一方面,由于重要进程的崩溃,依赖这样繁琐的代码可能会发现恶意软件。他的散列函数不是很好,如果进程加载了很多小库,那么冲突的风险很高。无论如何,这个问题可能是基于观点的,应该关闭,特别是当你似乎想把它交给讨论时。IInspectable在你接受的答案中说的和我一样……链接Windows DLL对我来说似乎很清楚。
HMODULE _getKernel32Handle(void)
{
#if defined _WIN64
  return NULL; //FIXME
#else  
  __asm
  {
    cld                    //clear the direction flag for the loop

    mov edx, fs:[0x30]     //get a pointer to the PEB
    mov edx, [edx + 0x0C]  //get PEB-> Ldr
    mov edx, [edx + 0x14]  //get the first module from the InMemoryOrder module list

  next_mod:
    mov esi, [edx + 0x28]  //get pointer to modules name (unicode string)
    mov ecx, 24            //the length we want to check
    xor edi, edi           //clear edi which will store the hash of the module name

  loop_modname:
    xor eax, eax           //clear eax
    lodsb                  //read in the next byte of the name
    cmp al, 'a'            //some versions of Windows use lower case module names
    jl not_lowercase
    sub al, 0x20           //if so normalise to uppercase

  not_lowercase:
    ror edi, 13            //rotate right our hash value
    add edi, eax           //add the next byte of the name to the hash
    loop loop_modname      //loop until we have read enough

    cmp edi, 0x6A4ABC5B    //compare the hash with that of KERNEL32.DLL
    mov eax, [edx + 0x10]  //get this modules base address
    mov edx, [edx]         //get the next module
    jne next_mod           //if it doesn't match, process the next module
  };
#endif
}