// 文件的路径作为参数传递给线程回调函数
#define DLL_PATH L""
int main()
{
//0.正常情况下,我们可以通过遍历进程根据进程名得到进程ID
DWORD dwId = 0;
//1.打开目标进程,得到句柄
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwId);
//2.在目标进程中申请一块空间,能够存放下dll文件的路径
DWORD dwSize = (wcslen(DLL_PATH)+1)*2;
LPVOID lpAddress = VirtualAllocEx(hProcess, NULL, dwSize, MEM_COMMIT, PAGE_READWRITE);
//3.将dll文件的路径写入到目标进程申请的空间中
SIZE_T sSize = 0;
WriteProcessMemory(hProcess, lpAddress, DLL_PATH, dwSize, &sSize);
//4.在目标进程中,创建远程线程使其能够执行LoadLibrary,参数是我们写入的dll路径
HANDLE hThread = CreateRemoteThread(
hProcess,
NULL,
NULL,
(LPTHREAD_START_ROUTINE)LoadLibraryW,
lpAddress,
NULL,
NULL
);
//5.等待线程结束,我们释放空间
WaitForSingleObject(hThread,-1);
VirtualFreeEx(hProcess, lpAddress, dwSize, NULL);
//6.程序结束
CloseHandle(hThread);
CloseHandle(hProcess);
- 关于64位的注入
32位的dll正常情况只能注入到32位程序中,注入程序也应该是32位,64位的dll正常情况只能注入到64位的程序中,注入程序也应该是64位