Soccer
8th December 2022 / Document No D22.100.219
Prepared By: C4rm3l0
Machine Author: sau123
Difficulty: Easy
Classification: Official

Synopsis
Soccer is an easy difficulty Linux machine that features a foothold based on default credentials, forfeiting
access to a vulnerable version of the Tiny File Manager , which in turn leads to a reverse shell on thetarget system ( CVE-2021-45010 ). Enumerating the target reveals a subdomain which is vulnerable to ablind SQL injection through websockets. Leveraging the SQLi leads to dumped SSH credentials for theplayer user, who can run dstat using doas - an alternative to sudo . By creating a custom Python plugin

for doas , a shell as root is then spawned through the SUID bit of the doas binary, leading to fully
escalated privileges.

Skills Required
Basic web enumeration
Basic Linux enumeration

Skills Learned
Identifying blind SQL Injections
Leveraging SUID binaries to escalate privileges

Enumeration

Enumeration
Nmap
ports=$(nmap -p- --min-rate=1000 -T4 10.10.11.194 | grep '^[0-9]' | cut -d '/' -f 1 |tr '\n' ',' | sed s/,$//)
nmap -p$ports -sC -sV 10.10.11.194

Scanning the target with Nmap reveals three open TCP ports. The first two are occupied by SSH andNginx , both of which running on their default ports. The last open port is 9091 , which is running an

unknown service.

HTTP
Browsing to port 80 redirects us to the domain soccer.htb .

We proceed to add the domain to our /etc/hosts file and refresh the page.
echo "10.10.11.194 soccer.htb" | sudo tee -a /etc/hosts

The web app appears to be a static page, without any functionality. We run a directory scan using gobuster
to find any potentially interesting files.
gobuster dir -u http://soccer.htb -w /usr/share/wordlists/dirbuster/directory-list-2.3medium.txt

Our enumeration yields a /tiny directory, which when navigated to shows a login panel to a file manager.

A search for the keywords tiny file manager reveals a GitHub repository, which in turn divulges thedefault administrative credentials for the service, namely admin:admin@123 .
We log in successfully and land on the file manager's dashboard, which also reveals the service's version,
namely 2.4.3 . As a quick search reveals, Tiny File Manager <= 2.4.6 allows remote attackers withvalid user accounts to upload malicious PHP files to the webroot and achieve code execution on the target
server, which is also known as CVE-2021-45010 .

The tiny folder contains an uploads directory, to which we have write permissions.

With that in mind, we can try uploading a php reverse shell.

We fire up a listener on port 4444 and can trigger the reverse shell by navigating to/tiny/uploads/shell.php .

nc -nlvp 4444

We successfully get a shell as www-data .

FootholdHTTP
Enumerating the target system as the www-data user yields no interesting vectors or files, however,remembering that the web application is running on Nginx , we take a look at the sites-enabled directoryfor possible subdomains that weren't detected during our initial enumeration:

We add the newly discovered subdomain to our /etc/hosts file and proceed to browse to it.
echo "10.10.11.194 soc-player.soccer.htb" | sudo tee -a /etc/hosts

The site appears similar in form to the initial static page, however, we see that it has some addedfunctionality in the form of a Login and Signup button. Attempting to log in with typical admin credentials
returns no results, so we use a newly registered account to log into the site, revealing the /check page.

We are provided with a ticket id, as well as the possibility to check whether a given ticket is valid or not.
Looking at the site's source code reveals that this functionality is based on a WebSocket server running on
port 9091 , which we also found during our enumeration:<script>
var ws = new WebSocket("ws://soc-player.soccer.htb:9091");
window.onload = function () {var btn = document.getElementById('btn');
var input = document.getElementById('id');
ws.onopen = function (e) {console.log('connected to the server')}
input.addEventListener('keypress', (e) => {keyOne(e)});<...SNIP...></script>

In order to efficiently enumerate the functionality of the service, we intercept a request using BurpSuiteand send it to the Repeater for further analysis. By manipulating the input, we discover that mathematicaloperations have no impact on whether the ticket is deemed valid or not. This leads us to suspect that thesite's logic extracts the submitted value and compares it to a database. To verify our hypothesis, we inject
an SQL boolean payload of OR 1=1 and observe the response, which confirms that the ticket is consideredvalid. This suggests that the form is vulnerable to SQL injection attacks.

Blind SQLi
The vulnerability we found is also known as a blind SQL injection, as we can inject SQL logic, but cannot
directly see or access any of our queries' output. We must therefore use indirect methods to determine theoutcome of our queries, such as observing changes in the server's behavior or responses to different
inputs. Fortunately, sqlmap can automate this task for us as it can directly access the WebSocket service
on port 9091 , given that we provide it with the necessary parameters for its queries.
sqlmap -u "ws://soc-player.soccer.htb:9091" --data '{"id": "*"}' --dbs --threads 10 -level 5 --risk 3 --batch

After a few minutes sqlmap successfully dumps the database names, with the more interesting candidate
being soccer_db . We can then directly target that database and dump its contents, using the -D and -dump flags, respectively.

sqlmap -u "ws://soc-player.soccer.htb:9091" --data '{"id": "*"}' --threads 10 -D
soccer_db --dump --batch

The database is dumped successfully, revealing the credentials player:PlayerOftheMatch2022 , which we
can use to SSH into the box.

The user flag can be found at /home/player/user.txt .

Privilege Escalation
SUID (setuid) is a Unix-based security mechanism that allows executables to be run with the privileges of thefile's owner. This is useful for executables that need to access system resources or perform actions that are
typically restricted to privileged users, such as changing system settings or accessing other users' files.
However, it also presents a potential security vulnerability because it allows attackers to escalate theirprivileges on a system by exploiting SUID executables.
Looking for files with the SUID bit set, we stumble upon the /usr/bin/doas binary, which is an alternative
to the more commonly used sudo binary:find / -type f -perm -4000 2>/dev/nullA quick search for doas reveals that its configuration file can be found at /usr/local/etc/doas.conf ,which in turn reveals that the player user can run dstat with elevated privileges, as the binary is owned
by root .
cat /usr/local/etc/doas.conf

Dstat is a tool for generating system resource statistics. Taking a look at its manual shows a handful ofinteresting information, most importantly revealing the possibility of using Python plugins for the tool.
man dstatIf we can execute Python code as the root user, we could spawn a shell with the elevated privileges intact.
Although dstat plugins can only be hosted in certain directories, we have write access to one of them,which is /usr/local/share/dstat . This means that we can potentially exploit this access to execute
arbitrary code as the root user.

We create a Python script that spawns a bash shell, and save it in the above directory, making sure toprefix it with dstat_ , as per the manual.
echo 'import os; os.system("/bin/bash")' > /usr/local/share/dstat/dstat_pwn.py

To verify that the plugin is detected by dstat , we run the command with the --list flag.
doas /usr/bin/dstat --list

Finally, having confirmed that our plugin is detected, we run dstat and specify the plugin by passing it as acommand line argument, using a -- prefix.
doas /usr/bin/dstat --pwn

Our payload successfully triggered, and we have obtained a shell as root . The final flag can be found at/root/root.txt .