【发布时间】:2016-05-04 12:03:13
【问题描述】:
我在看 ZeuS 恶意软件,我遇到了这个source code:
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
}
逻辑如下:
- 读取
fs段寄存器(32位Windows在那里存储TEB) - 获取指向
PEB的指针 - 获取指向
PEB_LDR_DATA的指针(包含有关进程已加载模块的信息) - 遍历
InMemoryOrder列表 - 使用自定义自制哈希函数将模块名称与
"kernel32.dll"进行比较
为什么这里不适合使用GetModuleHandle?
【问题讨论】:
-
恶意软件通常以难以从 Windows DLL 链接到外部函数的方式注入进程。可以编写这样的代码以避免必须链接到外部函数。
-
@DavidHeffernan 另一方面,依靠如此繁琐的代码可能会因为重要进程的崩溃而发现恶意软件。他的“哈希”功能不是很好,如果进程加载了很多(小)库,那么就会有很高的冲突风险。
-
无论如何,这个问题可能是基于意见的,应该关闭,尤其是当你似乎想把它变成讨论时。
-
IInspectable 在你接受的答案中和我说的一样......
-
链接 Windows DLL 对我来说似乎很清楚。
标签: c++ windows winapi assembly malware