knowledge

Overview

NFS (Network File System) is a distributed file system protocol developed by Sun Microsystems that allows file systems to be mounted and accessed over a network as if they were local. NFS is primarily used between Linux and Unix systems and cannot communicate with SMB servers. Authentication is delegated to the RPC protocol layer, meaning NFS itself has no built-in auth mechanism — access is controlled by UID/GID mappings between client and server, which can be exploited when those mappings differ.


Terminology

TermDefinition
NFSNetwork File System — protocol for remote file system access over a network
RPCRemote Procedure Call — underlying protocol NFS uses for communication
ONC-RPCOpen Network Computing RPC (also called SUN-RPC) — NFS transport layer; exposes on TCP/UDP port 111
XDRExternal Data Representation — system-independent data format used by RPC
portmapperService on port 111 that maps RPC program numbers to port numbers
pNFSParallel NFS — NFSv4.1 extension allowing parallel access to files across multiple servers
UID/GIDUser/Group ID — Linux identifiers used by NFS for authorization
root_squashConfig option that maps root UID/GID to anonymous — prevents remote root from having root on share
no_root_squashDangerous: remote root user keeps root privileges on the NFS share
/etc/exportsNFS server config file listing shared directories and their access rules
showmountTool to list NFS shares exported by a server

Core Concepts

Protocol Overview

NFS is governed by Internet standard RFCs and uses ONC-RPC as its transport protocol. It exposes on TCP/UDP port 111 (portmapper) and TCP/UDP port 2049 (NFS service itself; required in NFSv4+).

NFS has no native authentication or authorization mechanism. Authentication is handled by RPC via UNIX UID/GID. The server translates client user info into file system permissions. Because the server does not verify that client UID/GID mappings match its own, an attacker who controls UID 0 on their machine effectively has root access to any NFS share mounted without root_squash.


NFS Versions

VersionKey Characteristics
NFSv2Older; widely supported; originally operated over UDP only
NFSv3Variable file size, better error reporting; not fully compatible with NFSv2; only requires client authentication
NFSv4Kerberos support, firewall-friendly (single port 2049), ACLs, stateful protocol, IPv6 and TLS support; requires user authentication
NFSv4.1Adds parallel NFS (pNFS) — clients can access multiple storage servers simultaneously for scale; adds session trunking (multipathing) so one session can use multiple network paths for redundancy; still uses TCP/UDP 2049 only

/etc/exports Configuration

The exports file specifies which directories are shared and what rules apply. Format: <directory> <host_or_subnet>(<options>)

Options

OptionDescription
rwRead and write permissions
roRead-only permissions
syncSynchronous writes — slightly slower but consistent
asyncAsynchronous writes — faster but risk of inconsistency on crash
secureOnly ports below 1024 allowed (privileged ports only)
insecurePorts above 1024 allowed — weaker
no_subtree_checkDisable subtree checking — improves reliability for exported subdirectories
root_squashMap remote root to anonymous UID/GID — default safe behavior
no_root_squashRemote root retains root privileges on share — dangerous
nohideExport subdirectories mounted below an exported directory

Create an export entry: echo '/mnt/nfs 10.129.14.0/24(sync,no_subtree_check)' >> /etc/exports systemctl restart nfs-kernel-server exportfs — display current active exports


Dangerous Settings

SettingRisk
rwCombined with no_root_squash, attacker with local root can write anything
insecureNon-privileged ports allowed — less trust verification
nohideMounts nested below exported dirs also become accessible
no_root_squashRemote root == local root on the share — full privilege escalation if mounted

Footprinting NFS

NFS enumeration requires ports 111 and 2049. Scan with Nmap using NFS NSE scripts (--script nfs*) to list available shares, their contents, and stats.

Show available shares from Linux: showmount -e <target>

Mount a share locally: mkdir target-NFS && sudo mount -t nfs <target>:/ ./target-NFS/ -o nolock

Use ls -nl after mounting to see numeric UID/GID — useful for identifying the real user accounts owning files on the server.

Unmount when done: sudo umount ./target-NFS

ℹ︎Note on Windows-to-Linux Mounts

After mounting a Windows NFS share to a Linux machine, check file permissions — you may need root to access certain files.


Privilege Escalation via NFS

When you have SSH access to a system and want to read files from a restricted directory:

  1. If the target has an NFS share with no_root_squash, mount it on your attack machine
  2. Create a local user matching the target’s UID
  3. Upload a shell binary with SUID set as that UID
  4. Execute the shell via SSH to elevate to that user’s context

This works because no_root_squash lets you write files as root on the share, and the SUID bit executes with the file owner’s UID on the target.


  • Service Enumeration

References / Images

  • man exports
  • man showmount
  • RFC 7530 (NFSv4), RFC 8881 (NFSv4.1)