Adhyan Agarwal logoadhyan agarwal
BACK TO ARCHIVE
HTB|2022.11.26

Precious — pdfkit Command Injection to Ruby YAML Root

OS

Linux

Difficulty

Easy

Category

WEB

Released

2022.11.26

Exploited a URL-to-PDF feature backed by pdfkit 0.8.6 (CVE-2022-25765) for command injection, pivoted to henry via creds in a .bundle config, then abused a sudo Ruby script's unsafe YAML.load to deserialize a malicious dependencies.yml for root.

Want to try this box yourself?

Spoiler-free mode is on by default — every solution stays hidden behind a reveal. Peek the hints, attempt each step, then unlock the answer when you're stuck. Turn it off to read every solution inline.

Nmap

Web Enumeration

Pasted image 20260101175136

The Burp request shows that this is written using Ruby.

Pasted image 20260101175219

The FFUF scan does not show anything interesting:

Testing for command injection, we see that we have command injection.

Pasted image 20260101180544

Pasted image 20260101180533

We stood up a Python HTTP server and used our machine's IP as a URL, and it downloaded a PDF on our computer.

Pasted image 20260102141331

The file just shows our directory where we stood up the Python server.

Pasted image 20260102141407

We then looked at the metadata of the file and see it was created by pdfkit v0.8.6.

Initial Foothold

Looking online about this version, we see there is a command injection vulnerability.

There is this CVE online.

Cloning the repo, we can use the exploit:

We have to start a listener:

Pasted image 20260102142414

Lateral Movement

In the home directory, we see a non-standard directory called .bundle.

In the directory, we see a config file:

This gives us what seems like henry's password.

Using the credentials above, we get a shell:

Privilege Escalation

Looking at update_dependencies.rb:

This reads from a file called dependencies.yml.

Trying to find the file:

Looking at the file:

We looked up yaml 0.1.1.

Nothing popped up, but some results did show for YAML deserialization.

The source code of update_dependencies.rb calls a dependencies.yml file, but there are no absolute paths, so it calls the dependencies.yml file in the directory we are currently in. So we can use the /tmp directory to create a dependencies.yml file and execute this.

PayloadsAllTheThings has a module on ruby deserialization on its website, which we can use.

First we have to determine the version of Ruby running on the server:

It is 2.7.4.

So we will use the 2.x-3.x payload:

This payload runs the id command.

First, we create a file named dependencies.yml in the /tmp directory:

Then we paste the payload above.

Then we run the command we got from sudo -l:

We get command execution as root.

Now we can edit the payload and add a reverse shell command so we can get a reverse shell as root.

The /tmp directory automatically clears all files periodically, so we need to create a new dependencies.yml file.

Start a listener:

We get a shell as root.

Pasted image 20260105151137 Pasted image 20260105151627