DLL Hijacking exploits the way Windows searches for Dynamic Link Libraries (DLLs). When an application loads a DLL, Windows searches specific directories in a defined order. If we can place a malicious DLL earlier in the search path, our code runs instead of the legitimate library.
Think of it like a road detour. The application expects to find its library at the usual location, but we've set up a fake "library" earlier on the route. The application picks up our fake, thinking it's the real thing.
Service vs Application DLL Hijacking
Hijacking a DLL loaded by a SYSTEM service = SYSTEM privileges. Hijacking a DLL loaded by a user application = that user's privileges. Focus on services for privilege escalation.
DLL Search Order
Why DLL Hijacking Works
Finding DLL Hijacking Opportunities
Using Process Monitor
Automated Discovery
Creating Malicious DLLs
Using msfvenom
Matching Exported Functions
Export Matching
Some applications check for specific exported functions. If your DLL doesn't export what's expected, it may not load. Use dumpbin to see required exports.
Exploitation Examples
Missing DLL Hijacking
PATH DLL Hijacking
Commonly Hijacked DLLs
DLL Hijacking Methodology
DLL Hijacking Attack Flow
1
MonitorUse Process Monitor to find missing DLLs
2
IdentifyFind DLLs searched in writable locations
3
VerifyConfirm directory is writable (icacls)
4
Check ServiceVerify service runs as SYSTEM
5
Create DLLGenerate malicious DLL with msfvenom
6
PlaceCopy DLL to writable location
7
TriggerRestart service or wait for load
Knowledge Check
Challenges
Key Takeaways
- Windows searches for DLLs in a specific order
- If we can write to a directory earlier in the order, we win
- Process Monitor reveals DLL loading behavior
- Filter for NAME NOT FOUND in writable locations
- Target services running as SYSTEM for privilege escalation
- May need to export specific functions to match expectations