HackTheBox Writeup - SmartHire
HackTheBox Writeup - SmartHire
Target IP: 10.129.245.215 Difficulty: Medium OS: Linux
1. Reconnaissance
Nmap Scan
1
2
3
4
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.9p1 Ubuntu 3ubuntu0.15 (Ubuntu Linux; protocol 2.0)
80/tcp open http nginx 1.18.0 (Ubuntu)
|_http-title: Did not follow redirect to http://smarthire.htb/
Subdomain Discovery
Adding smarthire.htb to /etc/hosts and further enumeration/research reveals the subdomain models.smarthire.htb. This subdomain hosts an MLflow instance (v2.14.1), which is accessible using common credentials admin:password.
2. Initial Access (Foothold)
Vulnerability: CVE-2024-37054 (Insecure Pickle Deserialization)
MLflow version 2.14.1 is vulnerable to insecure deserialization in its pyfunc model flavor.
Exploitation Steps:
- Create a Run: Create a new experiment run via the MLflow API to get a
run_id. - Generate Malicious Pickle: Craft a
python_model.pklthat executes a reverse shell (or command) using the__reduce__method. - Upload Artifacts: Upload the malicious
python_model.pkland a descriptorMLmodelfile to the run’s artifact directory. - Register Model: Register the poisoned run as a new model version for the user’s company-specific model name (found via the
/model_infoendpoint on the main dashboard). - Trigger: Use the “Make Predictions” feature on
smarthire.htb/predict. When the application loads the registered model version, the pickle is deserialized, executing the payload.
User Flag: e050f6c4315dfface834893b3af85b65
3. Privilege Escalation
Vulnerability: Python Module Hijacking
Checking sudo -l for the svcweb user:
1
(root) NOPASSWD: /usr/bin/python3.10 /opt/tools/mlflow_ctl/mlflowctl.py *
The script /opt/tools/mlflow_ctl/mlflowctl.py uses site.addsitedir() on the /opt/tools/mlflow_ctl/plugins/ directory.
Exploitation Steps:
- Check Permissions: The
svcwebuser is in thedevsgroup, which has write access to/opt/tools/mlflow_ctl/plugins/dev/. - Hijack Path: Create a
.pthfile (e.g.,exploit.pth) in thedevplugin directory. Python executes code inside.pthfiles during path initialization. - Execute Sudo: Run the allowed sudo command:
1
sudo /usr/bin/python3.10 /opt/tools/mlflow_ctl/mlflowctl.py status - Root Access: The malicious code in the
.pthfile runs as root.
Root Flag: c4b5a954abfe4718f345a18e22459dc8
This post is licensed under CC BY 4.0 by the author.