[GWCTF 2019]pyre
得到的是 .pyc 文件,需要转换成 .py 文件
可以通过在线网站转换
也可以使用 uncompyle6 库
pip install uncompyle6
uncompyle6 -o attachment.py attachment.pyc
打开得到的 .py 文件
可以看到逻辑如下:
(1)最终的输出的code,上面是一个for循环对code进行 code[i] = code[i] ^ code[i + 1]
处理
(2)在往上是将 input 的内容进行操作后,通过中间变量 num,再加到 code 上
因此我们直接逆着往回求,编写解密脚本
code = ['\x1f', '\x12', '\x1d', '(', '0', '4', '\x01', '\x06', '\x14', '4', ',', '\x1b', 'U', '?', 'o', '6', '*', ':',
'\x01', 'D', ';', '%', '\x13']
str1 = ''
for i in range(len(code) - 2, -1, -1):
code[i] = chr(ord(code[i]) ^ ord(code[i + 1]))
for i in range(len(code)):
code[i] = chr((ord(code[i]) - i + 128) % 128)
str1 += code[i]
print(code)
print(str1)