AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Tutorials CreateRemoteThread - DLL Injection
Tutorial durchsuchen
Ansicht
Themen-Optionen

CreateRemoteThread - DLL Injection

Ein Tutorial von Luckie · begonnen am 14. Mai 2008 · letzter Beitrag vom 3. Jul 2008
 
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#1

CreateRemoteThread - DLL Injection

  Alt 14. Mai 2008, 13:09
CreateRemoteThread - DLL Injection
Anbei eine Demo zur API-Funktion MSDN-Library durchsuchenCreateRemoteThread bzw. wie man mittels einer DLL Code von einer anderen Anwendung ausführen lässt.

Das Beispiel nutzt dafür die notepad.exe und lässt von ihr eine Messagebox anzeigen, die den Pfad ausgibt, der den Code ausführt.

Der relevante Code:
Delphi-Quellcode:
const
  DLLFILENAME = 'MsgBox.dll';

var
  ProcessID : Integer;
  hProcess : THandle;
  DLLPath : string;
  pDLLPath : Pointer;
  BytesWritten : Cardinal;
  ThreadID : Cardinal;

begin
  About;

  DLLPath := ExtractFilePath(ParamStr(0)) + '\' + DLLFILENAME;

  ProcessID := GetProcessID('notepad.exe');
  if ProcessID <> 0 then
  begin
    hProcess := GetProcessHandleFromID(ProcessID);
    if hProcess <> 0 then
    begin
      // alloc memory in remote process
      pDLLPath := VirtualAllocEx(hProcess, nil, Length(DLLPath), MEM_COMMIT, PAGE_EXECUTE_READWRITE);
      if Assigned(pDLLPath) then
      begin
        // write DLL Path into the allocated memory
        if WriteProcessMemory(hProcess, pDLLPath, PChar(DLLPath), Length(DLLPath), BytesWritten) then
        begin
          // create remote thread and load library
          if CreateRemoteThread(hProcess, nil, 0, GetProcAddress(GetModuleHandle('kernel32.dll'), 'LoadLibraryA'),
            pDLLPath, 0, ThreadID) <> 0 then
          begin
            CloseHandle(hProcess);
            Writeln('DLL injected...');
          end
          else
            Writeln(GetLastError);
        end
        else
          Writeln(GetLastError);
      end
      else
        Writeln(GetLastError);
    end
    else
      Writeln(GetLastError);
  end
  else
    Writeln(GetLastError);

  Readln;
end.
Der ganze Code kann in der Demo im Anhang nachvollzogen werden.
Angehängte Dateien
Dateityp: zip createremotethread_144.zip (25,3 KB, 212x aufgerufen)
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:41 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz