HTB Valentine: Heartbleed to Root via tmux Session Hijack

HTB Valentine: Heartbleed to Root via tmux Session Hijack

Begin by adding the target machine IP to /etc/hosts.

nano /etc/hosts
1.png

sudo nmap -sV -sC valentine.htb

2.png

I also conducted an NSE script scan against the vulnerable target.

sudo nmap -sV --script=vuln valentine.htb --max-rate=10000
3.png

Meanwhile, directory fuzzing also proved useful.

dirsearch -u http://valentine.htb -w /usr/share/dirb/wordlists/common.txt 
4.png

Let's check the /dev/ endpoint.

The directory contains two files, so I checked them.

5.png

In the notes.txt file, the author mentions a mechanism related to a key:

To do:

1) Coffee.
2) Research.
3) Fix decoder/encoder before going live.
4) Make sure encoding/decoding is only done client-side.
5) Don't use the decoder/encoder until any of this is done.
6) Find a better way to take notes.

Since the vulnerability is related to a key, and the Nmap results point to a Heartbleed-related vulnerability — as the default page also implies — I looked into the Heartbleed exploit.

6.png

I discovered a GitHub repo containing the related vulnerability PoC.

HeartBleed Exploit

Using the exploit as follows:

python2 heartbleed-poc.py 10.129.232.136 80

I was not able to run it via python3, so it most likely only works with Python 2.

The heartbeat response revealed a Base64-encoded string referencing decode.php.

7.png
$text=aGVhcnRibGVlZGJlbGlldmV0aGVoeXBlCg==

CyberChef automatically decoded the text.

8.png

I could not identify the format, so I passed it through DenCode.

DenCode

9.png

Now it is clear that the hexadecimal encoding reveals an SSH private key, but it still did not work directly.

Decoding HEX

Therefore, I used the following techniques to extract the SSH key.

DECODE HEX

xxd -p -r encoded_data.txt out.txt

# MAKE THE key CLEAR

openssl rsa -in out.txt -out clean_key

Then I used the extracted key to authenticate via SSH.

ssh -i clean_key [email protected]
10.png

Initially, I could not find a privilege escalation vector. I transferred linpeas.sh to the target to enumerate further.

11.png
12.png

In the linpeas.sh results, a tmux session was found running as root:

13.png
/usr/bin/tmux -S /.devs/dev_sess

Running the binary directly with the -S flag attaches to the root session.

14.png

Read more