标签:install mpi details tac led round bytecode 简单 net
https://buuoj.cn/challenges#[GWCTF%202019]pyre
先安装uncompyle
py -3 -m pip install uncompyle
然后执行指令,弄出一个.py文件
uncompyle6.exe .\attachment.pyc > .\test1.py
打开test1.py,代码如下:
1 # uncompyle6 version 3.6.5 2 # Python bytecode 2.7 (62211) 3 # Decompiled from: Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)] 4 # Embedded file name: encode.py 5 # Compiled at: 2019-08-19 21:01:57 6 print ‘Welcome to Re World!‘ 7 print ‘Your input1 is your flag~‘ 8 l = len(input1) 9 for i in range(l): 10 num = ((input1[i] + i) % 128 + 128) % 128 11 code += num 12 13 for i in range(l - 1): 14 code[i] = code[i] ^ code[(i + 1)] 15 16 print code 17 code = [‘\x1f‘, ‘\x12‘, ‘\x1d‘, ‘(‘, ‘0‘, ‘4‘, ‘\x01‘, ‘\x06‘, ‘\x14‘, ‘4‘, ‘,‘, ‘\x1b‘, ‘U‘, ‘?‘, ‘o‘, ‘6‘, ‘*‘, ‘:‘, ‘\x01‘, ‘D‘, ‘;‘, ‘%‘, ‘\x13‘] 18 # okay decompiling .\attachment.pyc
关于异或,我们要知道这样一个技巧:
a^0=a,a^a=0,那么可得:a^b^a=b,a^b^b=a
此题中,13、14行使code[i]=code[i]^code[i+1],i从0取到l-1-1。处理后,code[l-1]没有变,那么要逆向,则令x从l-2取到0,使code[x]=code[x]^code[x+1](a^b^b=a)。关于取模,(a%c+b%c)%c=(a+b)%c,所以第10行等价于(input1[i]+i)%128。
这么简单的脚本,我写的时候报了好多格式错误。。。Python还是不过关,最后还是对照网上的wp改脚本。。
解密脚本:
1 code = [‘\x1f‘, ‘\x12‘, ‘\x1d‘, ‘(‘, ‘0‘, ‘4‘, ‘\x01‘, ‘\x06‘, ‘\x14‘, ‘4‘, ‘,‘, ‘\x1b‘, ‘U‘, ‘?‘, ‘o‘, ‘6‘, ‘*‘, ‘:‘, ‘\x01‘, ‘D‘, ‘;‘, ‘%‘, ‘\x13‘] 2 l=len(code) 3 print(‘Welcome to Reverse!‘) 4 for x in range(l-2,-1,-1): 5 code[x]=chr(ord(code[x])^ord(code[x+1])) 6 for x in range(l): 7 print(chr((ord(code[x])-x)%128),end=‘‘)
re学习笔记(52)BUUCTF-re-[GWCTF 2019]pyre
BUUCTF [GWCTF 2019]pyre WriteUp
标签:install mpi details tac led round bytecode 简单 net
原文地址:https://www.cnblogs.com/hardcoreYutian/p/12718992.html