Saturday, May 13, 2017

[Write Up] CTF ITobaFest 2017 - Rev 2







Task   :Disoalnya dikasih file berkestensi .pyc buat apa? direverse lah :( biar dapet flagnya :v


File : link

POC :

Pake command file di terminal linux bisa keliatan jenis filenya gan, jenisnya
python 2.7 byte-compiled.



Menggunakan tool bernama uncompyle2, ane melakukan proses decompile pada file python tersebut dengan command sebagai berikut:

uncompyle2  rev2.pyc

Hasil :


# 2017.05.13 18:03:01 WIB
#Embedded file name: medium.py
exec 'import re;import base64'
exec (lambda p, y: (lambda o, b, f: re.sub(o, b, f))('([0-9a-f]+)', lambda m: p(m, y), base64.b64decode('NSAzNwoKMWQgPSBbMjgsIDJjLCAyYiwgMWIsIDMwLCAxNCwgZSwgZSwgMjksIDJhLCBjLCAzNiwgMTMsIDI1LCAyZiwgMzEsIDcsIDM1LCAyMSwgMTYsIDgsIDMyLCAyMSwgMTUsIGQsIGQsIDEyLCA2LCBjLCAyMywgMzQsIDgsIDE3LCA2LCAyNywgMjQsIDMzLCAxMiwgMmUsIDJkLCA3LCAxYywgMjYsIDIyXQoKMTAgPSAiIgoxOCAxZSAxZiBhKDAsIDE5KDFkKSk6CgkxMCA9IDEwICsgMWEoMWUgXiAxZFsxZV0pCgpmID0gMygiMTE6ICIpCjIwICgzNy4yKDEwKSA9PSBmKToKICAxICI0ISIKYjoKICAxICI5ISI=')))(lambda a, b: b[int('0x' + a.group(1), 16)], '0|print|b64decode|raw_input|Correct|import|119|114|112|Wrong|range|else|68|65|64|f|s|Flag|72|105|104|125|126|122|for|len|chr|117|113|t|i|in|if|88|22|46|89|63|26|27|83|82|81|80|87|85|96|92|93|99|77|70|76|35|59|base64'.split('|'))
+++ okay decompyling rev2.pyc
# decompiled 1 files: 1 okay, 0 failed, 0 verify failed
# 2017.05.13 18:03:01 WIB


Output dari uncompyle2 ane simpan menjadi file baru, dan melakukan pengubahan yaitu mengubah sintaks exec didepan lamda menjadi print.


exec 'import re;import base64'
print (lambda p, y: (lambda o, b, f: re.sub(o, b, f))('([0-9a-f]+)', lambda m: p(m, y), base64.b64decode('NSAzNwoKMWQgPSBbMjgsIDJjLCAyYiwgMWIsIDMwLCAxNCwgZSwgZSwgMjksIDJhLCBjLCAzNiwgMTMsIDI1LCAyZiwgMzEsIDcsIDM1LCAyMSwgMTYsIDgsIDMyLCAyMSwgMTUsIGQsIGQsIDEyLCA2LCBjLCAyMywgMzQsIDgsIDE3LCA2LCAyNywgMjQsIDMzLCAxMiwgMmUsIDJkLCA3LCAxYywgMjYsIDIyXQoKMTAgPSAiIgoxOCAxZSAxZiBhKDAsIDE5KDFkKSk6CgkxMCA9IDEwICsgMWEoMWUgXiAxZFsxZV0pCgpmID0gMygiMTE6ICIpCjIwICgzNy4yKDEwKSA9PSBmKToKICAxICI0ISIKYjoKICAxICI5ISI=')))(lambda a, b: b[int('0x' + a.group(1), 16)], '0|print|b64decode|raw_input|Correct|import|119|114|112|Wrong|range|else|68|65|64|f|s|Flag|72|105|104|125|126|122|for|len|chr|117|113|t|i|in|if|88|22|46|89|63|26|27|83|82|81|80|87|85|96|92|93|99|77|70|76|35|59|base64'.split('|'))


Kemudian kami jalankan file tersebut, outputnya sebagai berikut :



import base64


t = [83, 87, 80, 117, 93, 104, 64, 64, 82, 81, 68, 59, 105, 63, 92, 99, 114, 35, 88, 126, 112, 77, 88, 125, 65, 65, 72, 119, 68, 46, 76, 112, 122, 119, 27, 89, 70, 72, 96, 85, 114, 113, 26, 22]


s = ""
for i in range(0, len(t)):
s = s + chr(i ^ t[i])


f = raw_input("Flag: ")
if (base64.b64decode(s) == f):
 print "Correct!"
else:
 print "Wrong!"



Didalam kode tersebut terdapat perulangan dengan variabel s serta kondisi if jika input sama dengan hasil variabel s yang sudah di decode maka akan menghasilkan output Correct.
Untuk mendapatkan flagnya, kami menambahkan kode sebelum f = raw_input (“Flag: “) yaitu :


print base64.b64decode(s)


Setelah dijalankan muncul flagnya yaitu : 


 ITobaFest{deobfuscate_the_snake}

Share:

0 comments:

Post a Comment

This Blog is protected by DMCA.com