CozyHosting

$machine=10.129.84.247

sudo nmap -sS -Pn -p- $machine
Starting Nmap 7.93 ( https://nmap.org ) at 2023-10-17 00:09 CDT
Nmap scan report for 10.129.84.187
Host is up (0.055s latency).
Not shown: 65533 closed tcp ports (reset)
PORT   STATE SERVICE
22/tcp open  ssh
80/tcp open  http

Added the following to my etc/hosts:

$machine cozyhosting.htb

Reviewing the Site

Browsing around, we see there's a login page:

  • cozyhosting.htb/login

Browsing to the site and doing some recon, we can see it's created through the bootstrapmade and is using the NiceAdmin:

    <!-- =======================================================
    * Template Name: NiceAdmin
    * Updated: Mar 09 2023 with Bootstrap v5.2.3
    * Template URL: https://bootstrapmade.com/nice-admin-bootstrap-admin-html-template/
    * Author: BootstrapMade.com
    * License: https://bootstrapmade.com/license/
    ======================================================== -->

Additionally, looking through the page source code, we can see the login is using the POST method:

The main page for cozyhosting.htb is comprised of Ubuntu and Nginx on the backend:

![[Pasted image 20231017113654.png]]

Performing Site Scanning

Tried doing a spider crawl through ZAP, didn't really find too much, and didn't see anything super out of the ordinary.

One of my teammates used a tool called dirsearch, I went ahead and installed this through git clone and found some interesting directories such as:

  • /actuators/beans

Searching this specific directory, I found that beans is part of the Java Spring framework. From previous professional experience, I know there have been several exploits against this particular tool.

reference; https://docs.spring.io/spring-boot/docs/current/actuator-api/htmlsingle/

Looking through some of the output from dirsearch I checked:

  • http://cozyhosting.htb/actuator/sessions

Which gave me a result of:

  • {"99132C1A463C58EB494A4C8C14037620":"kanderson"}

This seems kind of peculiar, and looks like the first part might be a token to the user, kanderson's, session.

Searched for methods to hijack the potential JWT, no luck

Starting to go back through the login page to see if we are able to use SQLi to sign in, gain credentials.

Performing SQLi Payloads

Within Burpsuite, using Intruder > Sniper on the following page:

  • cozyhosting.htb/login

Using the wordlists from:

  • https://github.com/payloadbox/sql-injection-payload-list

None of the SQLi was successful (at this time.)

Reviewing Java Spring Boot

reference; https://www.veracode.com/blog/research/exploiting-spring-boot-actuators

  1. Remote Code Execution via /jolokia

    1. Unsuccessful

    2. The Jolokia library is not present

  2. Config Modification via /env

    1. Unsuccessful

    2. POST methods are not allowed

Reviewing Web Server info

Ran another NMAP scan to review what is running on port 80:

Running the following GET request in Burpsuite Intruder:

We receive something that seems to maybe indicate that the actuators are running on the nginx host itself:

Running the below request, we see that the spring boot version is:

  • application/vnd.spring-boot.actuator.v3+json

Session hijacking

Using the token from the user kanderson, we're able to replay this through the Burp Suite proxy, and gain access to cozyhosting.htb/admin

NOTE: Double check your token is correct, as they will refresh

After some tinkering, we see that there is some light arbitrary command execution in the username field within the POST request of the following:

Eventually we can use IFS (internal format separator) to remove any whitespace in our commands.

Testing for arbitrary code execution:

We received an interesting response:

Tried getting a reverse TCP Shell:

Tried URL-encoding to remove whitespaces, no luck:

One of my friends mentioned trying to use and set a variable through IFS, and after a few tries, it looked like we were getting somewhere:

Tried a few other directories for the -o parameter, but I received access denied.

AccessDenied

AccessDenied

Checked for /tmp/ and bingo:

response

My reverse shell script contained the following:

After a few failures of trying to use chmod +x to make the script executable, I tried alternative methods:

This landed our reverse shell, finally.

Privesc

Work on trying to upgrade our shell.

We can use which along with the following to see if we have methods of upgrading:

reference; https://zweilosec.github.io/posts/upgrade-linux-shell/

We login and we're the user app. From some enumeration methods we tried, we know that there is a directory for /home/josh, but we are unable to access it.

Starting to run through privesc opportunities from https://blog.g0tmi1k.com/2011/08/basic-linux-privilege-escalation/

I imagine there might be a method to try and pivot from app to the user profile. So I specifically started to look for SUID / GUID opportunities.

Worked through the following:

The responses for these commands were quite lengthy, nothing really seemed to stick out.

Continued through the SUID/GUID and sticky bits.

This found something slightly interesting, we can access /var/log/postgresql, given this is a web application, we might be able to review, dump a database.

Tried doing:

No luck.

No interesting GTFObins returned from:

Running

We again see some results containing postgres:

  • /run/postgresql

  • /run/posgresql/14-main.pg_stat_tmp

Start reviewing how to interact with posgres databases.

Pivoting around a bit, I ran find / -writable -type d 2>/dev/null, we were able to see that there's a share for /dev/shm, when we do ls /dev/shm/* we see there's a file named PostgreSQL.1814524994.

Apparently these were rabbit holes.

No Privesc needed yet

Reviewing a brief write-up, we see there were credentials in the file found in the directory you get your reverse shell in /app. The person whose write-up I reviewed mentioned you can find them via the tool jd-gui. This is a part of the Kali repository https://www.kali.org/tools/jd-gui/, but was not installed on my image.

Performed the following to pull and review the .jar file:

  • On my attacker machine executed sudo apt install jd-gui

  • Victim machine I used a Python simple server to move the file

    • cd /app

    • python3 -m http.server 9090

  • Once the server is setup, you can run curl or wget to retrieve the jar.

    • wget 10.129.209.88:9090/cloudhosting-0.0.1.jar

  • When the file is retrieved, you can do jd-gui & on your attacker machine

  • Within jd-gui, browse and open the cloudhosting*.jar file

Postgresql Enumeration

After we're able to retrieve the postgresql username and password from the .jar file we can run the following on the victim machine:

Then copy and paste the password we received from the .jar file. This will allow us to access the database.

After some brainless tinkering, I used the following to further assist with navigating the postgresql database:

https://stackoverflow.com/questions/34098326/how-to-select-a-schema-in-postgres-when-using-psql

Running the following I pivoted to what seems to be the password hash for kanderson and admin:

This returns the schema of the database. Unfortunately this wasn't super useful.

Running \l will return the databases from the schema, this is where things seemingly start to move forward.

We can then run \c cozyhosting to swap databases.

TLDR; Use the following to enumerate.

\dn # provide the schema of your database \l # list the databases within your current schema, this is is an l as in Lima \c <table name> # change databases \dt # list tables

Once the correct database is selected, we want to enumerate the tables.

These look like entries provided by /etc/shadow, from here we can try to use either hashcat or john to crack the potential passwords.

Doing some digging, we see that the cipher used for these is blowfish per the bcrypt documentation:

https://en.wikipedia.org/wiki/Bcrypt

Searched around online, and we can create a file on our attacker machine with the following format:

The previous format should work for john, went ahead and also tried hashcat as well. Since I seldom use these tools, I used the following to make sure my hash file format was correct:

https://hashcat.net/wiki/doku.php?id=example_hashes

Hashcat syntax as follows:

The file contained the following contents based off the above link for example hashes:

Further verifying some additional command parameters to use for john:

https://www.kali.org/tools/john/

We see we can use the following:

This will explicitly use the bcrypt format when sifting through possible matches which should expedite the decryption.

Once we receive the password we can go ahead and try to sign-in with the user we observed earlier during our enumeration during our proxy requests.

User

SSH to the victim with josh@<machine_ip> with the newly cracked password.

User flag obtained!

Enumerating to root

Performed the following quick checks:

No luck, try to review if we can run any commands as super user:

Bingo, we have a GTFObin here!

https://gtfobins.github.io/gtfobins/ssh/

That's a wrap on this box!