1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| #include <debugapi.h> #include <handleapi.h> #include <libloaderapi.h> #include <memoryapi.h> #include <minwindef.h> #include <processthreadsapi.h> #include <string.h> #include <windows.h> #include <stdio.h> #include <winnt.h>
BOOL LoadDll(DWORD dwProcessID,char *szDllPathName){ BOOL bRet; HANDLE hProcess; HANDLE hThread; DWORD dwLength; FARPROC dwLoadAddr; LPVOID lpAllocAddr; HMODULE hModule;
bRet = FALSE; dwLoadAddr = 0; hProcess = 0;
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE,dwProcessID); if (hProcess == NULL) { OutputDebugStringA("OpenProcess Error! \n"); return FALSE; } dwLength = strlen(szDllPathName) + 1;
lpAllocAddr = VirtualAllocEx(hProcess, NULL, dwLength, MEM_COMMIT,PAGE_READWRITE);
if (lpAllocAddr == NULL) { OutputDebugStringA("VirtualAllocEx Error! \n"); CloseHandle(hProcess); return FALSE; } bRet = WriteProcessMemory(hProcess, lpAllocAddr, szDllPathName,dwLength,NULL); if (!bRet) { OutputDebugStringA("WriteProcessMemory Error! \n"); CloseHandle(hProcess); return FALSE; }
hModule = GetModuleHandleA("Kernel32.dll"); if (hModule == NULL) { OutputDebugStringA("GetModuleHandleA Error! \n"); CloseHandle(hProcess); return FALSE; } dwLoadAddr = GetProcAddress(hModule, "LoadLibraryA"); if (dwLoadAddr == NULL) { OutputDebugStringA("GetProcAddress Error! \n"); CloseHandle(hProcess); CloseHandle(hModule); return FALSE; } hThread = CreateRemoteThread(hProcess, NULL, 0,(LPTHREAD_START_ROUTINE)dwLoadAddr,lpAllocAddr,0,NULL); if (hThread == NULL) { OutputDebugStringA("CreateRemoteThread Error! \n"); CloseHandle(hProcess); CloseHandle(hModule); return FALSE; }
CloseHandle(hProcess); CloseHandle(hThread);
return TRUE; }
int main(int argc, char *argv[]) { LoadDll(111, ""); return 0; }
|