Hack the Box is one of the cybersecurity upskilling platforms I use for professional development. Roughly once a week, Hack the Box releases a new vulnerable box for users to hack. Additionally, one active box is retired every week. Below is a walkthrough on compromising the recently retired box, “Precious.”
“Precious,” is hosting a website that offers a service to convert webpages to PDFs. During my investigation, I discover a command injection vulnerability in the tool used for this purpose. Exploiting this vulnerability, I gain a foothold on the box. By manually enumerating the box, I come across credentials stored in a configuration file for the user “Henry.” “Henry” has the privilege to execute a ruby script as root. Exploiting a deserialization vulnerability in this ruby script, I successfully obtain a root shell.
Port Scanning
nmap finds two open TCP ports, SSH (22) and HTTP (80).
The web server redirects to http://precious.htb.
Foothold
I add the domain precious.htb to /etc/hosts. This will allow me to enumerate the website.
Navigating to http://precious.htb in my browser I see I have the ability to convert a website to a PDF.
I set up a local web server hosting a simple page to explore this “Convert Web Page to PDF” feature.
The website returns a pdf of my simple webpage. Looking at the file properties I see pdfkit v0.8.6 was used to create the pdf.
CVE-2022-25765
Using google, I find that pdfkit v0.8.6 appears to be vulnerable to CVE-2022-25765. This particular CVE has a high EPSS score and CVSS score, increasing my confidence that it is the intended path to obtaining a foothold on the box.
EPSS: .092
EPSS Percentile: .94
CVSS Score: 9.8
KEV Catalog: No
Following the links provided by NVD above, I am able to find a POC for the vulnerability.
Vulnerability Description
An application could be vulnerable to a command injection if it tries to render a URL that contains query string parameters with user input.
PoC
Adjusting the PoC I get RCE with the following url.
http://10.10.14.8:9713/?name={%20`pwd`}
Enumerating applications I find python is available. I am able to get a remote shell with the following crafted url.
Upgrading my shell and manually enumerating the box. I find credentials for Henry.
Using the above credentials I can ssh into the box as henry.
Root
Listing the commands I can run as sudo I see I can run update_dependencies.rb as root.
Looking at update_dependencies.rb I see it call YAML.load(). In this instance YAML.load is vulnerable to a deserialization attacks.
Saving the following maliciously crafted yml file as dependencies.yml I will obtain root privileges.
Conclusion
“Precious” is an example of one of the many intriguing challenges available on Hack the Box. I intend to publish walkthroughs of future retired boxes as I continue using the platform to broaden my knowledge.
If you have any questions, or would like to discuss this topic in more detail, feel free to contact us and we would be happy to schedule some time to chat about how Aquia can help you and your organization.