c++ - 如何将 DLL 注入任何进程?
问题描述
我正在努力将 dll 注入 Windows 上的任何进程。我已经有一个适用于我自己的程序的代码,比如 hello world 或类似的东西,但其他程序,比如 notepad 、 calc、 chrome 等。
程序可以防止dll的注入,所以我不知道我能做些什么来绕过这个。
我的最终目标是挂钩任何程序的 api 调用。
这个域对我来说是新的,所以我是这里的初学者,如果你有任何关于它的资源或解决方案!
注射器.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;
}
我的dll
#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;
}
我目前使用的是来自 Unix 操作系统的 Windows 10 x64,所以 Windows 对我来说很新!
谢谢你的时间 !
解决方案
对于 99% 的注入方法,您必须能够将代码写入目标进程。为此,您需要能够使用具有所需权限的OpenProcess () 打开进程句柄。
如果您尝试注入的进程是具有内核模式反作弊的游戏,它将通过ObjRegisterCallbacks阻止您。您还需要处于内核模式才能绕过此保护,除非他们有一些您可以在用户模式下滥用的白名单系统。
如果您尝试注入的进程作为 SYSTEM 或 Protected Process Light 进程运行,那么您在那里也遇到了麻烦。在我之前的回答中获得更多信息
在您的评论中,您说您的目标是挂钩 API,为了回答您问题的这一部分,我会向您推荐这个答案,我会在其中解释它
推荐阅读
- azure-functions - Azure函数将多个数据插入表存储
- reactjs - 使用“useState”钩子时,有什么方法可以使用 React DevTools 在 React 多状态中查看“字段”的名称
- java - Spring Data JPA 上的条件查询在 DB2 (z/OS) 上给出 -417 错误
- wpf - 触发键盘快捷键( Ctrl+F7 )时如何触发事件?
- django - django中用PrimaryKeyRelatedField表示json数据
- javascript - geolocation.getCurrentPosition 在 iOS 上不准确
- shell - zsh 颜色仅在终端中直接使用命令时才有效
- javascript - 使用继承的未知属性
- python - 使用 Selenium 刮取无限滚动问题
- php - 使用 updateOrInsert() 方法批量插入/更新并将数组转换为字符串