Precious
PDFkit and Deserialization.
PDFkit and Deserialization.
Nmap Scan:
Seems like a web vulnerability exploit kinda machine.
Website to PDF ind of functions run on plugins, and depending on the language used to do this conversion (JS, PHP), there are exploits for them.
For instance, we can redirect this website to our own hosted HTTP server and convert that. Alternatively, attempts can be made in order to exploit the website via LFI to read the files on the machine.
For enumeration purposes, I began by generating a PDF and downloading it to my machine from this website. We can enumerate the PDF to see if there is a particular software being used.
This version of pdfkit is vulnerable to RCE using CVE-2022-25765. There are public exploit scripts available for this.
Following the exploit, we can test to see if we indeed have RCE:
Works! Now we just need to gain a reverse shell. I used a simple bash shell to do so.
When we gain access as the user ruby, the flag is not there. There is another user named henry in this machine.
We don't have permissions to read the flag from henry's directory. However, when poking around ruby's directory and looking into the .bundle directory, we can find henry's password.
With this, we can SSH in as henry for a better shell. Then, we can grab the user flag.
Checking sudo privileges, we find that henry is able to execute the following:
Intriguing. The script is as shown below:
From the looks of this script, YAML.load function is being used. There are certain deserialization exploits for this. The attack is known as 'YAML Deserialization'
Hacktricks has a relevant page covering it.
When searching along the lines of Ruby deserialisation attacks through YAML.load, I found this article which included a PoC.
How this works is thorugh implementing a gadget chain that was previously used with other Ruby YAML exploits. This basically gives us RCE over the machine as root.
We just need to put the malicious YAML file in some writeable place and execute it. Works because the script does not check for an absolute path. Here's the PoC:
I changed the command to chmod +s /bin/bash
and tried it out. Worked!
Rooted!