NFS Root Squashing
no_root_sqush
Background Knowlege: no_root_squash
no_root_squash
Q: What is NFS?
A: Network File System (NFS) is an UDP-based RPC service. It allows remote hosts to mount file systems over a network and interact with those file systems as though they are mounted locally.
Q: What is root squash?
A: Root squash is a special mapping that maps remote root user (uid 0) to local "nobody" user (uid 65534), which has minimal privileges.
Q: What is no_root_squash
?
In the /etc/exports
file, if some directory is configured as no_root_squash
, then a remote root user will be mapped to local root user.
Q: How is this related to privesc?
Suppose we are the root user on our attack machine. We can mount this target directory on our attack machine and write to this directory as the root user on the victim machine. The attack plan is:
Mount the target directory locally
Create a privesc exploit as SUID binary in the local directory
Execute this privesc exploit on the victim machine
When we create the privesc exploit locally, this exploit will be created on the victim machine as a root-owned SUID binary simultaneously through NFS. Then we can execute this privesc exploit on the victim machine and get a root shell.
Enumeration
Examine /etc/exports
:
Suppose /tmp
has the no_root_squash
option turned on, then the victim machine is vulnerable to NFS root squashing:
On our attack machine, we can verify that the remote /tmp
directory is mountable:
Exploitation
Create a temporary directory on our attack machine.
Mount the target directory.
Prepare the privesc source code x.c
.
Compile the source code.
Turn on the SUID bit.
Trigger the payload on the victim machine.
Last updated