SECCON 2014 quals # Binary – Reverse it

URL: http://score.quals.seccon.jp/question/
Type: crypto
Solution: SECCON{6in_tex7}
 


Description
Reverseit http://files.quals.seccon.jp/Reverseit


First we try to identify the type of the given file :

$ file Reverseit
Reverseit: data
$ hexdump -C Reverseit
00000000  9d ff 70 0d b6 da fc 93  72 63 28 22 22 bd d2 18  |..p.....rc(""...|
...
000013b0  02 02 02 02 02 02 02 02  02 02 02 02 02 02 02 02  |................|
*
00001ba0  02 02 02 02 02 02 02 02  02 02 02 02 02 e3 16 47  |...............G|
...
00001e00  84 00 84 00 10 10 10 00  64 94 64 a4 01 00 0e ff  |........d.d.....|
00001e10  8d ff                                             |..|

 
As the challenge name told us, we first try to reverse the bytes in the file:

00000000  ff 8d ff 0e 00 01 a4 64  94 64 00 10 10 10 00 84  |.......d.d......|
...

 
No success… Let’s try next taking into account high and low nibbles:

import sys
 
def swap_nibbles(byte):
  return ((byte<<4) | (byte>>4)) & 0xff
 
i=open(sys.argv[1], 'rb')
o=open(sys.argv[1] + '.rev', 'wb')
o.write(''.join(map(chr, map(swap_nibbles, map(ord, i.read()[::-1])))))
i.close()
o.close()

 

$ python rev_bytes.py Reverseit
$ file Reverseit.rev 
Reverseit.rev: JPEG image data, JFIF standard 1.01
$ hexdump -C Reverseit.rev
00000000  ff d8 ff e0 00 10 4a 46  49 46 00 01 01 01 00 48  |......JFIF.....H|
...

 
Let’s have a look at the image :
Reverseit.revSo, we also have to reverse the image:

import sys
from PIL import Image
 
i = Image.open(sys.argv[1])
o = Image.new(i.mode, i.size)
idata, odata = i.load(), o.load()
 
for y in range(i.size[1]):
  for x in range(i.size[0]):
    odata[x, y] = idata[i.size[0]-x-1, y]
 
o.save(sys.argv[1] + '.jpg')

 

$ python revh_image.py Reverseit.rev

 
We then obtain the following image which contains the flag SECCON{6in_tex7}:
Reverseit.rev.jpg

Programming is fun but lazyness is better! You can do the same with the following commands:

$ hexdump -ve '1/1 "%.2x"' Reverseit | rev | xxd -r -p > Reverseit.rev
$ convert -flop Reverseit.rev Reverseit.rev.jpg

 

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *


*

Captcha loading...