在过去,我们使用CreateRemoteThread并将LoadLibraryA用作lpStartAddress的地址(该地址在所有进程中都相同).诀窍是使用VirtualAllocEx分配要注入的DLL名称,并将其用作lpParameter.实际上,您的线程使用您要注入的DLL名称调用LoadLibraryA.加载Dll时,将调用Dllmain,并且可以在附加dll的时间内在Dllmain中运行代码(DLL_PROCESS_ATTACH).
link在执行此操作时具有一些非常好的信息.但是,此技术依赖于Dllmain函数.如果可以使用Dllmain,则此机制可能会起作用.该文章的步骤摘要提供了一个概述:
现在,我们可以通过以下步骤总结该技术:
Retrieve a HANDLE to the remote process (OpenProces).
Allocate memory in the remote process's address space for injected data (VirtualAllocEx).
Write a copy of the initialised INJDATA structure to the allocated memory (WriteProcessMemory).
Allocate memory in the remote process's address space for injected code.
Write a copy of ThreadFunc to the allocated memory.
Start the remote copy of ThreadFunc via CreateRemoteThread.
Wait until the remote thread terminates (WaitForSingleObject).
Retrieve the result from the remote process (ReadProcessMemory or GetExitCodeThread).
Free the memory allocated in Steps #2 and #4 (VirtualFreeEx).
Close the handles retrieved in Steps #6 and #1 (CloseHandle).
我看到您对过多信息的评论.不确定我是否完全理解.但是Dllmain有一些限制,例如不能使用大多数Win32 API调用.有一些例外,一种是CreateThread.您是否考虑过拆线工作?如果在Dllmain中使用CreateThread,则它会被有效阻止,直到Dllmain退出.因此,一旦Dllmain返回,线程将执行.