Course contentsShow
← Security
Lesson 2147 of 3,05242. Penetration Testing and Red TeamingFree lesson

NFS and Network File System Exploits

Exploiting no_root_squash and weak NFS exports to create SUID binaries or access privileged files.

NFS and Network File System Exploits

You'll learn how weak NFS configurations can be exploited to gain root access by creating malicious SUID binaries or accessing privileged files.

Network File System (NFS) allows remote systems to mount and access directories over a network. When misconfigured, it becomes a powerful privilege escalation vector on Linux systems.

The Core Vulnerability: no_root_squash

By default, NFS "squashes" root privileges—meaning if you're root on your machine but access an NFS share, you're treated as a low-privilege user. However, when an NFS export is configured with the no_root_squash option, your root privileges are preserved across the network mount.

Think of it like this: Imagine a shared storage locker where normally anyone entering is downgraded to "guest" status. But with no_root_squash, if you're the boss on your side, you remain the boss inside the locker too.

The Attack Chain

  1. Discover NFS exports on the target system (you've learned enumeration techniques)
  2. Mount the share to your attacker machine
  3. Create a SUID binary as root on your machine (since no_root_squash preserves your root status)
  4. Execute the SUID binary from the victim machine—it runs with root privileges

For example, you could compile a simple shell program, set it as SUID root on the mounted share, and when a user on the victim system runs it, they get a root shell.

Alternatively, if NFS exposes sensitive directories like /root or /etc, you can directly read SSH keys, password hashes, or configuration files.

Why This Works

The victim system trusts files created on the NFS share with their owner IDs intact. A SUID binary owned by UID 0 (root) executes with root privileges, regardless of who runs it.

Key Takeaway: NFS exports with no_root_squash or overly permissive access controls allow attackers to plant SUID backdoors or steal privileged data by leveraging root access from their own machines.