Challenge: Fittyfit
Author: d1l3mm4
Description: Download sensitive files using race conditions and info leaks
CTF: Faust CTF 2022
Category: A/D Web Service
Warning: unintended solution here :p
This challenge presents itself as a web service where to generate and exchange “NFTs”.
Here we can upload a pdf, set some attributes to tag it, transfer it to other users and download your files.
We focused our attention on the first of these steps.
When you generate a new NFT, there are two steps involved:
Upload the pdf file
Add the tags to the file
Between these steps, the file is in the data/nft/generator folder, waiting for it to be edited and moved to the data/nft/<username>/<hash>/ path.
During this time, the file is accessible by anyone, i.e. there isn’t any access control on data/nft/generator folder, where files are temporarily stored awaiting for further processing. The only thing to know to query a file from there is the actual name of the file.
By looking at the traffic capture related to bot interaction with the service within a tick, we can see that the bot awaits some time between the file upload and the nft generation, maybe we’re lucky enough to try and read the file while it is still “processing”.
We’ve also noticed that the filename of the flag has the same UUID as the username of the bot who created it.
Knowing this, we can use another endpoint ( /search ), tied to the transfer functionality, needed to implement the auto-complete front-end function on the “target username” field in the form.
By making the following request to the endpoint: /search?s=MrFlag_, we obtain a list of the bot’s accounts.
With this, we have all the info needed to try to get the desired file.
Now, all we need to do is writing the exploit and hope for the best (in a busy network this approach is not very reliable).
We’ll start by creating a new user and signing in. After that, we’ll poll the search endpoint, looking for new bots registered.
When we find one, we start to poll the endpoint nft?file=generator/FlagNFT_{bot-UUID}.pdf, hoping to find a file to download.
If so, then we can read its content using a python library like PyPDF2 and with that we’re ready to submit the flag.
For this exploit we used two scripts, a multi-threaded one to dump pdf files to the local folder, and another one which makes polling on the folder to find new pdf files, read the contents of each one, submit flags and move them to another folder.
We managed to get ~300 attack points on this service during the CTF, running the script for 4 hours.
We provide here only the exploit stub of the first script and the complete second script.
The first one: