我正在研究如何将 dll 注入(inject)到 Windows 上的任何进程中。 我已经有一个适用于我自己的程序的代码,比如 hello world 或类似的东西,但其他程序,如记事本、calc、chrome 等。
程序可以防止dll的注入(inject),所以我不知道我能做些什么来绕过这个。
我的最终目标是 Hook 任何程序的 api 调用。
这个域对我来说是新的,所以我是这里的初学者,如果您有任何资源或解决方案!
注入(inject)器.cpp
#include <iostream>
#include <Windows.h>
int main()
{
// path to our dll
LPCSTR DllPath = "D:\\projects\\standardinjection\\release\\testlib.dll";
INT process_id = 14367;
// Open a handle to target process
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, process_id);
// Allocate memory for the dllpath in the target process
// length of the path string + null terminator
LPVOID pDllPath = VirtualAllocEx(hProcess, 0, strlen(DllPath) + 1,
MEM_COMMIT, PAGE_READWRITE);
// Write the path to the address of the memory we just allocated
// in the target process
WriteProcessMemory(hProcess, pDllPath, (LPVOID)DllPath,
strlen(DllPath) + 1, 0);
// Create a Remote Thread in the target process which
// calls LoadLibraryA as our dllpath as an argument -> program loads our dll
HANDLE hLoadThread = CreateRemoteThread(hProcess, 0, 0,
(LPTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandleA("Kernel32.dll"),
"LoadLibraryA"), pDllPath, 0, 0);
// Wait for the execution of our loader thread to finish
WaitForSingleObject(hLoadThread, INFINITE);
std::cout << "Dll path allocated at: " << std::hex << pDllPath << std::endl;
std::cin.get();
// Free the memory allocated for our dll path
VirtualFreeEx(hProcess, pDllPath, strlen(DllPath) + 1, MEM_RELEASE);
return 0;
}
我的动态链接库
#include <Windows.h>
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
if (ul_reason_for_call == DLL_PROCESS_ATTACH)
MessageBox(0, L"Hello From testlib!", L"Hello", MB_ICONINFORMATION);
return TRUE;
}
我目前使用的是 Windows 10 x64 来自 Unix 操作系统,所以 Windows 对我来说是全新的!
感谢您的宝贵时间!
最佳答案
对于 99% 的注入(inject)方法,您必须能够将代码写入目标进程。为此,您需要能够使用 OpenProcess 打开进程句柄。 () 与所需的 privileges .
如果您尝试注入(inject)的进程是一个具有内核模式反作弊功能的游戏,它将通过ObjRegisterCallbacks 阻止您。 .您还需要处于内核模式才能绕过此保护,除非他们有一些您可以在用户模式下滥用的白名单系统。
如果您尝试注入(inject)的进程正在作为 SYSTEM 或 Protected Process Light 进程运行,那么您也有麻烦了。更多信息在我的previous answer
在您的评论中,您说您的目标是 Hook API,要回答您问题的这一部分,我建议您参阅 this answer我在哪里解释
关于c++ - 如何将 DLL 注入(inject)任何进程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58366312/