Search

Type to search posts.

es
HackTheBox: Curling

HackTheBox: Curling

Junior Restituyo
0xR3iko

Curling is a very interesting easy machine which first challenges us with the Joomla CMS, followed by a privilege escalation with Polkit’s pkexec on Linux.

Enumeration

Nmap

Looking at the scan, we see that only ports 22 and 80 are open.

# Nmap 7.94SVN scan initiated as: nmap -p22,80 -sCV -n -Pn 10.129.150.135
Nmap scan report for 10.129.150.135
Host is up (0.095s latency).

PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)
80/tcp open  http    Apache httpd 2.4.29 ((Ubuntu))
|_http-title: Home
|_http-generator: Joomla! - Open Source Content Management
|_http-server-header: Apache/2.4.29 (Ubuntu)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

We go to the website hosted on port 80, where we find a blog.

The blog hosted on port 80

Web Enumeration

We enumerate the website and find that it is managed by Joomla.

Joomla! is a free and open-source content management system (CMS) for publishing web content.

bash
curl -s http://<DOMAIN>/ | grep Joomla

Confirming the site runs Joomla

Version:

bash
curl -s http://<DOMAIN>/README.txt | head -n 5

Reading the Joomla version from README.txt

Knowing the website uses Joomla, we found the administrator panel by going to /administrator.

The Joomla administrator login panel

We couldn’t find any credentials by bruteforcing, so we went in search of a user on the blog.

User Enumeration

On the main page we find a post made by a person who left their name, which hints at a username. The post also has the word curling2018 that looks a lot like a password, but it didn’t work.

Blog post hinting at a username and a possible password

Finally, we have a possible username: floris.

Identifying the username floris

We continued looking through the source code and saw a comment was left, pointing to a document. We open it and find what appears to be a base64-encoded string.

bash
echo Q3VybGluZzIwMTgh | base64 -d

Decoding the base64 string to reveal a password

Now we have a password.

Foothold

Now that we have access to the administrator panel, we can use several techniques to achieve RCE.

Logged in to the Joomla administrator panel

RCE

We go to Templates at the bottom left, under Configuration.

Navigating to the Templates section

Next, we click on the Templates option.

Opening the Templates list

We can choose the Protostar template for our purpose.

Selecting the Protostar template

Now let’s select a page to insert our webshell; for this we can use error.php.

Editing error.php inside the template

We insert our payload into the PHP code, then click Save & Close.

Inserting the PHP webshell payload

Using curl we execute our webshell.

bash
curl -s "http://10.129.81.108/templates/protostar/error.php?cmd=whoami"

Executing commands through the webshell

We list the folders on the server, find a single user in /home, and within it a password_backup file.

Finding the password_backup file in the user's home

Looking at its content, we find that it is a hexdump.

The password_backup file contains a hexdump

Inspecting the hexdump content

To obtain clear text, we used CyberChef. After passing the text through different decoding modes, we obtained what appears to be a text file with some content inside.

Decoding the hexdump with CyberChef

We tried this text with the user floris via SSH, and it worked.

Logging in as floris over SSH

Now we got our first flag.

User flag obtained

Privilege Escalation

For privilege escalation we start by noting that the user does not have permission to use sudo on the server.

The user cannot run sudo

Next, we notice that the kernel and sudo versions are outdated.

Outdated kernel and sudo versions

We found this version to be vulnerable to PwnKit: a self-contained exploit for CVE-2021-4034, a local privilege escalation in Polkit’s pkexec.

https://blog.qualys.com/vulnerabilities-threat-research/2022/01/25/pwnkit-local-privilege-escalation-vulnerability-discovered-in-polkits-pkexec-cve-2021-4034

For our purpose we used Metasploit.

Setting up the PwnKit exploit in Metasploit

After backgrounding a session, we use the cve_2021_4034_pwnkit_lpe_pkexec exploit, which directly gave us a session as root.

Getting a root session with PwnKit

Here we got our final flag.

Root flag obtained

Thanks for reading.