我正在做一些标题所说的麻烦......我制作了一个可以使用x86到x86和x64到x64的注入器,但从x64(带有x86 dll)注入x86并没有#39;使用该代码:
#include <Windows.h>
#include <string>
bool InjectDll(DWORD processId, std::string dllPath)
{
HANDLE hThread, hProcess;
void* pLibRemote = 0; // the address (in the remote process) where
// szLibPath will be copied to;
HMODULE hKernel32 = GetModuleHandle("Kernel32");
char DllFullPathName[_MAX_PATH];
GetFullPathName(dllPath.c_str(), _MAX_PATH, DllFullPathName, NULL);
// Get process handle
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);
// copy file path in szLibPath
char szLibPath[_MAX_PATH];
strcpy_s(szLibPath, DllFullPathName);
// 1. Allocate memory in the remote process for szLibPath
pLibRemote = VirtualAllocEx(hProcess, NULL, sizeof(szLibPath),
MEM_COMMIT, PAGE_READWRITE);
if (pLibRemote == NULL)
return false;
// 2. Write szLibPath to the allocated memory
WriteProcessMemory(hProcess, pLibRemote, (void*)szLibPath,
sizeof(szLibPath), NULL);
// 3. Force remote process to load dll
LPTHREAD_START_ROUTINE thread;
thread = (LPTHREAD_START_ROUTINE)GetProcAddress(hKernel32,"LoadLibraryA");
hThread = CreateRemoteThread(hProcess, NULL, 0, thread, pLibRemote,
0, NULL);
if (hThread == NULL)
return false;
return true;
}
该函数在每个场景中都返回true(即使是注入32位进程的64位注入器),但它实际上无法注入dll。
顺便说一句,在我的研究过程中,我发现了这些问题:
x86 Code Injection into an x86 Process from a x64 Process
C++: Injecting 32 bit targets from 64 bit process
但是虽然答案解释了如何,但我没有设法实际做到这一点......所以我需要的只是一个代码片段以正确的方式发送给我?
答案 0 :(得分:3)
更改此行:
thread = (LPTHREAD_START_ROUTINE)GetProcAddress(hKernel32,"LoadLibraryA");
这一行:
thread = (LPTHREAD_START_ROUTINE)system("loadLibrary_x86_address.exe");
“loadLibrary_x86_address.exe”是32位应用,定义为:
#include <Windows.h>
int main()
{
return (int)LoadLibraryA;
}
作品!这是一种黑客行为,但它确实起到了作用。