# Nfs Rpc Exploitation

> Use when NFS/rpcbind (2049/111) exposed: enum & mount.

- Skill: `yufeifeio/nfs-rpc-exploitation` (Agent Skill, multi-file: 4 files)
- Install (CLI): `npx get-skill add yufeifeio/nfs-rpc-exploitation`
- Raw SKILL.md: https://api.skillmd.com/api/skills/yufeifeio/nfs-rpc-exploitation/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: Yufeifeio (https://skillmd.com/u/yufeifeio)
- Updated: 2026-11-22
- Page: https://skillmd.com/skills/yufeifeio/nfs-rpc-exploitation

---


# NFS / RPC-Service Exploitation

Attacking hosts exposing NFS + rpcbind: common on operator/dev boxes, cloud ECS instances, NAS, and internal networks. Highest-value outcomes: a world-exported share with `no_root_squash` (files you write land on the server as uid 0), and/or an unpatched NFSv4.0 n-day.

## Detection & sweep
Scan every host you already hold (family siblings, looted boxes, internal ranges) for `2049` (nfs) and `111` (rpcbind) before concluding a box has no more doors — one NFS hit can outweigh a week of web fuzzing:
```bash
nmap -Pn -p 2049,111 --open -T4 <targets...>
```
```python
# fast multicore connectivity sweep over a /24
ok = socket.socket().connect_ex((ip, 2049)) == 0
```

## Procedure
1. **RPC service map — do NOT trust `showmount`/`rpcinfo` alone.** They hang for minutes when mountd sits on a nonstandard port or UDP is filtered. Call the portmapper directly: `scripts/portmap_dump.py <host> [port=111]` (UDP + TCP; TCP requires ONC RPC record marking = 4-byte header `0x80000000|len` — a bare call just times out). It prints the program→port map: mountd(100005), nfs(100003), statd(100024), nlockmgr(100021). Expect mountd on a random high port.
2. **List exports.** If showmount works, use it; otherwise raw MOUNT v2 EXPORT (proc 5) against the mountd port: `scripts/mnt_export.py <host> <mountd_port>`. Parse for export paths and the client spec — group `*` = open to everyone.
3. **Mount — version/path gotchas (time sink):**
   - `with vers=3` → `requested NFS version or transport protocol is not supported` ⇒ server is **NFSv4-only**.
   - NFSv4: mount the **pseudo-root `:/`**, NOT the export path — `host:/srv/nfs/share` returns `No such file or directory` even when the export exists.
   ```bash
   mount -t nfs -o vers=4.0,soft,timeo=30 <host>:/ /mnt/nfsx
   ```
4. **Write + identity-mapping test (the jackpot):**
   ```bash
   mkdir /mnt/nfsx/probe_$$ && ls -ln /mnt/nfsx
   ```
   Probe dir showing uid 0/gid 0 ⇒ **no_root_squash**: your files live as root on the server. `sec=sys` (default) means the server trusts the client-claimed uid — squashing is the operator's choice, so always test it, never assume.
5. **Escalate or park:**
   - A writable-as-root share is only host-root if something on the box executes/consumes from it — check what the share is for (deploy dir, backup, queue) before claiming escalation. NFSv4's pseudo-root isolates the share; there is no traversal to `/etc` or `/root`.
   - No exec vector ⇒ keep the mount (exfil channel + box-relation signal), and pivot to the same host's other ports (SSH, HTTPS panels).
   - The box's own looted SSH keys/passwords frequently do NOT log back into the same box (hardened sshd) — try ≤3, then move on.
6. **n-day check:** NFSv4.0 code is live exploit territory — see `references/cve-2026-31402-nfsv4-rce.md` (crash PoC is pure-network; full RCE needs a local foothold). Weigh keep-alive value before crashing anything.

## Pitfalls
- `showmount -e` hanging ≠ no NFS — it is a thin UI over the same RPC calls; go raw (steps 1–2).
- Forgetting ONC RPC TCP record marking looks exactly like a filtered/closed port.
- NFSv4 `No such file or directory` on mount = wrong path form (use `:/`), not a dead export.
- Same box, two surfaces pair up: an open HTTP directory listing (python `http.server` etc.) gives file READ while NFS gives root-identity WRITE — check both and verify a file created over NFS through the box's own HTTP layer.
- A writable share does not equal root. State impact precisely: "share writable as uid 0" until an execution/consumption path is proven.
- An empty share listing is not a dead export — operators clean shares between runs; only the write test (mkdir + `ls -ln`) decides.

## References
- `references/cve-2026-31402-nfsv4-rce.md` — NFSv4.0 LOCK-replay heap overflow → RCE: mechanics, preconditions, exploit status.
- `scripts/portmap_dump.py` — raw portmapper DUMP (UDP+TCP, record marking handled).
- `scripts/mnt_export.py` — raw MOUNT v2 EXPORT listing for nonstandard mountd ports.

