• We just launched and are currently in beta. Join us as we build and grow the community.

FourAndSix: 2 Vulnhub Walkthrough

sxn1a

Crypto Wallet Engineer
S Rep
0
0
0
Rep
0
S Vouches
0
0
0
Vouches
0
Posts
139
Likes
90
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 400 XP
FourAndSix: 2 is the sequel for previously solved vulnerable machine FourAndSix by Fred uploaded on vulnhub. It is not mandatory but is advised to read the prequel of this lab here. You can download the FourAndSix:2 vulnerable lab from here. The challenge is to become root and read flag.txt in the same directory.

Table of Contents:
  • Discovery of IP address.
  • Scanning for open ports and services.
  • Discovering universally accessible directory in the victim’s machine.
  • Cracking the password of archive found in the storage partition.
  • Reading the pub file and logging in using ssh.
  • Discovering utilities with sticky bit on them.
  • Using doas to get root.
  • Snagging the flag!
  • Let’s get started then.

The first step is, as usual, to find the IP of the target machine using netdiscover. In this case, it is 192.168.1.103

1.png


Next, we discover open ports and services using nmap.


Code:
nmap -A 192.168.1.103

The ports open were 22, 111, 2049.

2.png


There was only one way to proceed and that is port 2049. So, we used showmount command to check for NFS shared partitions.

Later, we mounted it under the folder name “raj” using the mount command. And we found a 7z compressed file.

Code:
showmount -e 192.168.1.103
mount -t nfs 192.168.1.103:/home/user/storage raj

3.png


But the file “backup.7z” was, unfortunately, password protected.

4.png


So, after trying out a number of options like John The Ripper and getting zero success, we found a site online to break its password.

The password was: chocolate

5.png


We extracted its contents in the same folder and found a few images along with RSA keys. As port 22 is running SSH service on the target machine, we can use RSA private key to login. We open RSA public key to taking a look at the username.

Code:
cat id_rsa.pub

6.png


We tried logging in to ssh but it was asking for a passphrase. So, we created the following script to find the correct password.

Code:
cat /usr/share/wordlists/metasploit/adobe_top100_pass.txt | while read pass; do if ssh-keygen –c –C "user@forandsix" –P $pass –f id_rsa &>/dev/null; then echo $pass; break; fi; done

8.png


From the id_rsa.pub file, we found the user for the secure shell of the victim and logged in to it. The password was: “12345678”.

Code:
ssh -i id_rsa [email protected]

We used the find utility to discover files or packages with SUID bit set on them.

Code:
find / -perm –u=s –type f 2>/dev/null

We found an interesting utility with SUID bit: /usr/bin/doas which is an alternate to sudo.

After reading the “doas.conf” file, we find that “less” can be run as root.

9.png


Let’s pick the configuration file and try to understand it word by word. Doas utility executes commands as other users according to the rules in doas.conf configuration file.

Permit/Deny: allows the rule.

Nopass: the user is not required to enter any password.

Persist: After the user successfully authenticates, do not ask for a password again for some time.

Keepenv: The user’s environment is maintained.

Cmd: command is allowed to run.

Since doas configuration file says that less can be run with no password at all as root with no password, it can be used for shell escaping.

Code:
doas /usr/bin/less /var/log/authlog

10.png


Enter v to escape to vi and then “:!sh” to escape to our brand new shell.

11.png


The final step was to snag the flag! It was in the root directory as told by the creator of the VM.

id shows that the shell is root shell and finally we read the congratulatory flag using cat!

12.png


So this was how we root the FourAndSix:2. Hope you liked it.

Author: Harshit Rajpal is an InfoSec researcher and a left and right brain thinker. contact here
 

434,295

313,335

313,344

Top