كيف تعمل لودر لملفات dll
#8
للفائدة سأضيف 3 دالات و وحدة
كود :
procedure InjectDll(PID: dword; DLL: pChar); var BytesWritten, hProcess, hThread, TID: Cardinal; Parameters: pointer; pThreadStartRoutine: Pointer; begin hProcess := OpenProcess(PROCESS_ALL_ACCESS, False, PID); Parameters := VirtualAllocEx( hProcess, nil, Length(DLL)+1, MEM_COMMIT or MEM_RESERVE, PAGE_READWRITE); WriteProcessMemory(hProcess,Parameters,Pointer(DLL ),Length(DLL)+1,BytesWritten); pThreadStartRoutine := GetProcAddress(GetModuleHandle('KERNEL32.DLL'), 'LoadLibraryA'); hThread := CreateRemoteThread(hProcess, nil, 0, pThreadStartRoutine, Parameters, 0, TID); CloseHandle(hProcess); end;
كود :
Function InjectDll2(ProcessID: DWORD; LibraryName: String): Integer; const MAX_LIBRARYNAME = MAX_PATH; MAX_FUNCTIONNAME = 255; MIN_INSTRSIZE = 5; Type PLibRemote = ^TLibRemote; TLibRemote = packed record ProcessID: DWORD; LibraryName: Array [0..MAX_LIBRARYNAME] of Char; LibraryHandle: HMODULE; end; var hKernel: HMODULE; hProcess: THandle; hThread: THandle; dwNull: Cardinal; lpRemote: PLibRemote; lpLibRemote: PChar; Begin // Set default result of (-1), which means the injection failed result:=(-1); // Check library name and version of OS we are running on if (Length(LibraryName) > 0) and ((GetVersion and $80000000) = 0)then begin Result := 2; // Attempt to open the process hProcess:=OpenProcess(PROCESS_ALL_ACCESS, False, ProcessID); // Check process handle if (hProcess <> 0) then begin // Resource protection try Result:= 3; // Get module handle for kernel32 hKernel:=GetModuleHandle('kernel32.dll'); // Check handle if (hKernel <> 0) then begin Result := 4; // Allocate memory in other process lpLibRemote:=VirtualAllocEx(hProcess, nil, Succ(Length(LibraryName)), MEM_COMMIT, PAGE_READWRITE); // Check memory pointer if Assigned(lpLibRemote) then begin // Resource protection try Result := 5; // Write the library name to the memory in other process WriteProcessMemory(hProcess, lpLibRemote, PChar(LibraryName), Length(LibraryName), dwNull); // Create the remote thread hThread:=CreateRemoteThread(hProcess, nil, 0, GetProcAddress(hKernel, 'LoadLibraryA'), lpLibRemote, 0, dwNull); // Check the thread handle if (hThread <> 0) then begin // Resource protection try // Allocate a new remote injection record lpRemote:=AllocMem(SizeOf(TLibRemote)); // Set process id lpRemote^.ProcessID:=ProcessID; // Copy library name StrPLCopy(lpRemote^.LibraryName, LibraryName, MAX_LIBRARYNAME); // Wait for the thread to complete WaitForSingleObject(hThread, INFINITE); // Fill in the library handle GetExitCodeThread(hThread, DWORD(lpRemote^.LibraryHandle)); // Add to list result:=1; finally // Close the thread handle CloseHandle(hThread); end; end; finally // Free allocated memory VirtualFree(lpLibRemote, 0, MEM_RELEASE); end; end; end; finally // Close the process handle CloseHandle(hProcess); end; end; end; End;
كود :
function InjectDll(TargetProcessID : DWORD; dllName : string): boolean; var LibName : pointer; hProcess , ThreadHandle : Thandle; BytesWritten , TheadID : DWORD; begin result := false; hProcess := OpenProcess( PROCESS_ALL_ACCESS, FALSE, TargetProcessID ); if (hProcess = 0) then exit; // alocate and write the dll name to the remote process LibName := VirtualAllocEx(hProcess , 0, length(dllName) + 5 , MEM_COMMIT , PAGE_READWRITE) ; if ( LibName <> nil) then begin WriteProcessMemory(hProcess , LibName, pchar(dllName) , length(dllName) , BytesWritten ); end ; ThreadHandle := CreateRemoteThread( hProcess , nil , 0, GetProcAddress(LoadLibrary('kernel32.dll'), 'LoadLibraryA') , LibName ,0 , TheadID ); result := ThreadHandle <> 0; WaitForSingleObject( ThreadHandle , INFINITE); //wait for the thread to execute // free the memory we allocated for the dll name VirtualFreeEx( hProcess , LibName , 0 , MEM_RELEASE); CloseHandle(hProcess); end;
الرد


الردود في هذا الموضوع
كيف تعمل لودر لملفات dll - بواسطة cargem - 14-07-2011, 09:25 PM
كيف تعمل لودر لملفات dll - بواسطة cargem - 15-07-2011, 01:52 PM
كيف تعمل لودر لملفات dll - بواسطة أبو معاذ - 16-07-2011, 06:27 PM
كيف تعمل لودر لملفات dll - بواسطة paix144 - 14-07-2011, 11:19 PM
كيف تعمل لودر لملفات dll - بواسطة paix144 - 15-07-2011, 06:24 PM
كيف تعمل لودر لملفات dll - بواسطة cargem - 15-07-2011, 08:21 PM
كيف تعمل لودر لملفات dll - بواسطة cargem - 15-07-2011, 09:20 PM
كيف تعمل لودر لملفات dll - بواسطة paix144 - 15-07-2011, 10:16 PM
كيف تعمل لودر لملفات dll - بواسطة paix144 - 15-07-2011, 10:24 PM
كيف تعمل لودر لملفات dll - بواسطة paix144 - 15-07-2011, 10:55 PM
كيف تعمل لودر لملفات dll - بواسطة cargem - 15-07-2011, 11:01 PM
كيف تعمل لودر لملفات dll - بواسطة cargem - 15-07-2011, 11:08 PM

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم