DLL Search Order Hijacking
ID: T1038 Tactic: Persistence, Privilege Escalation, Defense Evasion
Windows systems use a common method to look for required DLLs to load into a program. Adversaries may take advantage of the Windows DLL search order and programs that ambiguously specify DLLs to gain privilege escalation and persistence.
Adversaries may perform DLL preloading, also called binary planting attacks, by placing a malicious DLL with the same name as an ambiguously specified DLL in a location that Windows searches before the legitimate DLL. Often this location is the current working directory of the program. Remote DLL preloading attacks occur when a programs sets its current directory to a remote location such as a Web share before loading a DLL.Adversaries may use this behavior to cause the program to load a malicious DLL.
Adversaries may also directly modify the way a program loads DLLs by replacing an existing DLL or modifying a .manifest or .local redirection file, directory, or junction to cause the program to load a different DLL to maintain persistence or privilege escalation.
If a search order-vulnerable program is configured to run at a higher privilege level, then the adversary -controlled DLL that is loaded will also be executed at the higher level. In this case, the technique could be used for privilege escalation from user to administrator or SYSTEM or from administrator to SYSTEM, depending on the program.
Programs that fall victim to path hijacking may appear to behave normally because malicious DLLs may be configured to also load the legitimate DLLs they were meant to replace.
Let's set some examples
In Windows environments when an application or a service is starting it looks for a number of DLL's in order to function properly. If these DLL's doesn't exist or are implemented in an insecure way (DLL's are called without suing a fully qualified path) then it is possible to escalate privileges by forcing the application to load and execute a malicious DLL file.
It should be noted that when an application needs to load DLL it will go through the following order:
  • The directory from which the application is loaded.
  • C:\Windows\System32
  • C:\Windows\System
  • C:\Windows
  • The current working directory
  • Directories in the system PATH environment variable
  • Directories in the user PATH environment variable
A fast way to Hijack and Find any DLL hijacking is using Powersploits, Find-PathhDLLHijack, Find-ProcessDLLHijack, Invoke-AllChecks. We can check that powersploit will tell us where the hijack is located and what command to use next to hijack the process immediately.
For this technique I will use Procmon, as this is a great tool to view what a program is loading at run time, there are also other great tools from PowerSploit that will verify this Vulnerability and SharpUp from GhostPack it is a tool written in C#
The nsutil.dll is missing.But we see that it finds it later in the SYSWOW64PATH. But first it will try and search for it at C:\Program Files (x86)\Winamp\ PATH so an adversary here will take advantage by placing a malicious DLL file and wait until the Program is executed again.
We can kill the process, but that isn't Stealthy, right?
I created a malicious DLL with my payload to call back into my Kali Box. And we need to verify does our user have WRITE permissions in that folder.
BUILTIN\Users:(W) Write permissions
Now let's Add the DLL and rename it properly.
Now we kill the process and reload it again.
Last modified 1yr ago
Copy link