Skip to content

Mentor — HackTheBox (write-up)

Difficulty: Medium Box: Mentor (HackTheBox) Author: dsec Date: 2025-01-02


TL;DR

SNMP with community string internal leaked an API key. Accessed a FastAPI docs endpoint, used the API to get a JWT, then triggered a backup endpoint for command injection into a Docker container. Pivoted to Postgres for a password hash, cracked it, then SSH'd as svc. Found SNMP config with root's password for sudo escalation.


Target info

  • Host: 10.129.228.102
  • Vhost: api.mentorquotes.htb

Enumeration

Nmap results

Web page

Directory fuzzing

SNMP walk with community string internal:

time snmpbulkwalk -v2c -c internal 10.129.228.102

SNMP results

SNMP leaked key

Found API key: kj23sadkj123as0-d213

Vhost discovery

Discovered api.mentorquotes.htb, added to /etc/hosts.

API page

API endpoints


Foothold

Found /docs endpoint (FastAPI Swagger):

FastAPI docs

User james@mentorquotes.htb visible. Used /auth/login:

Login attempt

JWT token

Got JWT: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...

API with JWT

Used the JWT with various API requests (/users, /admin/backup) and iterated until finding a command injection point:

Command injection

Used Python reverse shell from revshells.com (escaped double quotes):

Reverse shell

No bash available:

No bash


Lateral movement

Container environment

uvicorn was running with --reload, meaning changes to the API auto-apply.

Postgres connection

Connected to Postgres with default creds postgres:postgres. Found password column in the database that wasn't exposed via the API:

Database dump

Password hashes

Hash cracking

Cracked passwords

Postgres tables

\list showed mentorquotes_db.

Cracked hash: 53f22d0dfa10dce7e29cd31f4f953fd8 -> 123meunomeeivani

ssh svc@mentorquotes.htb

SSH as svc


Privesc

Checked SNMP configuration:

cat snmpd.conf | grep -v "^#" | grep .

snmpd.conf

Found: SuperSecurePassword123__

Root via sudo

Used the SNMP config password with sudo su for root.


Lessons & takeaways

  • SNMP community strings beyond public/private (like internal) can leak sensitive data -- always brute-force community strings
  • FastAPI /docs endpoint exposes the full API spec including hidden admin routes
  • Docker containers often have default Postgres credentials and can be pivoted through
  • SNMP configuration files (snmpd.conf) can contain reused passwords