
Week 8. Blurry
TL;DR
This is a Debian 11 machine dedicated to train and deploy ML and LLM models. It runs a vulnerable version of CleanML which can be exploited to get an initial user shell. Regarding escalation, we abuse the deserialization feature of the Python PyTorch machine learning library.
KEYWORDS
CleanML, CVE-2024-24590, PyTorch, Pickle, insecure deserialization.
REFERENCES
https://www.cvedetails.com/cve/CVE-2024-24590/
https://github.com/xffsec/CVE-2024-24590-ClearML-RCE-Exploit
https://www.hackingarticles.in/python-serialization-vulnerabilities-pickle/
https://medium.com/@yulin_li/what-exactly-is-the-pth-file-9a487044a36b
https://docs.python.org/3/library/pickle.html
https://github.com/trailofbits/fickling
ENUMERATION
Port scan.
Enumerate the open ports.
Add to hosts file and enumerate the site with Firefox. A ClearML web site appears, according to the developers site, this is "a platform to build, train, and deploy your AI/ML and LLM models".
USER
Look for ClearML vulnerabilities, there is this one here: https://www.cvedetails.com/cve/CVE-2024-24590/. And an associated exploit here: https://github.com/xffsec/CVE-2024-24590-ClearML-RCE-Exploit
In CleanML, open one the project "Black Swan" and click on "New experiment". You are presented instructions to configure a local clearml client.
Follow the instructions, first install clearml client.
Then run the configuration script clearml-init and paste the API configuration.
Now start a listener and run the exploit.py from the GitHub repository. Enter option 2 ("Run exploit"), then enter your IP and the listener port. Finally enter the project name, which is the one you used to create the experiment ("Black Swan" in this case).
Shortly after, a reverse shell for user jippity is received on port 1919.
To stabilize this shell we move to ~/.ssh folder and retrieve a private key, then use it to open an SSH session as user jippity
Which can be used to retrieve the user flag.
ROOT
Start from the jippity SSH session and take the opportunity to enumerate the user and the system.
User jippity may run the following sudo command on the host:
Basically, the user is allowed to run /usr/bin/evaluate_model as root with the .pth files located in the /models directory. No password will be prompted.
Enumerate the script /usr/bin/evaluate_model
We see the script checks input file (which is called "model file"), extracts it and run binary /usr/local/bin/fickling on it. Other interesting things mentioned are a library called PyTorch and a Python script located /models/evaluate_model.py
Enumerate the Python script.
Here we see more references to a library called torch, and a call to the function torch.load(model_path), which is executed on the input file (the "model file").
Now it is time to make some research on the things we have discovered. Long story short:
PyTorch is an open-source machine learning library for Python based on the
torchlibrary. When needed, it stores serialized data as.pthfiles. It uses the functionstorch.save()for serializing andtorch.load()for deserializing (https://medium.com/@yulin_li/what-exactly-is-the-pth-file-9a487044a36b).PyTorch functions rely on the Python
picklemodule, which is who actually implements the binaries for serializing and deserializing data (https://docs.python.org/3/library/pickle.html).Finally,
ficklingis a tool to manage Python pickle serialized objects (https://github.com/trailofbits/fickling).
With this in mind, it seems we should focus on finding vulnerabilities on the Python serialization/deserialization process (pickling). These are well explained here: https://www.hackingarticles.in/python-serialization-vulnerabilities-pickle/
In summary, custom pickling and unpickling code can be used with a method called __reduce__. I took the script published in the mentioned site and, after some modifications and testing, I found a workable malicious script.
The script was modified to add a call to torch.save() to serialize the data, and get rid of the pickle.dumps() function.
Save the script as ~/exploit.py and execute it to generate the serialized malicious model file exploit.pth
Now we have a malicious serialized payload in /models/exploit.pth. Start a listener and run it with sudo
A shell is received on port 1919.
You are root.
Last updated