C++ Can';t使用loadlibrary(C+;+;)卸载注入的dll
今天我得到了一个LoadLibraryA注入器,它工作得很好,但它不允许在注入后删除dll(loadlibrary的东西),我尝试了FreeLibraryAndExitThread,但它没有工作 我尝试的代码:C++ Can';t使用loadlibrary(C+;+;)卸载注入的dll,c++,dll,loadlibrary,dll-injection,C++,Dll,Loadlibrary,Dll Injection,今天我得到了一个LoadLibraryA注入器,它工作得很好,但它不允许在注入后删除dll(loadlibrary的东西),我尝试了FreeLibraryAndExitThread,但它没有工作 我尝试的代码: freelLibraryAndExitThread(hThread,0) 注入代码: const char* procName = "notepad.exe"; DWORD procID = 0;
freelLibraryAndExitThread(hThread,0)代码>
注入代码:
const char* procName = "notepad.exe";
DWORD procID = 0;
while (!procID)
{
procID = GetProcID(procName);
Sleep(30);
}
HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, 0, procID);
if (hProc && hProc != INVALID_HANDLE_VALUE)
{
void* loc = VirtualAllocEx(hProc, 0, MAX_PATH, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
if (loc)
{
WriteProcessMemory(hProc, loc, dllPath, strlen(dllPath) + 1, 0);
}
HANDLE hThread = CreateRemoteThread(hProc, 0, 0, (LPTHREAD_START_ROUTINE)LoadLibraryA, loc, 0, 0);
if (hThread)
{
CloseHandle(hThread);
}
if (hProc)
{
CloseHandle(hProc);
}
FreeLibraryAndExitThread(hThread, 0);
return 0;
}
顺便说一句,对于愚蠢的问题,我很抱歉,我是cpp的新手,在internet上找不到有效的解决方案。您没有正确卸载DLL
您误用了FreeLibraryAndExitThread()
。它需要卸载加载的DLL的HMODULE
,但您给它的是远程线程的HANDLE
——您事先已经通过CloseHandle()
关闭了它。在任何情况下,freellibraryandexitthread()
都会终止调用线程,在这种情况下,您不希望这样做
您需要等待LoadLibrary()
完全完成。创建远程线程后,使用WaitForSingleObject()
或相关函数等待线程HANDLE
然后,您可以将调用注入远程进程的上下文中,将HMODULE
传递给它,该LoadLibrary()
返回了您当前没有的。将LoadLibrary()
用作线程过程时,线程的退出代码将包含返回的HMODULE
。如果目标是32位进程,则可以使用来检索该HMODULE
。但是如果目标是64位进程,事情会变得更复杂,因为线程的退出代码将截断HMODULE
值
请参见。我不太确定您想要什么,但您不能这样做,因为您关闭了手柄:
if (hThread)
{
CloseHandle(hThread);
}
...
FreeLibraryAndExitThread(hThread, 0);
请做一份报告<应使用hLibModule
(由LoadLibrary
、LoadLibraryEx
、GetModuleHandle
或GetModuleHandleEx
返回)调用code>freelibraryandexithread
。我认为CreateRemoteThread
不会返回兼容的句柄。因此,如果切换到LoadLibrary或LoadLibraryEx,我可以卸载dll?您不能只切换函数CreateRemoteThread
创建线程,LoadLibrary
加载DLL
。我从来没有做过DLL注入,所以我不确定在你的场景中库是从哪里加载的。我的意思是,切换整个注入代码。我不知道。我从来没有注射过。