Skip to main content

VULNHUB INFOSEC PREP : OSCP


Welcome to the walkthrough of InfoSec Prep: OSCP walkthrough. It is a beginner-level boot2root machine and it can be downloaded from here.

I cracked this machine literally 5 minutes after it booted properly. So you can consider this machine the easiest. 

Hint:

  1. Nmap
  2. Finding secret.txt and decoding it.
  3. Login via ssh.
  4. Privilege escalation to root via SUID binary. 


Boot up the machine and it should show the IP address.


We start off by pinging the box to verify that the box is up and running and we can reach out to it.
Command: ping <IP>


Then we can run Nmap scan to look for open ports and services running on the box.
We will use -sC for running default scripts, -sV for Version/Service info and -T4 for faster execution, and -o for saving the result on a file named nmap
The command is: sudo nmap -sC -sV -T4 <IP> -o filename


Looking at the scan results, port 22 is open and running ssh, and port 80 is open, and it's running Apache.
We can also see a directory named secret.txt as a disallowed entry in the robots.txt file. 

# Port 80 Enumeration


The web server has some content regarding the challenge that was released with the box.


But there's some useful info too. it tells you clearly that there is only one user on the box named "oscp".
So we know a username. Let's visit the secret.txt file that we found in the Nmap scans.


Looking at the content we see lots of text, but if you look it ends with "==" which means this may be base64 encoded. Copy the contents to your system and decode it using the command.
cat secret.txt |base64 -d



So it is a ssh private key. Now we have a username and a private key. Let's try logging in via ssh.
But first, remember to modify the permission for the private key.
Command: chmod 600 key
Log in via ssh: ssh -i key oscp@<IP>


And we log in successfully. Since we logged in as oscp we need to do some kind of privilege escalation to gain root access.

# Finding SUID binaries
Use the command: find / -perm -4000 2>/dev/null


We can see bash is set to SUID and abusing it is very easy.
Run the command bash -p and we are root.


Grab the root flag.

# Root via cronjob.
 If you visit the home directory of oscp user, there is a bash script named "ip" that's running as a cronjob. Since the file is in the user's home directory we can edit it and put our reverse shell into it and when cronjob runs we get a shell as the root user.
Add the reverse shell into the bash script.


Set up a Netcat listener to catch the reverse shell.
Command: nc -nvlp 1234


# Privilege Escalation by abusing lxd group.

First, we need to find the absolute path to lxc and lxd binaries to run the commands.



After the pool has been created we just need to run these commands on the victim.


And we are root users now.


Thanks for reading.

Comments

Popular posts from this blog

KIOPTRIX LEVEL 1 WALKTHROUGH WITH AND WITHOUT METASPLOIT

Kioptrix Level 1 is a beginner level CTF challenge. You can download this virtual machine from here .  Details of Kioptrix : Size----186 MB OS---Linux Note: In virtual box, set up a Bridged network (virtual box -> preferences -> network) in networking, put both your Kali and Kioptrix to Bridged network. Fire-up both the machines(Kali and Kioptrix Level 1) Kioptrix will ask for the logins which we don't know at the moment. This also means we can't find IP of the Kioptrix directly from the Kioptrix machine itself. Leave the Kioptrix machine as it is and switch to Kali. First we need to find the IP address of the Kioptrix machine. We will use the tool netdiscover that comes pre-installed in Kali Linux to identify the IP address. Command   sudo netdiscover -i eth0 Wait  for scan results. 192.168.233.130 seems to be the IP of the Kioptrix machine. Let's scan this IP address using the tool Nmap (scan will also verify that its the IP of Kioptrix machine) Command  sudo nmap

HTB GRANDPA WALKTHROUGH

HackTheBox  is an excellent platform for various pen-testers to increase their testing skills and knowledge. Machine Level -Easy Machine Name -Grandpa Machine OS -Windows Machine IP -10.10.10.14 Tools: Nmap  -Nmap is a fantastic tools for scanning the open ports, services and OS detection. You can use other tools other than nmap (which ever you are more comfortable with ) like masscan, SPARTA etc to scan for open ports. Metasploit  -One of the most common and widely used tool by pen-testers to launch exploits, it is maintained by Rapid 7 . Many books are available to understand the features of this tool. Method : Scanning the machine is the first step(i.e. Enumeration). We use the following nmap command, sudo nmap -T4 -p- -A 10.10.10.14 The command  scans for all ports(-p-) with threads speed 4 (-T4) and also gives you version details  (-A). So, only port 80 is open. Its says its running Microsoft IIS 6.0 , but first lets visit the victim's IP and see what's there