Valentine

Reconnaissance:

NMAP:

β”Œβ”€β”€(kaliπŸ’€kali)-[~]
└─$ sudo nmap -sC -sV -O 10.10.10.79

22/tcp  open  ssh      OpenSSH 5.9p1 Debian 5ubuntu1.10 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   1024 96:4c:51:42:3c:ba:22:49:20:4d:3e:ec:90:cc:fd:0e (DSA)
|   2048 46:bf:1f:cc:92:4f:1d:a0:42:b3:d2:16:a8:58:31:33 (RSA)
|_  256 e6:2b:25:19:cb:7e:54:cb:0a:b9:ac:16:98:c6:7d:a9 (ECDSA)

80/tcp  open  http     Apache httpd 2.2.22 ((Ubuntu))
|_http-title: Site doesn't have a title (text/html).
|_http-server-header: Apache/2.2.22 (Ubuntu)

443/tcp open  ssl/http Apache httpd 2.2.22 ((Ubuntu))
|_ssl-date: 2024-01-03T06:05:58+00:00; -3s from scanner time.
|_http-title: Site doesn't have a title (text/html).
|_http-server-header: Apache/2.2.22 (Ubuntu)
| ssl-cert: Subject: commonName=valentine.htb/organizationName=valentine.htb/stateOrProvinceName=FL/countryName=US
| Not valid before: 2018-02-06T00:45:25
|_Not valid after:  2019-02-06T00:45:25

No exact OS matches for host (If you know what OS is running on it, see https://nmap.org/submit/ ).
TCP/IP fingerprint:
OS:SCAN(V=7.94SVN%E=4%D=1/3%OT=22%CT=1%CU=35325%PV=Y%DS=2%DC=I%G=Y%TM=6594F
OS:94C%P=x86_64-pc-linux-gnu)SEQ(SP=104%GCD=1%ISR=10C%TI=Z%CI=Z%II=I%TS=8)S
OS:EQ(SP=105%GCD=1%ISR=10D%TI=Z%CI=Z%TS=8)SEQ(SP=106%GCD=1%ISR=10E%TI=Z%CI=
OS:Z%II=I%TS=8)OPS(O1=M53AST11NW4%O2=M53AST11NW4%O3=M53ANNT11NW4%O4=M53AST1
OS:1NW4%O5=M53AST11NW4%O6=M53AST11)WIN(W1=3890%W2=3890%W3=3890%W4=3890%W5=3
OS:890%W6=3890)ECN(R=Y%DF=Y%T=40%W=3908%O=M53ANNSNW4%CC=Y%Q=)T1(R=Y%DF=Y%T=
OS:40%S=O%A=S+%F=AS%RD=0%Q=)T2(R=N)T3(R=Y%DF=Y%T=40%W=3890%S=O%A=S+%F=AS%O=
OS:M53AST11NW4%RD=0%Q=)T4(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T5(R=Y%D
OS:F=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)T6(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O
OS:=%RD=0%Q=)T7(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)U1(R=N)U1(R=Y%DF
OS:=N%T=40%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G%RUD=G)IE(R=Y%DFI=N%T=40
OS:%CD=S)

Network Distance: 2 hops
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Enumeration: HTTP TCP Port 80

http://10.10.10.79/ view-source:http://10.10.10.79/

It only contains a picture (which is a big indication of the vulnerability we’ll find) and no other links. So we’ll have to run Gobuster.

/index, /omg and /server-status lead nowhere. /encode and /decode seem to be scripts that encode and decode strings. /dev on the other hand proves to be interesting.

http://10.10.10.79/dev/

http://10.10.10.79/dev/notes.txt 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.

http://10.10.10.79/dev/hype_key

Enumeration: SSH TCP Port 22

It contains a string that is hex encoded. Let’s use an online tool to convert it to text. We find out that it is an RSA private key!

Take the converted text format and save it into a hype_key file. Disclaimer: You should NEVER enter your or anyone else’s credentials in online tools just in case it gets logged at the backend! In this case, it doesn’t matter since this is a fake security assessment.

We’ll try and ssh using our newly found private key. Based on the naming convention of pub/priv keys, β€œhype” is likely the username.

-i: Selects a file from which the identity (private key) for RSA authentication is read.

I get back the following error.

Since a private key is equivalent to a password, it should only be readable by you. We resolve the error using the following command.

However, we are prompted for a password that we still don’t have and so we need to do more enumeration.

Enumeration: HTTPS TCP Port 443

https://10.10.10.79/

Run nmap’s vulnerability scan script to determine if any of the services are vulnerable.

Port 443 is running a version of OpenSSL that is vulnerable to Heartbleed!

If you don’t know what that is, here’s a great comic explaining it. It is essentially a vulnerability in the popular OpenSSL cryptographic software library. This vulnerability allows anyone on the Internet to read the memory of the systems protected by this vulnerable version of OpenSSL. This can lead to the compromise of secret keys, passwords, information, etc. It also allows attackers to eavesdrop on communications. There’s a whole site dedicated to the heardleed bug.

Heartbleed exploit

Now that we know for sure that port 443 is running a vulnerable version of OpenSSL, let’s try and exploit it to gain an initial foothold on the target machine.

First, get the exploit

Run the script to view the help instructions.

Let’s run the exploit with a loop number of 10. We might have to run the script multiple times or increase the loop size depending on how useful the content of the memory dump is.

We’re looking for hype’s passphrase so that we could SSH into his account. After rummaging through the memory dump, we find the following strings.

Someone used the decode.php script on the website to decode a string of characters. Copy the string and use the site to decode it.

This looks like a password! Let’s use it to ssh into hype’s account.

Privilege Escalation

In the attack machine, start up a server in the directory that the script resides in.

In the target machine download the script.

We get back many results of which two are interesting.

First, it’s running an old version of Ubuntu that is probably vulnerable to DirtyCow. Dirty COW is a privilege escalation vulnerability which exploits a race condition in the way the Linux kernel’s memory subsystem handles the copy-on-write (COW) breakage of private read-only memory mappings.

Second, there’s an active tmux session that is owned by root.

It’s essentially a shell that is owned by root! So if we can enter this active tmux session, any command we run there is executed with root privileges. This one I didn’t figure out on my own, I had to use

Alright, so we have two ways of escalating privileges.

Privilege Escalation #1: Dirty COW Vulnerability

To confirm that the target machine is vulnerable to Dirty COW, download the Linux Exploit Suggester script. In the attack machine, start up a server in the directory where the script resides.

Download the exploit on your target machine.

Clone the exploit on the attack machine.

Start up a server in the directory where the exploit resides.

Compile the file as per the included compile instructions.

Run the exploit.

Choose the password for the newly created user.

Change to the newly created user.

su firefart

Privilege Escalation #2: Attach to Root Owned tmux Session

In the target machine, attach to the tmux shell using the following command.

Since this is a session owned by root, we have root privileges!

Last updated