NFS
CPTS Notes
- Start Here
- General Framework
- Enumeration
- Enumeration with Nmap
- Services
- FTP
- SMB
- NFS
- DNS
- SMTP
- IMAP
- POP3
- Reference
- Port References
- Linux Commands Cheatsheet
- DNS Resolution
- The Mail Pipeline
- SMB & NetBIOS
TL;DR
NFS (Network File System). Unix and Linux file sharing over RPC. NFSv3 needs rpcbind on TCP/UDP 111, plus NFS on 2049 and a mountd port. NFSv4 uses 2049 alone. NFSv3 and earlier authenticate with AUTH_SYS: the server trusts the client-supplied UID and GID, so there is no real authentication. NFSv4 can use Kerberos.
First checks: the exports, the NFS version, and the squash setting.
Enumeration
Workflow: sweep with nmap, enumerate with nxc nfs, then mount with the NFS client to read.
Sweep. rpcbind and NFS, with the export scripts:
sudo nmap -p111,2049 -sV --script rpcinfo,nfs-showmount,nfs-ls,nfs-statfs -oA scans/nfs $TARGETEnumerate with NetExec (nxc nfs). One command reports the NFS versions, whether root escape
(no_root_squash) is possible, and the exports:
nxc nfs $TARGET --shares--enum-shares walks the files in each export, three levels deep by default. --ls, --get-file,
and --put-file read and write without mounting. The module runs anonymously.
List and mount with the NFS client. List the exports, then mount one:
showmount -e $TARGETsudo mount -t nfs -o vers=3,nolock $TARGET:/<export> /mnt/nfsshowmount -e lists the exports. -o vers=3 selects NFSv3 (AUTH_SYS). nolock disables file
locking, which mounts cleanly when the lock manager is unreachable. Run umount /mnt/nfs when done.
Common misconfigurations
- Exports readable by any host (exported to
*). no_root_squash: a remote root user writes files as local root.- Writable exports.
- AUTH_SYS trust: the server trusts the client-supplied UID and GID, so any user can impersonate another UID.
insecure: accepts client source ports above 1024, so a non-root attacker can mount the export.
Attack playbook
NFS has no iconic version exploit. Its danger is configuration, so work the access it gives you.
- Loot readable exports. Mount and read. Hunt for SSH keys, configs, credentials, and backups. The usual NFS win. Listing and mounting are in Enumeration.
- Spoof a UID.
root_squashmaps your root to nobody, but AUTH_SYS trusts your UID. Read the numeric owner withls -n, then create a local user with that UID and act as them:
ls -n /mnt/nfssudo useradd -u 1014 lootusersudo -u lootuser cat /mnt/nfs/<file>ls -n shows the UID and GID instead of names, which your local /etc/passwd would mistranslate.
3. no_root_squash to root. When an export allows root and you hold local root, write a SUID
root shell into the share, then run it on the target:
sudo mount -t nfs $TARGET:/<export> /mnt/nfscp /bin/bash /mnt/nfs/rootbashchmod +s /mnt/nfs/rootbash# on the target:/<export>/rootbash -pchmod +s sets the SUID bit. bash -p keeps the root effective UID instead of dropping it.
- Write for access. A writable export mapped to a user’s
~/.sshor a web root takes an SSH key or a payload.
Practice boxes
| Box | Difficulty | NFS’s role |
|---|---|---|
| Squashed | Easy | UID spoofing: a share owned by another UID, read by creating a local user with that UID. |
| Remote | Easy | Windows NFS export readable by everyone leaks an Umbraco config hash. |
| Fortune | Hard | UID spoofing on an exported /home (OpenBSD). |
| Jail | Insane | nfsshell to reach root-squashed exports. |
On easy boxes NFS is loot or a quick privesc. The signature escalation is
no_root_squashto a SUID root shell.