Ver Mensaje Individual
  #3  
Antiguo 10-01-2017
angelp4492 angelp4492 is offline
Miembro
 
Registrado: dic 2007
Posts: 99
Reputación: 0
angelp4492 cantidad desconocida en este momento
Gracias escafandra, lo pruebo en cuanto llegue a casa. Precisamente estoy siguiendo un tutorial tuyo sobre Api_hook espectacular por cierto.

la técnica que utizo para la inyección es como tu bien dices CreateremoteThread (seguro que alguna función publicada por tí), voy a buscar la técnica que me indicas de suspender el thread.

Tengo un poco de lio con la inyección en 64 bit y de 32 bit.

a ver yo tengo un pc con windows 7 de 64 bits y hay procesos que corren en 32 bits (firefox.exe *32) por ejemplo y otros en 64 bits.

con esta inyección me funciona en un pc con windows 7 32 bit, pero no me funciona en windows 7 64 bits en proceso de 32 bits. (ni compilando la dll y el injector en el pc de 64 bits, CreateremoteThread me devuelve 0 y sale).

Código Delphi [-]
function InjectLib(ProcessID: Integer): Boolean;
var
  Process: HWND;
  ThreadRtn: FARPROC;
  DllPath: AnsiString;
  RemoteDll: Pointer;
  BytesWriten: DWORD;
  Thread: DWORD;
  ThreadId: DWORD;

  aux:string;
begin
  Result := False;
  Process := OpenProcess(PROCESS_CREATE_THREAD or PROCESS_VM_OPERATION or PROCESS_VM_WRITE,
                         True,
                         ProcessID);
  if Process = 0 then Exit; 
  try

   
    DllPath := AnsiString(ExtractFilePath(ParamStr(0)) + DLLName) + #0;
   

    RemoteDll := VirtualAllocEx(Process,
                                nil,
                                Length(DllPath),
                                MEM_COMMIT or MEM_TOP_DOWN, PAGE_READWRITE);
    if RemoteDll = nil then Exit;
    try
     
      if not WriteProcessMemory(Process,
                                RemoteDll,
                                PChar(DllPath),
                                Length(DllPath),
                                BytesWriten)      then Exit;
      if BytesWriten <> DWORD(Length(DllPath)) then Exit;
      
      ThreadRtn := GetProcAddress(GetModuleHandle('Kernel32.dll'),
                                                  'LoadLibraryA');
      
      if ThreadRtn = nil then Exit;
    
      Thread := CreateRemoteThread(Process,
                                   nil,
                                   0,
                                   ThreadRtn,
                                   RemoteDll,
                                   0,
                                   ThreadId);
      if Thread = 0 then Exit;
      try
       
        Result := WaitForSingleObject(Thread,
                                      INFINITE) = WAIT_OBJECT_0;
      finally
        CloseHandle(Thread);
      end;
    finally
      VirtualFreeEx(Process,
                    RemoteDll,
                    0,
                    MEM_RELEASE);
    end;
  finally
    CloseHandle(Process);
  end;
end;

function GetPID(ExeFileName: string): dword;
var
  ContinueLoop, ffound: boolean;
  FSnapshotHandle: THandle;
  FProcessEntry32: TProcessEntry32;
  UpEFN: string;
begin
  result := 0;
  ffound := false;
  UpEFN := UpperCase(ExeFileName);
  FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  FProcessEntry32.dwSize := SizeOf(FProcessEntry32);
  ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
  while integer(ContinueLoop) <> 0 do
  begin
    if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) = UpEFN) or
        (UpperCase(FProcessEntry32.szExeFile) = UpEFN)) then
    begin
      result := FProcessEntry32.th32ProcessID;
      ffound := true;
      break;
    end;
    ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
  end;
  CloseHandle(FSnapshotHandle);
  if not ffound then
    ShowMessage(ExeFileName+'is not runing');
end;



var
  PID: dword;
begin

  PID := GetPID('notepad.exe');
 
  if (PID > 0) then

  if InjectLib(PID) = True then
       Application.MessageBox('Inyección OK', 'Application.Title', MB_OK +
       MB_ICONINFORMATION);

Última edición por angelp4492 fecha: 10-01-2017 a las 14:42:23.
Responder Con Cita