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

HA: Natraj Vulnhub Walkthrough

tentonnesofgold

Deep Web Investigator
T Rep
0
0
0
Rep
0
T Vouches
0
0
0
Vouches
0
Posts
151
Likes
47
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
Today weā€™re going to solve another boot2root challenge called ā€œNatrajā€. Itā€™s available at Vulnhub for penetration testing practice. This lab is not difficult if we have the right basic knowledge to break the labs and are attentive to all the details we find during the reconnaissance. The credit for making this lab goes to Hacking Articles. Letā€™s get started and learn how to break it down successfully.

Level: Not defined

Since these labs are available on the Vulnhub website. Letā€™s download the lab file from here.

Penetration Testing Methodology

Reconnaissance

  • Netdiscover
  • Nmap

Enumeration

  • Dirb
  • LinEnum

Exploitation

  • RCE with LFI and SSH Log Poisoning

Privilege Escalation

  • Abuse of Apache configuration file permissions
  • Abusing SUDO
  • Capture the flag

Walkthrough

Reconnaissance

Like always we will identify the hostā€™s IP with the ā€œNetdiscoverā€ tool.

Code:
netdiscover

1.png


So, letā€™s start by listing all the TCP ports with nmap.

Code:
nmap -sV -sC -p- 192.168.10.156

2.png


Enumeration

We started by visiting the web service (port 80), where we have found several pictures and information about the Natraj, we will check the source code and robots.txt, it seems that there is nothing useful. (or at least, for the moment). So letā€™s proceed further.

3.png


With the help of Dirb and itā€™s default dictionary, we have found a directory called ā€œconsoleā€œ.

4-a.png


We go in and list a file called ā€œfile.phpā€œ:

4.png


If we execute it, we see that it does nothing. We probably need to add something else šŸ˜‰

5.png


Now I decided to use the same file name as the ā€œGETā€ variable and try to do a proof of concept (POC) to check if the site was vulnerable to Local File Inclusion (LFI).

6.png


Exploiting

After examining I found that it was vulnerable and that the site was using an Apache server, I tried to perform an RCE (Remote Command Execution) by poisoning the Apache log, but I was not successful.

After further testing of other options, I saw that I do have the Access to the ā€œauth.logā€ file, where SSH service logs appear.

Malicious sending:

7.png


Response from the server:

8.png


After this, we can try writing PHP code inside the SSH command for the connection:

9.png


We make another request, this time we indicate in the variable a ā€œidā€ and check that it is indeed vulnerable.

10.png


Great! now, weā€™ll put a listening netcat on port 1234 and run the command to get the reverse Shell.

11.png


We will pass this line to URL-Encode:

12.png


And we will send the request as shows in image below:

13.png


If everything went well, we will have a reverse shell with the user ā€œwww-dataā€:

14.png


We execute the following commands to get an interactive shell.

15.png


We use the tool ā€œLinEnumā€ and see that we have to write permissions in the file ā€œ/etc/apache2/apache2.confā€.

16.png


Privilege Escalation (user)

I downloaded the file in my machine and edited these lines, specifying the username ā€œmahakalā€.

17.png


We set up an HTTP server with Python, Download the file to the machine and replace the original.

18.png


Now, weā€™ll have to create a reverse Shell in PHP so that when we will run it, we take control of it as the user ā€œmahakalā€.

19.png


This web Shell will be hosted in the directory ā€œ/var/www/htmlā€œ.

20.png


Now weā€™ll put a Netcat to listen on port 5555.

21.png


Weā€™ll reboot the machine and run the ā€œshell.phpā€ file:

22.png


We go back to our shell with Netcat and check that we are already inside the machine with the user account ā€œmahakalā€.

23.png


Privilege Escalation (root)

We do a ā€œsudo -lā€ and see that we have permission to run the nmap binary as root and without a password.

24.png


We return to execute the necessary commands to get an interactive shell.

25.png


The idea is to raise a shell as root, for this we will put the command in a variable and then we will call it with nmap emulating a script, we can do it in the following way.

26.png


And having already hijacked the root account, we only have to read the flag and complete this great machine.

27.png


Author: David UtĆ³n is Penetration Tester and security auditor for Web applications, perimeter networks, internal and industrial corporate infrastructures, and wireless networksContact on LinkedIn.
 

442,401

317,942

317,951

Top