ich habe mich gestern mal rangesetzt und ein Dll Injektion Modul programmiert, da meine alten nicht mehr funktionieren.
Ich entwickle das ganze unter Windows 7 x64 und compile es als x86 statt 'Any CPU', da es sonst bei 32 bit Prozessen die 64 bit 'LoadLibraryA' Addresse laden würde. Unter Windows 7 x64 funktioniert es auch, sofern ich in einen 32 bit Prozess injecte.
Unter 32 bit (Windows X & 7)funktioniert der Inject0r aber nicht! Die Dll die ich injekte ist 100% 32 bit. Wie kann ich das regeln, dass es möglichst mit jeder OS-Bitversion und jeder Prozess-Bitversion funktioniert?
Hier der Code meiner 'Injection' class:
Public Class Injection ' Injection.vb class ' (C) 2013 hackiosa akaAnne Frank ' Do not copy without permission Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Integer, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer Private Declare Function VirtualProtectEx Lib "kernel32" (ByVal hProcess As Integer, ByVal lpAddress As Integer, ByVal dwSize As Integer, ByVal flNewProtect As Integer, ByVal lpflOldProtect As IntPtr) As Boolean Private Declare Function VirtualAllocEx Lib "kernel32" (ByVal hProcess As IntPtr, ByVal lpAddress As IntPtr, ByVal dwSize As IntPtr, ByVal flAllocationType As Integer, ByVal flProtect As Integer) As IntPtr Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As Integer Public Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Integer, ByVal lpProcName As String) As Integer Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Integer Private Declare Function CreateRemoteThread Lib "kernel32" (ByVal ProcessHandle As Integer, ByVal lpThreadAttributes As Integer, ByVal dwStackSize As Integer, ByVal lpStartAddress As Integer, ByVal lpParameter As Integer, ByVal dwCreationFlags As Integer, ByVal lpThreadID As Integer) As Integer Private Const MEM_COMMIT = &H1000 Private Const MEM_RESERVE = &H2000 Private Const PAGE_READWRITE = &H4 Private Shared Function GetProcessHandle(ByVal name As String) As IntPtr Dim handle As IntPtr name = Replace(name, ".exe", "") For Each p As Process In Process.GetProcessesByName(name) handle = OpenProcess(2035711, 0, p.Id) Next Return handle End Function Public Shared Sub InjectDLL(ByVal process As String, ByVal dll As String) Dim dwTid As Integer Dim dwLoadLibraryA As Int32 = GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA") Dim dwHandle As Integer = GetProcessHandle(process) Dim dwFreeSpace As Integer = VirtualAllocEx(dwHandle, 0, Len(dll) + 1, MEM_COMMIT + MEM_RESERVE, PAGE_READWRITE) ' write dll path to free space For i = 0 To Len(dll) - 1 WriteProcessMemory(dwHandle, dwFreeSpace + i, Asc(Mid(dll, i + 1, 1)), 1, vbNull) Next ' create thread to LoadLibraryA CreateRemoteThread(dwHandle, 0, 0, dwLoadLibraryA, dwFreeSpace, 0, dwTid) End Sub End Class
Vielen Dank im vorraus
Bearbeitet von 0xC3, 05 May 2013 - 12:36 Uhr.