Fatty HTB writeup

Fatty is an insane rated box in Hack the Box, it was extremely fun to do even though it took me ~50 hours of work to root it. This box will make you reverse engineer a java client and a server, write some code and learn how symlink really works behind different technologies.
Got some coffee and get ready to enjoy this master piece.
Enumeration
First things first, so Nmap gave us an FTP server with anonymous access allowed, also some other ports that nmap wasn't able to discover what was running on it.
Foothold
Nmap told us the FTP service allowed anonymous access, is time to connect and see whats on the files
First text file suggest the server has some kind of vulnerability and they changed default connection port but the fatty-client was updated with such changes.
Second note told us they are using Java version 8
Third note gave us login credentials.
One we gathered some information, first tried to directly connect with fatty-client which gave us connection error since the port whose trying to connect was not opened.
Reverse engineer and rebuild package
At this point only thing we where able to do is to decompile the .jar package with jd-gui program and export the resulting contents into our computer.
First thing we need is to create a correct maven package layout. To do this copy pom.xml and pom.properties from META-iNF/maven/fatty-client/fatty-client into package's root directory.
Next move all contents from htb to src folder (create it)
Copy the following files from package root into a new resources folder.
As we saw in the notes.txt, the server port was changed to 1337, then modify resources/beans.xml and change port to 1337
Last step is to build the package with maven, it needs to be done with java version 8.
Add server.fatty.htb to /etc/hosts.
Run the client and connect to the server using credentials from note3.txt
After enumerating the server with qtc permissions, we saw the following file which informs qtc that only his user is enabled and all admin users removed, this is useful information for later steps.
Contents of -> mail -> dave.txt
Directory Traversal
At this point we had no idea of how to proceed as we still missing some server behavior knowledge prior exploitation of other vulnerabilities.
Now is time to check if directory traversal was a thing and it was, we were able to see some other files in a previous directory, but due some server side input validation only a single directory traversal was possible.
In the traversed directory with ..///////// payload we can see a file called fatty-server.jar
Modify src/htb/fatty/client/methods/Invoker.java, might need to import some other classes at the begining of the java file.
Modified code for directory traversal file listing
Modified code for file download
Compile the client with maven again, login and click filebrowser on any folder, then click open.
At this point fatty-server.jar file should be already downloaded
Decompile server contents with jd-gui.
Some of the main thing noticed was a database connection.
Also on checkLogin method we can see an SQL injection was possible as no input sanization was done.
SQL injection
At first tried many different SQLi payload but got no success, so build a local lab to emulating server side code and client connections.
After a few hours analyzing server responses and modifying client code, got a sucess SQLi.
This is the Client method we have to bypass src/htb/fatty/shared/resources/User.java As we can see client side code will create a hash of username:password+string so our payload was not being executed properly.
Then found out I could send the hashed string of my choice directly modifying client side code.
Below is the code used to pass the hashed password instead of the generated in User.user method src/htb/fatty/shared/message/LoginMessage.java
All this information was after hours of debugging locally, this write up is not a step by step guide but rather a how to do some parts. You might need to investigate a bit more the code to fully understand and fix the code.
The payload used on username during logging was this, password field could be left empty as we hardcoded the hash in code.
The payload will return looked up server side data from the database and hardcode a role value with 'admin', this way we got admin role on the app without breaking other people fun changing content on the database.
And we got a successful login with admin privileged.
Java object serialization + RCE
Reviewing server side code was very clear that RCE was through object de-serialization on changePW method but the method was not fully implemented in client side code.
Now is time to make the client change password work to pass a new password in the client GUI src/htb/fatty/client/gui/ClientGuiTest.java
And modify the changePW method to not encode the input and directly pass our base64 encoded payload src/htb/fatty/client/methods/Invoker.java
At this point we were able to pass a base64 encoded payload during password change, but we still need to find a proper payload.
So at pom.xml in server source we saw commons-collections 3.1 library is used.
Then used ysoserial java app from github to create the payload with a reverse shell using CommonCollections7 and encoded in base64.
Right after sending the payload on new password during password change, we got a reverse shell as qtc user inside a docker container.
Local enumeration
After some hours enumerating locally and trying different exploits, found out with pspy64 an scp was being done every minute from a different host.
Privilege escalation
At this point a lot of work to understand the behaviour was required to get privesc on the other host.
The behavior of all this part was:
First upload a tar file, inside the tar a file called the same way
logs.tarwith a symlink pointing to/root/.ssh/authorized_keysThe server extract the tar file and our new
logs.tarfile with the symlink replaces its own name with the link to authorized_keysThen upload an authorized_keys file with same name as the link (Not a real tar file, just text file with tar extension)
While scp'ing on the server it will follow the link
At this point
/root/.ssh/authorized_keysis a link from tologs.tarwith our public key on it giving us root access into the box.
First create a logs_key.tar file with public key contents
Create a link called logs.tar pointing to root authorized_keys, and compress it as .tar
Inside the container download both files and remove existing logs.tar file.
First step in this privesc is to put the link, copy link tar as original name logs.tar and wait a minute.
At this point the link might be created, clean previous logs.tar and replace it with our key file
We can see the files were copied two times
Root
After the second logs.tar is downloaded, we can SSH into the box as root user.
Great, we rooted Fatty
To me this was one of the best boxes I've did on Hack the Box and the one on which I've spent more time until now (~50h).
Even though, it was fun and not the kind of boxes looking for unknown things
Regards
Last updated
Was this helpful?