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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
| #include<stdio.h> #include<Windows.h>
typedef struct _THREAD_PARAM { FARPROC pFunc[2]; char szBuf[4][128]; }THREAD_PARAM,*PTHREAD_PARAM;
typedef HMODULE(WINAPI* PFLOADLIBRARYA) ( LPCSTR lpLibFileName );
typedef FARPROC(WINAPI* PFGETPROCADDRESS) ( HMODULE hModule, LPCSTR lpProcName );
typedef int (WINAPI* PFMESSAGEBOX) ( HWND hWnd, LPCSTR lpText, LPCSTR lpCation, UINT uType );
DWORD WINAPI ThreadProc(LPVOID lParam) { PTHREAD_PARAM pParam = (PTHREAD_PARAM)lParam; HMODULE hMod = NULL; FARPROC pFunc = NULL;
hMod = ((PFLOADLIBRARYA)pParam->pFunc[0])(pParam->szBuf[0]);
pFunc = (FARPROC)((PFGETPROCADDRESS)pParam->pFunc[1])(hMod, pParam->szBuf[1]);
((PFMESSAGEBOX)pFunc)(NULL, pParam->szBuf[2], pParam->szBuf[3], MB_OK); return 0; }
BOOL InjectCode(DWORD dwPID) { HMODULE hMod = NULL; THREAD_PARAM param = { 0, }; HANDLE hProcess = NULL; HANDLE hThread = NULL; LPVOID pRemoteBuf[2] = { 0, }; DWORD dwSize = 0;
hMod = GetModuleHandleA("kernel32.dll"); param.pFunc[0] = GetProcAddress(hMod, "LoadLibraryA"); param.pFunc[1] = GetProcAddress(hMod, "GetProcAddress");
strcpy_s(param.szBuf[0], "user32.dll"); strcpy_s(param.szBuf[1], "MessageBoxA"); strcpy_s(param.szBuf[2], "www.reversecore.com"); strcpy_s(param.szBuf[3], "ReverseCore");
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwPID); dwSize = sizeof(THREAD_PARAM); pRemoteBuf[0] = VirtualAllocEx( hProcess, NULL, dwSize, MEM_COMMIT, PAGE_READWRITE );
WriteProcessMemory( hProcess, pRemoteBuf[0], (LPVOID)¶m, dwSize, NULL );
dwSize = (DWORD)InjectCode - (DWORD)ThreadProc; pRemoteBuf[1] = VirtualAllocEx( hProcess, NULL, dwSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE ); WriteProcessMemory( hProcess, pRemoteBuf[1], (LPVOID)ThreadProc, dwSize, NULL );
hThread = CreateRemoteThread( hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)pRemoteBuf[1], pRemoteBuf[0], 0, NULL ); WaitForSingleObject(hThread,INFINITE); CloseHandle(hThread); CloseHandle(hProcess);
return TRUE; }
int main(int argc, char* argv[]) { DWORD dwPID = 0;
if (argc != 2) { printf("\n USAGE : %ss pid \n", argv[0]); return 1; }
dwPID = (DWORD)atol(argv[1]); InjectCode(dwPID); }
|