# DLL Hijacking

### Overview

**DLL Hijacking** is a **Windows local privilege escalation (LPE)** technique that abuses **insecure DLL search order behavior** in **services or applications running with higher privileges** (often **SYSTEM**).

If a privileged service:

* Loads a DLL **without specifying a full path**
* And the attacker can **write to a directory searched earlier**

### Why this Works

Windows follows a **DLL search order** when loading DLLs without absolute paths:

1. Application directory
2. System32
3. System
4. Windows
5. Current working directory
6. Directories in `PATH`

If a service executable:

* Is **SYSTEM-owned**
* Loads a DLL **by name only**
* Searches a **writable directory first**

Attacker drops a malicious DLL → service loads it → **SYSTEM execution**

### Prerequisites

1. Local Code Execution
2. Vulnerable Service or Executable
3. Writable Directory in DLL Search Path
4. Ability to Restart the Service

### Steps

1. Enumerate Services:\
   **Eg**: Use:

   * **Process Monitor** (ProcMon)
   * Filter:
     * Process Name = service executable
     * Result = NAME NOT FOUND
     * Path ends in `.dll`

   This reveals **DLLs the service tries to load but cannot find**.
2. Generate and place Malicious DLL in the writable Directory.
3. Restart the Service


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gokulkarthik.gitbook.io/pentesting-checklist/windows-and-active-directory/windows-privilege-escalation/service-exploits/dll-hijacking.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
