by
Giulio "Krishath" De Pasquale
on June 12, 2015
under PlaidCTF2015
9 minute read ·
Me and my team, Tower of Hanoi, have played the PlaidCTF 2015: while my teammates did reversing stuff, my friend john and I did this awesome forensic challenge.
This was the challenge description:
We received this PNG file, but we’re a bit concerned the transmission may have not quite been perfect.
It was easy to understand we had to repair a PNG file, but first, we checked what we had in our hands. So, we ran file on the challenge file:
corrupt_735acee15fa4f3be8ecd0c6bcf294fd4.png: data
The file was, in fact, corrupted since it wasn’t recognized as a PNG image. The next step was to recreate the correct PNG header in our file, which should have been
0x89 0x50 0x4E 0x47 0xD 0xA 0x1A 0xA instead of 0x89 0x50 0x4E 0x47 0x0A 0x1A 0x0A, the actual header of our challenge’s file.
With the help of a hex editor we added the missing 0x0D byte, renamed the file and…
solution.png: PNG image data, 960 x 600, 8-bit/color RGB, non-interlaced
Bad news ahead: by opening the image we were greeted by a fantastic 960x600 black image. Not bad. Some of the PNG chunks must have been corrupted as well then.
Before going further with the challenge details, I’d like to quickly summarize how a PNG file actually is.
A PNG image has a lot of blocks, called chunks, which have the same structure:
The most important one, which actually represents the image, is called IDAT.
Now: we made a strong assumption.
Every chunks’ checksum and length section weren’t altered at all (in this way we could understand what was the original content of the data block in each chunk)
With the aforementioned assumption in our mind, we checked if any chunk had an unexpected checksum: pngcheck helped us doing this.
There were several corrupted IDAT chunks so we wrote a script to bruteforce the missing bytes of each chunk.
What we thought was: the LENGTH section indicates how many bytes should have been in the chunk in the first place so we compared that value with the actual length of the corrupted image DATA section.
We wrote the script and… it took a lifetime. No results. Much joy.
When our hope was gone and our PCs were slowly turning in frying pans, esseks another awesome teammate, came to the rescue.
Guys, text conversion.
Which meant: why would you bruteforce everything?
When an image is downloaded as text through FTP (ASCII Mode), each 0x0D 0x0A bytes tuple (\r\n) is truncated to 0x0A.
Long story short, here’s what we did next:
Edited the script making it output the offset in the file where the 0x0D byte should have been appended
Waited for the script to do its magic
Edited by hand the PNG image (sad but true)
Did we succeed?
PS: I know that some of you was wondering how wonderful our script was…so… have a good headache after it ;-)
PlaidCTF, Forensics, PNG, 2015
We feedback.
Let us know what you think of this article on twitter @towerofhanoi or leave a comment below!
On October 14th and 15th 2022 we participated in the Reply Cyber Security Challenge 2022. We solved many challenges and overall placed second (CTFtime). These are the writeups of the...
Continue Reading