#include<Windows.h>
int main()
{
const char* dllPath = "./testDll.dll"; //待注入的dll路径
DWORD buffSize = strlen(dllPath) + 1;
DWORD realWrite = 0;
// 1打开目标进程
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, 24136); //最后一个参数是被注入进程的进程号
//2 在目标进程内申请内存空间
char* str = (char*)VirtualAllocEx(hProcess, 0, buffSize, MEM_COMMIT, PAGE_READWRITE);
//3 将dll路径写入到目标进程内存空间
BOOL success = WriteProcessMemory(hProcess, str, dllPath, buffSize, &realWrite);
// 4 创建远程线程
HANDLE hThread = CreateRemoteThread(hProcess, 0, 0, (LPTHREAD_START_ROUTINE)LoadLibraryA, str, 0, 0);
//5 等待线程的执行
WaitForSingleObject(hThread, -1);
VirtualFreeEx(hProcess, str, 0 , MEM_RELEASE);
CloseHandle(hThread);
CloseHandle(hProcess);
return 0;
}
dll远程线程注入
于 2024-01-26 07:29:54 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)