无论我在哪里查看通过CreateRemoteThread进行注入(inject)的方法都是相同的,但是获取进程ID的方法并不相同。我的函数将返回正确的进程ID,对此我不感兴趣,因此我将作废该部分除外,仅包括实际注入(inject)。
我只是在学习DLL注入(inject),并尝试在notepad.exe上。如果注入(inject)有效,则记事本的标题将从“无标题-记事本”更改为“已挂钩”。
#define DLL_NAME "injectme.dll"
.....
BOOL InjectRemoteThread(DWORD ProcessID)
{
HANDLE RemoteProc;
char buf[50] = {0};
LPVOID MemAlloc;
LPVOID LoadLibAddress;
// Process ID does show correctly!
WCHAR id[100];
StringCbPrintf(id, 100, L"%d", ProcessID); // id contains the process ID... is confirmed in comparing ID shown in tasklist and the messagebox.
MessageBox(NULL, id, L"Process ID", MB_ICONINFORMATION);
// Process ID does show correctly!
if ( !ProcessID )
{
MessageBox(NULL, (LPCWSTR)GetLastError(), L"An error occured", NULL);
return 0;
}
RemoteProc = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, ProcessID);
if ( !RemoteProc )
{
MessageBox(NULL, (LPCWSTR)GetLastError(), L"An error occured", NULL);
return 0;
}
LoadLibAddress = (LPVOID)GetProcAddress(GetModuleHandleA("kernel32.dll"), "LoadLibraryA");
MemAlloc = (LPVOID)VirtualAllocEx(RemoteProc, NULL, strlen(DLL_NAME)+1, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
WriteProcessMemory(RemoteProc, (LPVOID)MemAlloc, DLL_NAME, strlen(DLL_NAME)+1, NULL);
CreateRemoteThread(RemoteProc, NULL, NULL, (LPTHREAD_START_ROUTINE)LoadLibAddress, (LPVOID)MemAlloc, NULL, NULL);
CloseHandle(RemoteProc);
VirtualFreeEx(RemoteProc, (LPVOID)MemAlloc, 0, MEM_RELEASE | MEM_DECOMMIT);
return 1;
}
DLL可以使用他人的注入(inject)器,但我不明白为什么...
实际上,它与注入(inject)器位于同一目录中。
最佳答案
我发现了问题...我感到很愚蠢。
任何有类似问题的人:使用绝对路径,而不要使用相对路径。
我变了
#define DLL_NAME "injectme.dll"
到
#define DLL_NAME "C:\\Users\\Raikazu\\Documents\\Visual Studio 2012\\Projects\\Hooking\\Release\\injectme.dll"
关于c++ - C++-CreateRemoteThread DLL注入(inject)[Windows 7],我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14096215/