DLL Injectors
Inject DLLs into remote process's virtual address space
Classic DLL Injection
C# Executable
A simple C# DLL injector to explain the basics:
Allocate space for the malicious DLL name in remote process's virtual address space.
Write the DLL name into the allocated space.
Locate the address of the LoadLibraryA function in kernel32.dll with
GetModuleHandle
andGetProcAddress
. Most Windows native DLLs are allocated at the same base address, so the obtained address ofLoadLibraryA
will be the same for the remote process.Invoke
LoadLibraryA
function on the behalf of the remote thread supplying baseLoadLibraryA
address as the 4th argument ofCreateRemoteThread
and the address of the DLL name to be loaded as the 5th argument.
All this is needed because LoadLibrary
functions cannot be invoked natively on a remote process.
According to this template that MSF is using to generate a DLL, there's another injection technique (Thread Execution Hijacking) in the DLL code itself which is invoked upon DLL_PROCESS_ATTACH
event. That causes the DLL not to be loaded in the target process memory, but it rather forces new shellcode to be executed by rundll32.exe
and the malicios process (meterpreter shell, etc.) gets the PID of rundll32.exe
. It may also result in hanging the parent's process (explorer.exe
in terms of this example) and crashing it when the shell dies.
Reflective DLL Injection (RDI)
Theory Basics
Custom LoadLibrary
Invoke-ReflectivePEInjection
Last updated