Weak NFS Privileges
Network File System (NFS) allows users to access shared files or directories over the network hosted on Unix/Linux systems. NFS uses TCP/UDP port 2049. Any accessible mounts can be listed remotely by issuing the command showmount -e
, which lists the NFS server's export list (or the access control list for filesystems) that NFS clients.
When an NFS volume is created, various options can be set:
Option
Description
root_squash
If the root user is used to access NFS shares, it will be changed to the nfsnobody
user, which is an unprivileged account. Any files created and uploaded by the root user will be owned by the nfsnobody
user, which prevents an attacker from uploading binaries with the SUID bit set.
no_root_squash
Remote users connecting to the share as the local root user will be able to create files on the NFS server as the root user. This would allow for the creation of malicious scripts/programs with the SUID bit set.
First, create a simple setuid binary, mount the directory locally as root user, copy it, and set the necessary permissions as root user.
Go back the target machine and just execute it.
Privilege Escalation via UID Spoofing and NFS Misconfiguration (with bash -p
)
bash -p
)In insecure NFS environments, privilege escalation can be achieved by spoofing a UID and abusing file operations through shared directories. A common technique involves using bash -p
, which preserves the effective UID when the binary has the setuid bit.
🔧 Steps to Exploit:
Identify a Target UID: Find the UID of a privileged user (e.g., through
/etc/passwd
or file ownership within the NFS share).Create a Local User with Matching UID (on Attacker's Machine):
Upload Bash Binary to NFS (from Compromised Account): Use an account (e.g.,
www-data
) with write access to place a localbash
binary into the shared NFS directory:Set SetUID Bit on the Bash Binary (from Attacker’s Machine):
Execute Bash with Preserved UID (on Target): From the target system, the low-privileged user can run:
This launches a shell with the effective privileges of the spoofed UID (typically a higher-privileged user).
Last updated