Einzelnen Beitrag anzeigen

Lyan

Registriert seit: 5. Aug 2011
188 Beiträge
 
#1

DLL-Injection klappt nicht

  Alt 31. Okt 2012, 04:51
Delphi-Version: 7
Hallo,

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
const Pfad = 'C:\temp\test.dll';
var
  h : HWND;
  r, hProc, Fehler : DWORD;
  pVAE : Pointer;
begin
  h := FindWindow(nil,PAnsiChar('Unbenannt - Editor'));
  GetWindowThreadProcessId(h,@r);
  hProc := OpenProcess(PROCESS_ALL_ACCESS,false,r);
  pVAE := VirtualAllocEx(hProc,nil,length(Pfad)+1,MEM_COMMIT OR MEM_RESERVE,PAGE_READWRITE);
  WriteProcessMemory(hProc,pVAE,Pchar(Pfad),length(Pfad)+1,Fehler);
  CreateRemoteThread(hProc,nil,0,getprocaddress(loadlibrary('kernel32.dll'),'LoadLibraryA'),pVAE,0,Fehler);
end;
wäre für Denkanstöße, warum es so nicht funktioniert sehr dankbar!

Vlt. verstehe ich auch etwas falsch:
also habe mal ganz easy mit findwindow "h" das handle von notepad zugewiesen, dann in "r" die Processid gespeichert... hProc das Handle des Prozesses zugewiesen. Dann mit VirtualAllocEx Speicher für den String "C:\temp\test.dll" alloziert und mit WriteProcessMemory dann den String reingeschrieben.

Und ja, dann CreateRemoteTherad das handle von OpenProcess wieder geben,
Code:
"A pointer to the application-defined function of type LPTHREAD_START_ROUTINE to be executed by the thread and represents the starting address of the thread in the remote process. The function must exist in the remote process. For more information, see ThreadProc."
deshalb GetProcAddress(loadlib) machen und halt eben den Pfad zur DLL...


Hilfe

Geändert von Lyan (31. Okt 2012 um 04:53 Uhr)
  Mit Zitat antworten Zitat