gpt4 book ai didi

c++ - 从 x64 注入(inject)器注入(inject)带有 x86 dll 的 x86 目标

转载 作者:可可西里 更新时间:2023-11-01 11:28:00 28 4
gpt4 key购买 nike

我在做标题所说的事情时遇到了一些麻烦...我制作了一个适用于 x86 到 x86 和 x64 到 x64 的注入(inject)器,但是从 x64(带有 x86 dll)注入(inject) x86 并没有使用该代码:

#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(即使是从 64 位注入(inject)器注入(inject) 32 位进程),但它无法真正注入(inject) dll。

顺便说一句,在我的研究过程中,我发现了这些问题:

x86 Code Injection into an x86 Process from a x64 Process

C++: Injecting 32 bit targets from 64 bit process

但是虽然答案解释了如何操作,但我并没有真正做到...所以也许我需要的只是一个代码片段以正确的方式发送给我?

最佳答案

改变这一行:

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;
}

有效!这有点像 hack,但它确实有效。

关于c++ - 从 x64 注入(inject)器注入(inject)带有 x86 dll 的 x86 目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29652839/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com