NSSCTF_Re_[NISACTF 2022]ezpytho
每天一道CTF题,第一天.
一道py逆向,
附件是exe,
pyinstaller打包,用pyinstxtractor反汇编成py源码
可以看到这里有许多文件,但是这个叫src的文件很特别
pyc文件需要用Easy Python Decompiler v1.3.2来反汇编,不出意外的话,前面某篇应该有下载地址
但是这个文件直接反汇编是会失败的,因为少了Magic value
注意看src.pyc文件下面有个struct.pyc文件,依稀记得这个是打包时候的工程文件
(10条消息) windows下py文件打包成exe和exe解包出py文件_叼不起的烟斗的博客-CSDN博客_py打包exe
这篇博客讲的很清楚
只需要把struct文件E3前面的复制到src文件上就可以成功反汇编:
反汇编成功
得到源码:
# File: s (Python 3.4) import rsa import base64 key1 = rsa.PrivateKey.load_pkcs1(base64.b64decode('LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlFcVFJQkFBS0NBUUVBcVJUZ0xQU3BuT0ZDQnJvNHR1K1FBWXFhTjI2Uk42TzY1bjBjUURGRy9vQ1NJSU00ClNBeEVWaytiZHpSN2FucVNtZ1l5MEhRWGhDZTM2U2VGZTF0ejlrd0taL3UzRUpvYzVBSzR1NXZ4UW5QOWY1cTYKYVFsbVAvVjJJTXB5NFFRNlBjbUVoNEtkNm81ZWRJUlB2SHd6V0dWS09OQ3BpL0taQ082V0tWYkpXcWh3WGpEQgpsSDFNVURzZ1gyVUM4b3Bodnk5dXIyek9kTlBocElJZHdIc1o5b0ZaWWtaMUx5Q0lRRXRZRmlKam1GUzJFQ1RVCkNvcU9acnQxaU5jNXVhZnFvZlB4eHlPb2wwYVVoVGhiaHE4cEpXL3FPSFdYd0xJbXdtNk96YXFVeks4NEYyY3UKYWRiRE5zeVNvaElHaHYzd0lBVThNSlFnOEthd1Z3ZHBzRWhlSXdJREFRQUJBb0lCQURBazdwUStjbEZtWHF1Vgp1UEoyRWxZdUJpMkVnVHNMbHZ0c1ltL3cyQnM5dHQ0bEh4QjgxYlNSNUYyMEJ2UlJ4STZ3OXlVZCtWZzdDd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2h2M3dJQVU4TUpRZzhLYXdWd2Rwc0VoZUl3SURBUUFCCi0tLS0tRU5EIFJTQSBQVUJMSUMgS0VZLS0tLS0K')) def encrypt1(message): crypto_text = rsa.encrypt(message.encode(), key2) return crypto_text def decrypt1(message): message_str = rsa.decrypt(message, key1).decode() return message_str def encrypt2(tips, key): ltips = len(tips) lkey = len(key) secret = [] num = 0 for each in tips: if num >= lkey: num = num % lkey secret.append(chr(ord(each) ^ ord(key[num]))) num += 1 return base64.b64encode(''.join(secret).encode()).decode() def decrypt2(secret, key): tips = base64.b64decode(secret.encode()).decode() ltips = len(tips) lkey = len(key) secret = [] num = 0 for each in tips: if num >= lkey: num = num % lkey secret.append(chr(ord(each) ^ ord(key[num]))) num += 1 return ''.join(secret) flag = 'IAMrG1EOPkM5NRI1cChQDxEcGDZMURptPzgHJHUiN0ASDgUYUB4LGQMUGAtLCQcJJywcFmddNno/PBtQbiMWNxsGLiFuLwpiFlkyP084Ng0lKj8GUBMXcwEXPTJrRDMdNwMiHVkCBFklHgIAWQwgCz8YQhp6E1xUHgUELxMtSh0xXzxBEisbUyYGOx1DBBZWPg1CXFkvJEcxO0ADeBwzChIOQkdwXQRpQCJHCQsaFE4CIjMDcwswTBw4BS9mLVMLLDs8HVgeQkscGBEBFSpQFQQgPTVRAUpvHyAiV1oPE0kyADpDbF8AbyErBjNkPh9PHiY7O1ZaGBADMB0PEVwdCxI+MCcXARZiPhwfH1IfKitGOF42FV8FTxwqPzBPAVUUOAEKAHEEP2QZGjQVV1oIS0QBJgBDLx1jEAsWKGk5Nw03MVgmWSE4Qy5LEghoHDY+OQ9dXE44Th0=' key = 'this is key' try: result = input('please input key: ') if result == decrypt2('AAAAAAAAAAAfFwwRSAIWWQ==', key): print(decrypt1(base64.b64decode(decrypt2(flag, result)))) elif result == key: print('flag{0e26d898-b454-43de-9c87-eb3d122186bc}') else: print('key is error.') except Exception: e = None try: pass finally: e = None del e
在代码后面单独插一句:
可以得到true key
使用这个key再次运行就可以得到真正的flag:\
flag:
flag{5236cb7d-f4a7-4080-9bde-8b9e061609ad}