adworld python-trade | python反编译

题目链接

附件是 .pyc 格式的文件。

Python程序中,原始程序代码存储在.py文件里,而Python会在执行.py文件的时候,会将.py形式的程序编译成中间式文件(byte-compiled)的.pyc文件,这么做的目的就是为了加快下次执行文件的速度。

由于Python的脚本特性,.pyc是可以很容易被反编译的(其实不能说是反编译,因为它就没被编译过),我们可以用 在线工具 将该文件逆向为如下python源码。

或者用 python-uncompyle6 工具,用法详见GitHub页面。

#python2
import base64
 
def encode(message):
    s = ''
    for i in message:
        x = ord(i) ^ 32
        x = x + 16
        s += chr(x)
 
    return base64.b64encode(s)
 
correct = 'XlNkVmtUI1MgXWBZXCFeKY+AaXNt'
flag = ''
print 'Input flag:'
flag = raw_input()
if encode(flag) == correct:
    print 'correct'
else:
    print 'wrong'

加密方式很明显了,加密后的密文也已经暴露,我们直接相反地改一下源码就可以得到明文(flag)了。

#python3
import base64

def decode(message):
    s = ''
    for i in message:
        x = i - 16 #python3不需要ord(i)
        x = x ^ 32
        s += chr(x)
    return s

correct = 'XlNkVmtUI1MgXWBZXCFeKY+AaXNt'

flag = decode(base64.b64decode(correct))
print(flag)
posted @ 2020-02-26 20:48  暖暖草果  阅读(274)  评论(0)    收藏  举报