DLL Hijacking and Search Order Vulnerabilities
What You'll Learn
You'll learn how attackers exploit Windows' library loading behavior to inject malicious code into privileged processes, achieving code execution as SYSTEM or administrator.
The Core Problem: Windows DLL Search Order
When a Windows application needs a DLL (Dynamic Link Library), it searches multiple directories in a specific order. If an attacker can place a malicious DLL in a location checked before the legitimate one, Windows loads the attacker's code instead.
Think of it like this: You're at work and ask for "the Smith file." If someone plants a fake Smith file on your desk before you check the filing cabinet, you'll grab the wrong one without realizing it.
The Default Search Order
Windows typically searches in this order:
- The application's directory
- System directories (
C:\Windows\System32, etc.) - Current working directory
- Directories in the PATH environment variable
The vulnerability: If a privileged application (running as SYSTEM or admin) loads a DLL from a writable location like its application directory or current working directory, a low-privileged attacker can drop a malicious DLL there first.
Why This Matters for Privilege Escalation
When the privileged process loads your malicious DLL, your code runs with the same elevated privileges as the host process. This transforms a write-only file permission into full code execution at a higher privilege level.
Common scenarios:
- Services running as SYSTEM that load DLLs from their installation directory
- Scheduled tasks executing from user-writable paths
- Applications with weak directory permissions
Key Takeaway: DLL hijacking exploits Windows' predictable library search behavior—by placing a malicious DLL in a location checked before the legitimate library, attackers can inject code into privileged processes and inherit their elevated permissions, turning file-write access into privilege escalation.