DLL Hijacking
Hijacking opportunity if an application doesn't specify the full path to a required DLL
The default DLL search order used by the system depends on whether Safe DLL Search Mode
is activated. Default setting: Enable
With this mode enabled, applications search for necessary DLL files in the following sequence:
The directory from which the application is loaded.
The system directory.
The 16-bit system directory.
The Windows directory.
The current directory.
The directories that are listed in the PATH environment variable.
However, if 'Safe DLL Search Mode' is deactivated, the search order changes to:
The directory from which the application is loaded.
The current directory.
The system directory.
The 16-bit system directory.
The Windows directory
The directories that are listed in the PATH environment variable
Use procmon to solely include main.exe
Filter for an Operation
of Load Image
to only get the libraries the app is loading.
Proxying
Create a new library that will load the function Add
from library.dll
, tamper with it, and then return it to main.exe
.
Create a new library: We will create a new library serving as the proxy for
library.dll
. This library will contain the necessary code to load theAdd
function fromlibrary.dll
and perform the required tampering.Load the
Add
function: Within the new library, we will load theAdd
function from the originallibrary.dll
. This will allow us to access the original function.Tamper with the function: Once the
Add
function is loaded, we can then apply the desired tampering or modifications to its result. In this case, we are simply going to modify the result of the addition, to add+ 1
to the result.Return the modified function: After completing the tampering process, we will return the modified
Add
function from the new library back tomain.exe
. This will ensure that whenmain.exe
calls theAdd
function, it will execute the modified version with the intended changes.
Rename library.dll
to library.o.dll
, and rename tamper.dll
to library.dll
.
Running main.exe
Invalid Libraries
Result
filter set to NAME NOT FOUND
to observe binaries searching for their lost DLLs.
See References
PowerSploit
See References
Tools
Resources
Last updated