Course contentsShow
← Security
Lesson 1543 of 3,05231. Operating System Security - MalwareFree lesson

DLL Hijacking and Search Order Exploitation

Exploiting DLL search order, proxying legitimate DLLs, and application-specific DLL hijacking opportunities.

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:

  1. Application directory
  2. System directories (System32, SysWOW64)
  3. Current working directory
  4. Directories in the PATH environment 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.