【发布时间】:2022-01-06 19:38:00
【问题描述】:
我使用的代码是:
if(hwndMSWP && hProc && hProc != INVALID_HANDLE_VALUE && filePath.size() > 20) {
QByteArray const path = filePath.toLocal8Bit(); // < filePath definitely has the right path with backslashes
LPVOID const allocMemAddr = VirtualAllocEx(hProc, 0, MAX_PATH, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
if(!allocMemAddr) {
MessageBoxA(0, "ERROR: Couldn't allocate memory!", "Injection Error", 0);
return;
}
if(!WriteProcessMemory(hProc, allocMemAddr, (LPVOID)path.constData(), path.size(), 0)) {
MessageBoxA(0, "ERROR: Couldn't write memory!", "Injection Error", 0);
clean(allocMemAddr);
return;
}
FARPROC libraryAddress = GetProcAddress(GetModuleHandle(L"kernel32"), "LoadLibraryA");
if(!libraryAddress) {
MessageBoxA(0, "ERROR: Couldn't get kernel32 export function address!", "Injection Error", 0);
clean(allocMemAddr);
return;
}
DWORD dwThreadId;
HANDLE hRemoteThread = CreateRemoteThread(hProc, 0, 0, (LPTHREAD_START_ROUTINE)libraryAddress, allocMemAddr, 0, &dwThreadId);
if(!hRemoteThread || hRemoteThread == INVALID_HANDLE_VALUE) {
dwThreadId = 0;
clean(allocMemAddr);
MessageBoxA(0, "ERROR: Couldn't create remote thread!", "Injection Error", 0);
return;
}
WaitForSingleObject(hRemoteThread, INFINITE);
CloseHandle(hRemoteThread);
clean(allocMemAddr);
MessageBoxA(0, "Injected successfully!", "Injection Successfull", 0);
}
一切都已定义并正确设置。我还使用 x64dbg 进行了调试。它显示正在创建一个新线程。但我还在 LoadLibraryA 处设置了一个断点,它不会被命中。
在过去的一个小时里,我一直在处理这个单一的错误,我希望你对此有不同的看法。
【问题讨论】:
-
不是根本问题,但您应该分配
path.size()+1字节,然后将path.size()+1字节写入远程进程。如果path.size()正好是MAX_PATH,则写入远程进程的字符串不会以空值结尾。如果path.size()大于MAX_PATH,就会出现缓冲区溢出。 -
你说你用的是x64dbg,是不是说目标进程是64位的?你的注射器是 32 位还是 64 位进程?在目标进程中检索
LoadLibraryA()函数的适当地址时会有很大的不同。 -
我使用了 x32dbg,这个 dll 是一个 32 位的 dll,并且使用其他程序注入也可以。目标进程也是32位