Adhyan Agarwal logoadhyan agarwal
BACK TO ARCHIVE
HTB|2023.12.09

Surveillance — Craft CMS CVE-2023-41892 RCE to ZoneMinder sudo zmupdate Root

OS

Linux

Difficulty

Medium

Category

WEB

Released

2023.12.09

Exploited an unauthenticated Craft CMS RCE (CVE-2023-41892) for a www-data shell, found a database backup in Craft's storage directory, and cracked Matthew's raw SHA-256 hash to SSH in. Pivoted into an internal ZoneMinder instance over an SSH tunnel, got a zoneminder shell via command injection (CVE-2023-26039), then abused a NOPASSWD sudo rule on zmupdate.pl whose unsanitized --user argument runs a command substitution as root to drop a SUID bash.

Want to try this box yourself?

Spoiler-free mode is on by default — every solution stays hidden behind a reveal. Peek the hints, attempt each step, then unlock the answer when you're stuck. Turn it off to read every solution inline.

Nmap

Full Port Scan

Script and Service Scan

Web Enumeration

Browsing to the web page, we are taken to a home security service website.

Surveillance home security landing page

Scrolling down shows that the website is powered by Craft CMS, and clicking the link takes us to the Craft CMS GitHub page.

Craft CMS footer credit

Craft CMS GitHub release page

The GitHub page also reveals the version of Craft being used in this instance.

Initial Foothold

Looking online for any public vulnerabilities, we find an unauthenticated remote code execution vulnerability, CVE-2023-41892, and this GitHub PoC.

We clone the repo.

We run the script and get a shell.

PoC returning a www-data shell

To get a proper reverse shell, we write a reverse shell to a file and execute it.

Interactive reverse shell as www-data

We upgrade to a TTY shell.

Lateral Movement

Looking around the web root directory, we find a SQL backup in the /html/craft/storage/backups directory.

To download this file to the attacker machine, we set up a Python HTTP server on the victim.

We unzip and inspect the file contents.

This file is a database backup and holds credentials for a user named Matthew B.

We use hashid to identify the type of the hash.

This is most likely raw SHA-256, so we crack it.

Cracked password for Matthew

We have a password but no username.

We try to SSH in with the username matthew.

SSH login as matthew

SSH works with the credentials matthew:starcraft122490.

sudo -l shows that the user matthew cannot run any command with sudo.

We look at the internal running services.

The only service that stands out is running on port 8080.

A cURL request shows that the internal service running is ZoneMinder.

ZoneMinder identified on port 8080

To access this from our attacker VM browser, we use local port forwarding.

Browsing to the page takes us to a login page.

ZoneMinder login page over the SSH tunnel

There are three users with shell access, and one of them is a ZoneMinder user.

Local users with shell access

Accessing the ZoneMinder config files in /etc/zm shows permission denied.

Trying default credentials like admin:admin does not work, but the credentials admin:starcraft122490 work to log into the dashboard.

ZoneMinder dashboard after logging in

The dashboard also reveals the version info of ZoneMinder.

We find a command injection CVE with this GitHub PoC.

We follow the instructions and get a reverse shell.

Reverse shell as the zoneminder user

Privilege Escalation

sudo -l shows a command that the user zoneminder can run as root with no password.

We look at all the zm*.pl files to see if anything is writable.

None of them are writable.

Grepping through the scripts for anything that shells out, zmupdate.pl stands out.

The --user argument is stored in $dbUser and concatenated directly into a mysqldump/mysql command string with no sanitization.

Since $command is passed to the shell, a command substitution in --user executes as root. Supplying --version=1 forces the upgrade path, and answering y to the backup prompt reaches the mysqldump sink.

The mysqldump call errors out, but the command substitution already ran as root, creating a SUID copy of Bash.

SUID bash giving an effective root shell

We grab the root flag.

Root flag on surveillance