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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
| #include <stdio.h> #include <Windows.h> #include <tlhelp32.h> #include <tchar.h>
BOOL GetProcessPid(HANDLE *hProcessSnap, DWORD *PID, PROCESSENTRY32* pe32, LPCTSTR* DllPath); BOOL InjectDll(HANDLE hProcess, DWORD PID, LPCTSTR* DllPath);
int main(void) { HANDLE hProcessSnap, hProcess; PROCESSENTRY32 pe32 = { 0 }; DWORD PID; LPCTSTR DllPath = (LPCTSTR) "C:\\hack.dll"; GetProcessPid(&hProcessSnap, &PID, &pe32, &DllPath); InjectDll(hProcess, PID, &DllPath); }
BOOL GetProcessPid(HANDLE *hProcessSnap, DWORD *PID, PROCESSENTRY32* pe32, LPCTSTR* DllPath) { hProcessSnap = (HANDLE *)CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0); if(hProcessSnap == INVALID_HANDLE_VALUE) { _tprintf(_T("CreateToolhelp32Snapshot (of processes)")); return(FALSE); }
pe32->dwSize = sizeof(PROCESSENTRY32);
if (Process32First(hProcessSnap, pe32)) { do { if (!_tcsicmp(pe32->szExeFile, _T("지뢰찾기.exe"))) { *PID = pe32->th32ProcessID; _tprintf(_T("[*] Process Name : %s\n"), pe32->szExeFile); _tprintf(_T("[*] PID is : %u\n\n"), *PID); break; } } while(Process32Next(hProcessSnap, pe32)); CloseHandle(hProcessSnap); } else { _tprintf(_T("Process32First error! Error Code is : %d\n"), GetLastError()); CloseHandle(hProcessSnap); return(FALSE); }
}
BOOL InjectDll(HANDLE hProcess, DWORD PID, LPCTSTR * DllPath) { HANDLE hThread; LPVOID pRemoteBuf; HMODULE hMod = 0; LPTHREAD_START_ROUTINE pThreadProc;
if(!(hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, PID))) { _tprintf(_T("OpenProcess(%d) failed!!! [%d]\n"), PID, GetLastError()); return FALSE; }
if (!(pRemoteBuf = VirtualAllocEx(hProcess, NULL, lstrlen(*DllPath) + 1, MEM_COMMIT, PAGE_READWRITE))) _tprintf(_T("VirtualAllocEx() Failed!!\n")); _tprintf(_T("-> Virtual Memory is : %x\n"), (unsigned int)pRemoteBuf);
if (!(WriteProcessMemory(hProcess, pRemoteBuf, (LPVOID)*DllPath, lstrlen(*DllPath)+1, NULL))) _tprintf(_T("WriteProcessMemory() failed!!\n"));
if (!(hMod = GetModuleHandle(_T("Kernel32.dll")))) _tprintf(_T("GetModuleHandle() Failed!!, Error Code is : %d\n"), GetLastError()); _tprintf(_T("-> KERNEL.dll memory is : %x\n"), (unsigned int)hMod);
if(!(pThreadProc = (LPTHREAD_START_ROUTINE)GetProcAddress(hMod, "LoadLibraryA"))) _tprintf(_T("GetProcAddress() Failed!!, Error Code is : %d\n"), GetLastError()); _tprintf(_T("-> KERNEL32.LoadLibraryW : % x\n"), pThreadProc);
if (!(hThread = CreateRemoteThread(hProcess, NULL, 0, pThreadProc, pRemoteBuf, 0, NULL))) _tprintf(_T("CreateRemoteThread() Failed!!, Error Code is : %d\n"), GetLastError()); WaitForSingleObject(hThread, INFINITE);
_tprintf(_T("-> Thread Handle is : %x\n\n"), hThread); }
|