Hackthebox released a new machine called mentor. On this machine, first we enumerate the new vhost which gives the api documentation that lists all the endpoints. Then there we get the command injection and get the rev shell, find the creads of database dump the hashes from the database and get the user password from snmp config files and for root we have the permission to execute the sh binary.
Nmap
Nmap tell us there are two ports open 22:ssh, 80:http which is redirecting to mentorquotes.htb
Let’s add that in /etc/hosts file
Port-80
There is a simple web page, nothing much to do, I also try dirbusting but nothing found.
Let’s try to fuzz the new subdomain with wfuzz
Found one, let’s add that in /etc/hosts file
api.mentorquotes.htb
There is 404 page, nothing much, let’s try dirbusting to find some new endpoint.
Found some interesting endpoints Let’s go there one by one
/admin Tell us we need to authenticate first to access this endpoint.
/docs Tell us pretty much everything about every endpoint which is created on top of swagger module.
And we also see that the owner of the website is james and his email is james@mentorquotes.htb
Let’s try to sign up with help of documentation, but I like working in burp, so I capture the request in burp.
Created the account with random creads.
Now, let’s also capture the login endpoint request in burp.
And we got the JWT token.
I also capture the request of /users endpoint in burp, which will give the all users list.
But no luck this time, we got the 403 forbidden error which tell us that only admin can access this resource.
Let’s play with the /signup endpoint.
First I try to register with james user with his email which is admin of the website.
But that’s not working.
Now I change the email to that email which we register first time, and this time it’s working.
💡
It’s mean that it’s only validating the email that can’t be registered more
than one time but this is not the same case with username.
Now I try to log in with that same creads and we got the JWT token.
And this time we got the users list.
If you remember we found one endpoint called /admin which require authentication, let’s try this token with that endpoint.
And it’s works we got 2 new endpoints
/check
/backup
The /check endpoint is not implemented yet.
But the /backup endpoint tell us that the GET method is not allowed.
Let’s change the method of request.
And it’s tell us it’s want JSON object with body attribute
I add the empty JSON object and change the content type to application/json which give one more attribute to specify called path.
When I give both attribute it gives success message called `Done!“
Let’s try basic command injection with ping command, but first let’s start the tcpdump.
And the JSON object look like this.
Try a basic technique of command injection with ;
Let’s send the request and check the tcpdump.
And we got the ping back
Let’s try to get the rev shell.
And we got the rev shell back.
Inside the /app/app directory, I found db.py file, which has the PostgreSQL creads.
For interacting with PostgreSQL database, we need to forward the port with chisel
Let’s transfer the chisel binary.
Let’s start the chisel server on our kali box.
Now let’s connect the client with server on port 9002 which give access to 5432 port which is default port of PostgreSQL database.
Let’s connect the PostgreSQL database.
And we got the three hashes, one of the hashes is ours.
Crack the hash with crackstation and we got the svc user password called 123meunomeeivani
And we got the user.txt file.
Privilege Escalation
Running the linPEAS and we got the SNMP config file.
And we also see that it’s created recently.
And we also see that SNMP default port is open
Checking the snmpd.conf we got a password SuperSecurePassword123__
Try that password with james user and it’s works.
Checking the user if they have sudo privilege
And we see it’s run the /bin/sh binary with root privilege.