SOS! Some crazy malware cropped all my gif collection! Hopefully, people say that this malware had some 0-day flaw.
Could you please recover my gif collection ?
gif0day-f34fed283522eb7e.task.brics-ctf.ru:50051
cd deploy
docker-compose -p ppc_gif0day up --build -d
Provide zip file from public/ and IP:PORT of the deployed app.
Recover original GIF frames from GIF cropped with acropalypse style vulnerability. Recognize chars from recovered frames, brute missing ones. Do this 100 times and get the flag.
We are given the gRPC service, that will 100 times do these steps:
- Generate random string (will be the flag at step = 100).
- Generate random salt.
- Calculate md5 hash of this string and salt.
- Create animated GIF image from the string, where 1 GIF frame = 1 character.
- Crop resulting GIF to 30x30.
- Send the cropped GIF bytes, hash and salt to the client.
- Wait for client reply with timeout=10s.
- Compare the client result with the string.
- Repeated step 1 until step > 100, or client wasn't able to answer.
From the source code we can see that cropping is done with the acropalypse-style bug: the file is not truncated after the crop, so the part of the original (not cropped) GIF file is still there.
As the cropped image is ~50 times smaller than original, most of the GIF frames can be safely recovered. To recover the gif, we can follow this steps:
- Read the cropped GIF from file to find where the 'trailer' (original GIF bytes) part begins.
- Read the trailer, find fully-recoverable frames by reading the frame information (extension block).
- Find the original image size, by reading each recovered frame size.
- Write the cropped GIF header with modified size.
- Write recovered frames.
This will give us the recovered GIF image. This image will have most of the frames (characters) recovered, but not all of them, so we need to brute-force the rest (knowing the hash, salt).
The solution algorithm:
- Get recovery request.
- Recover the GIF.
- Split the GIF into multiple frames.
- For each frame do:
- Remove image noise.
- Run OCR.
- Combine OCR results to get the answer suffix.
- Brute force the prefix and poorly recognized chars using the fact we know the answer salted hash and the salt.
- Repeat step '1' 100 times (last recovery request will have a flag).
- Guess the flag prefix — it's brics+{ (flag format).
gif0day-f34fed283522eb7e.task.brics-ctf.ru
brics+{gfQF2aN_g1f_Cr0P_brut3_xgRubfE}
No