Basic enumeration got us a .ssh folder with a rsa key!
We will transfer it to our local host and use it to ssh to jippity with it.
PRIVILEGE ESCALATION:
After using ssh to log in, let's continue further with our enumeration so that we can obtain root: sudo -l
We can run anything in that folder by sudo with NOPASSWD and we can also write new files to that folder.
After I analyzed the evaluate_model.py script and checked some of the PyTorch docu and common vulnerabilities, I stumbled on Pickle (again) with __reduce__
Basically Pickle is used for serialization and deserialization (converting to bytes back and forth) for memory performance capabilities. If we check Pickle's Docu we will see that __reduce__ will let us provide more args, therefore we can launch arbitrary commands:
This is the payload I used for PrivEsc:
Run it via python3 pickled.py. Move the evil.pth to /models.
Set up a listener in a new tab of the terminal and: run sudo /usr/bin/evaluate_model /models/evil.pth on the target host.
$ ls -la /models
total 1068
drwxrwxr-x 2 root jippity 4096 Sep 14 07:06 .
drwxr-xr-x 19 root root 4096 Jun 3 09:28 ..
-rw-r--r-- 1 root root 1077880 May 30 04:39 demo_model.pth
-rw-r--r-- 1 root root 2547 May 30 04:38 evaluate_model.py
The `__reduce__()` method takes no argument and shall return either a string or preferably a tuple (the returned object is often referred to as the “reduce value”). […] When a tuple is returned, it must be between two and six items long. Optional items can either be omitted, or None can be provided as their value. The semantics of each item are in order:
- A callable object that will be called to create the initial version of the object.
- A tuple of arguments for the callable object. An empty tuple must be given if the callable does not accept any argument. […]