Network File Sharing (NFS)
Sharing a fileserver over the network sometimes allows you to upload files as root and escalate privileges
Finding NFS folders
To find a list of all configured NFS folders, just look in the /etc/exports
file.
This file shows the directories paths and the rules for sharing. An example would be the following:
The danger here is the no_root_squash
option. If you see this, it means that any files uploaded here will keep their root privileges. We can abuse this to upload programs that can be run as root on the target machine.
Finding NFS folders from the outside
We can also find these locations from our host machine, but without the rules associated with them. Using the showmount -e
command, which will show a list of folders like this:
Uploading a SUID binary
The trick to exploiting this is to upload a SUID binary that executes the code we want. Then we can run it as the user we have on the target system and elevate ourselves to root privileges.
We'll start by connecting to the target machine, by mounting it to a local folder. First, make a folder somewhere that will be mounted to the target. Then mount it using the mount
command to one of the target's folders with the no_root_squash
set. Finally, to make it easier for myself, I change the owner of the target_tmp
directory on my host to my own user, because we created it with sudo
.
Tip: You can view your active mounts by looking at your /proc/mounts
file. Then when you want to disconnect you can unmount the directory with the umount
command.
Now the target_tmp
folder is connected to the target machine's /tmp
directory. Then we can start creating the malicious binary, that executes the /bin/bash
command for example.
Then we can compile it into the target directory. Make sure you use sudo
for the gcc
command to ensure that the file owner is root when we upload it.
Finally, we need to set the SUID bit on this binary, to make sure that when we execute it our privileges get set to root.
Now if we look from the target machine, we see that we have created a shell
program that is owned by root, and has the SUID bit set (seen by the s
in the permissions).
This means we can now just run the /tmp/shell
program on the target with our low-privilege user, to get a root shell.
Last updated