BunyIP
Gaining Access
Nmap scan:
$ nmap -p- --min-rate 3000 192.168.233.153
Starting Nmap 7.93 ( https://nmap.org ) at 2023-06-30 15:55 +08
Nmap scan report for 192.168.233.153
Host is up (0.17s latency).
Not shown: 65531 filtered tcp ports (no-response)
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
3306/tcp open mysql
8000/tcp open http-altWeb Enum -> Hash Extension
Port 80 had a website that looked rather static with nothing interesting about it:

All of the links led to Lorem Ipsum related stuff, which is definitely not the exploit path we are looking for.
On the other hand, port 8000 contained something more interesting:

This seems to be a 'secure' way to run NodeJS code within the browser. This program checks for whether the signature (which is the MD5 Hash of API-KEY | CODE. We don't know the API key, and we only know the code to be run.
I viewed the traffic in Burpsuite, and when we press the 'submit' button for the default code generated, it produces this:

The sig part is obviously the signature being used, and the code part is our Javascript code in base64. This looks to be a cryptography based challenge, and let's gather the facts we know:
MD5 is the hash signature used.
Users control the
CODEportion of the plaintext.Since we control the
CODEportion, we definitely would know the length of the second part of the plaintext.We cannot get the API Key in anyway.
Based on the example API-key that they gave us, it is 37 characters long and in the exact same format. So we also know the length and format of the API key from the example alone. Also, it is computationally infeasible to brute force the API-key since there are 37 characters and is too long.
We know the correct signature generated from the default code generated when we load the page.
This combination of facts makes this application vulnerable to a hash extension attack.
There are a few repositories present for this attack, and this one works the best:
The above repository takes the current hash and current message (which is the default signature and code upon refreshing the page) and allows us to append additional code to the default code while generating a valid hash based on the format of the API key.
Our script can also include a small requests portion that is able to sent the code for us.
TLDR, here's my exploit script:
The code I appended is just a JS reverse shell. Running this would give us a shell:

Privilege Escalation
The shell can be uploaded by dropping our SSH public key into the authorized_keys folder of arnold.
Sudo Safe-Backup -> File Write
I checked our sudo privileges, and found this:
There's a wildcard present, which is never a good thing. When we run it, the program gives us the Github repository it is from:
Reading the repository, it seems that this file takes a file as input and either encrypts or decrypts it. The encryption is rather useless for privilege escalation, since it uses a secure method to encrypt files that we probably cannot break.
The same cannot be said for the decryption. Since we can run this as the root user on the machine, we can actually replace files with this method. All we have to do is encrypt some files on our Kali machine, transfer the encrypted file to the machine, then decrypt it there and overwrite any existing files.
We can generate a key pair using ssh-keygen and also create an authorized_keys file:
We can then download the compiled binary for secure-backup on our machine:
Then, we can create a backup of the SSH keys we just created and rename the directory appropriately:
Afterwards, we need to create a symbolic link to /root/.ssh as -root-.ssh in order to have the decryption overwrite the actual /root/.ssh. This is because when we decrypt the files, it would generate a new directory like this one containing the keys:
Run the following commands:
After this is done, we can ssh in as the root user:

Rooted!
Last updated
