Writeup: Pragyan 2019 - Magic-PNGs
Information
- category: forensics
- points: 100
Description
Magic PNGs:
Can you help me open this zip file? I seem to have forgotten its password. I think the image file has something to do with it.
Writeup
We have a zip file, and a PNG corrupted file that has the password to decrypt the zipped file.
If we launch pngcheck
to check the correctness of the image, we get the following output :
1 | you_cant_see_me.png: CORRUPTED by text conversion |
That’s because the first bytes (which defines the file type) don’t correspond to the PNG file signature. To correct the first bytes we can use an hex editor like hexer
or ghex
, and change :
89 50 4E 47 2E 0A 2E 0A
to
89 50 4E 47 0D 0A 1A 0A
To check the first bytes use this command :
xxd -l8 you_cant_see_me.png
To recheck the correctness of the file I launch the command pngcheck
:
1 | pngcheck -vf image.png |
We have an error in the offset 0x00113
in the idat
chunk. Feh confirms that it is a CRC error :
1 | feh image.png |
To recover the right CRC we can use PCRT, but it gives us some errors :
1 | [Finished] Correct PNG header |
But if we change in the file using an hex editor idat
to IDAT
we can correct the CRC using PCRT, so we need to change at line 00000110
the hex from :
0016 6969 6461 7478 dadd 1d89 b6aa 384c
To :
0016 6949 4441 5478 dadd 1d89 b6aa 384c
And then run :
python pcrt.py -i image.png -o correct.png
And we get :
which has the mirrored string :
h4CK3RM4n
If we do the md5hash of the string, we can unzip the file.
unzip -P $(echo -n "h4CK3RM4n" | md5sum | cut -d ' ' -f1) tryme.zip
Flag
pctf{y0u_s33_m33_n0w!}