Inspecting the source code I found what seems to be the source code:
So I downloaded the files and I inspected them. I discovered some documentation inside /docs, which are about interacting with its API:
While reading the docs I noticed that you apparently have some private access in the api (inside /api/priv), so you can perform registration and login to the API to access that endpoint.
As you can perform authentication, I decided to check inside the downloaded files in spite of some credentials:
There is a .git subfolder, so Iโll check the git logs:
โremoved .env for security reasonsโ gives me some bad ideas :)
So I checked that specific commit:
Iโve found a mongodb access token: gXr67TtoQL8TShUc8XYsK2HvsBYfyQSFCFZe4MQp7gRpFuMkKjcM72CNQN4fMfbZEKx4i7YiWuNAkmuTcdEriCMm9vPAYkhpwPTiuVwVhvwE
Now I also inpected the commit โnow we can view logs from server ๐โ:
Inspecting this code we can notice a command injection vulnerability in the git log --oneline ${file}. We can access to a new endpoint called /logs.
Now, inspecting again the source code I noticed that for the authentication there is a auth.js where jwt tokens are in use:
The docs also explain to us how it works:
Exploitation
So itโs time to create an account using the instructions using Postman.
First, I created my account.
Then I logged in to get my access token:
So my token is currently: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2NzY5MzQ2ZmY3NmI3NjA0NWQxYTQ3M2QiLCJuYW1lIjoiZ2l0YmxhbmMiLCJlbWFpbCI6ImdpdGJsYW5jQGdpdGJsYW5jLmNvbSIsImlhdCI6MTczNDk0ODAyMX0.kvQOonU3kTtSk79yObABGlqVoVq5fhd_bUkeUEbFxH4
Now we can check our privileges:
Now I can use the provided example of jwt token to craft the valid one by pasting it on the online tool:
So we finally got theadmin token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2MTE0NjU0ZDc3ZjlhNTRlMDBmMDU3NzciLCJuYW1lIjoidGhlYWRtaW4iLCJlbWFpbCI6InJvb3RAZGFzaXRoLndvcmtzIiwiaWF0IjoxNjI4NzI3NjY5fQ.52W5mGLsIO2iiLpy3f1VkVavP4hOoWHxy5_0BDn9UKo
Now, we can check the /api/logs endpoint:
We will now exploit the command injection vulnerability by appending ?file;id:
Itโs time to get a reverse shell:
I got user flag :D
Privilege Escalation
Searching for SUID binaries I found a weird one: /opt/count:
If we inspect the /opt directory we can find some weird files too:
This is the code.c content:
It seems to be a binary that basically counts words inside a file:
The binary is using core dumps to extract the contents of the files:
So my plan is to read the SSH key from root and crash the application before the file handler gets destroyed. When the application crashes a core dump file will be created at /var/crashes and we can unpack it using apport-unpack . To crash the application all we have to do is sent a SIGSEGV signal to the application. So, we execute the application, prompt it to read /root/.ssh/id_rsa key file, background it, sent the appropriate signal and when we bring the application to the foreground it will crash and create a core dump file:
A core dumped has been created:
Now, we can use apport-unpack and strings to get the root SSH key:
Got root access and root flag :D
Note
We could have also just read /root/root.txt instead of the private root ssh key, but itโs better to gain remote access