DLL Hijacking and Search Order Exploitation
You'll learn how attackers exploit Windows' DLL loading behavior to maintain persistence and execute malicious code.
The Core Vulnerability
Windows searches for DLLs in a predictable order when an application needs to load them. By default, it checks the application's directory before system directories. This creates an opportunity: if an attacker places a malicious DLL in a higher-priority location with the same name as a legitimate system DLL, Windows will load the attacker's version instead.
Think of it like leaving fake house keys in obvious places. If someone's programmed to grab "the first key they find" rather than "the right key from the right location," they'll use whatever malicious key you plant first.
How the Attack Works
DLL Search Order Exploitation
When an application calls LoadLibrary() without a full path, Windows searches locations in order:
- Application directory
- System directories (
System32,SysWOW64) - Current working directory
- Directories in the
PATHenvironment variable
Attackers place malicious DLLs in locations checked before the legitimate DLL location.
DLL Proxying
Sophisticated attackers create proxy DLLs that forward legitimate function calls to the real DLL while also executing malicious code. This maintains application functionality, avoiding detection through crashes or broken features.
Application-Specific Opportunities
Vulnerable scenarios include:
- Applications installed in writable directories
- Programs loading DLLs from user-controlled paths
- Elevated applications searching user-writable locations first
- Missing DLLs that applications attempt to load but don't strictly require
Key Takeaway: DLL hijacking exploits the predictable order Windows searches for libraries, allowing attackers to inject malicious code by placing fake DLLs in higher-priority locations, often using proxy techniques to maintain normal application behavior while achieving persistence.