DLL Search Order Hijacking
The application loads DLLs from locations that users can write to, so code placed there runs inside the application when it starts.
| Severity | Medium |
| CVSS 3.1 | 4.8 CVSS:3.1/AV:L/AC:L/PR:L/UI:R/S:U/C:L/I:L/A:L Open in the calculator |
| CVSS 4.0 | 2.4 CVSS:4.0/AV:L/AC:L/AT:N/PR:L/UI:P/VC:L/VI:L/VA:L/SC:N/SI:N/SA:N Open in the calculator |
| CWE | CWE-427: Uncontrolled Search Path Element |
| OWASP Top 10 | A08:2025 Software or Data Integrity Failures |
| MITRE ATT&CK | T1574.001 DLL |
| Category | Security Misconfiguration |
Description
The application loads one or more dynamic-link libraries (DLLs) without specifying a full path, so Windows searches a sequence of directories for them, and at least one directory searched before the genuine copy, or in place of a DLL that does not exist, can be written to by users who should not control the application's code. A DLL with the expected name placed there is loaded into the application's process, so an attacker who can write to that directory gets code execution inside the application, with its privileges, whenever it starts.
With the default safe search mode, Windows looks in the application's own directory first, then the system and Windows directories, then the current working directory and the directories listed in the PATH environment variable; system libraries on the KnownDLLs list are always loaded from the system directory. Common causes are an application installed outside Program Files, for example in a folder at the root of the system drive or in the user's profile, whose directory standard users can write to; an application that tries to load DLLs that do not exist, which are then sought in every location, including writable PATH entries; and installers or updaters that run from writable folders such as Downloads or temporary directories.
Where the directory is writable only by the user who runs the application, the weakness gives persistence and lets the attacker's code run inside a trusted, possibly signed, process that application control may allow, which is the typical case rated here. Where the application is started by other users or administrators, runs as a service or is launched elevated, it gives privilege escalation and should be rated higher. The weakness is identified by monitoring the application's DLL loads with Process Monitor, filtering for load attempts that return NAME NOT FOUND or that resolve to unprotected directories, checking those directories' permissions, and confirming exploitation by placing a test DLL that records its execution.
Remediation
Make the application load libraries only from trusted, protected locations, following Microsoft's guidance on dynamic-link library security:
- Install the application under
Program Files, or another directory where only administrators and SYSTEM can write, and make sure the installer does not loosen those permissions. - At start-up, call
SetDefaultDllDirectorieswithLOAD_LIBRARY_SEARCH_SYSTEM32, addingLOAD_LIBRARY_SEARCH_APPLICATION_DIRonly when the application directory is protected, so that the current directory andPATHare no longer searched. Add any other trusted directories withAddDllDirectory, which are searched only whenLOAD_LIBRARY_SEARCH_USER_DIRSis also specified. - Load libraries with
LoadLibraryExand theLOAD_LIBRARY_SEARCH_*flags, or with a fully qualified path, rather than by name alone, and remove attempts to load DLLs that are not shipped. - Run installers and updaters only from protected locations, and remove user-writable directories from the system
PATH.
For example:
Libraries that the executable imports statically are resolved before any of this code runs, so a protected installation directory remains essential. As an interim measure, correct the permissions on the affected directories so that standard users cannot write to them. Confirm the fix by repeating the Process Monitor review and the test DLL placement.
References
Add This Finding to Your Library
In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.
Free trialYour trial starts when your portal goes live, not when you sign up, so the time you spend setting up does not count. · No card required
Only need the reporting? Our reporting tool is free and open source, with the same library.