4 minutes
Hack the Box - Precious - Write Up
Enumeration
Initial scan using nmap:
Just port 80and 22open.
HTTP - 80
The initial step involved setting up the DNS entry for precious.htb, allowing me to access the address through my browser.

I executed whatweb for web enumeration:
Despite further enumeration with tools such as gobuster, nikto, and nmap using the vunls script, I couldn’t identify any clear entry points.
Inspecting the source code of the page also yielded no significant insights.
The site offers a functionality to convert web addresses into PDF. I tried converting several random web pages, but as the target machine lacked internet access, all attempts failed. Subsequently, I initiated a local HTTP server using Python and attempted to convert a local URL.

The tool successfully converted my local URL into a PDF, which I then downloaded for analysis.

Exploit
Upon using the exiftool, I identified the underlying tool for this conversion as pdfkit v0.8.6. Researching this version led me to discover the vulnerability CVE-2022-25765 associated with it.
Exploiting this vulnerability was straightforward. After starting the local HTTP server again, I initiated a local port using netcat and dispatched the payload via curl.
The payload is as follows:

Local Enumeration
Having obtained a shell, my immediate objective was to retrieve the user flag. Unfortunately, the user ‘ruby’ lacked the necessary permissions to access the file.
Further manual enumeration revealed user credentials stored in the ruby home directory:
SSH
Using the obtained credentials, I established an SSH connection to the machine and successfully accessed the user.txt flag:

Privilege Escalation
Closer examination indicated that the user ‘henry’ could execute /usr/bin/ruby /opt/update_dependencies.rb with sudo privileges:

After attempting various methods to escalate to root and researching online, I identified a vulnerability associated with the YAML load file function deserialization present within the /opt/update_dependencies.rb file.

Executing this file with sudo privileges initially resulted in an error due to a missing dependencies.yml file. In response, I created the required file and embedded a Ruby payload.
I modified the payload to gain the necessary root permissions and utilized it to initiate a reverse shell session with elevated privileges. Ultimately, with root access in hand, I accessed and read the flag located within the root directory.

Having gained access to the passwd file, I surmised that there was a potential avenue for escalating privileges to root. Multiple strategies could be pursued at this juncture. I could have attempted to decrypt the shadow file or modify permissions in the root directory. However, I opted to initiate a reverse shell session with root privileges using a Ruby payload.
To facilitate this, I opened a port on my attacking machine and modified the payload to execute the reverse shell.
Upon obtaining root access, I successfully retrieved the flag from the root directory.

