buuctf_pyre

下载附件得到一个.pyc文件,这是.py文件经过编译生成的文件,所以解题第一步是将其反编译为.py文件,我用的uncompyle6反编译

uncompyle6反编译方法:

uncompyle6 xxx.pyc > xxx.py

uncompyle6安装方法:

pip install uncompyle6

也可以使用在线工具反编译:python反编译 - 在线工具

反编译后得到

# uncompyle6 version 3.7.4
# Python bytecode 2.7 (62211)
# Decompiled from: Python 3.8.5 (default, Sep  3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)]
# Embedded file name: encode.py
# Compiled at: 2019-08-19 21:01:57
print('Welcome to Re World!')
print('Your input1 is your flag~')
l = len(input1)
for i in range(l):
    num = ((input1[i] + i) % 128 + 128) % 128
    code += num

for i in range(l - 1):
    code[i] = code[i] ^ code[(i + 1)]

print(code)
code = ['\x1f', '\x12', '\x1d', '(', '0', '4', '\x01', '\x06', '\x14', '4', ',', '\x1b', 'U', '?', 'o', '6', '*', ':',
        '\x01', 'D', ';', '%', '\x13']

关于%需要注意的是,(a+b)%c=(a%c+b%c)%c

所以第10行((input1[i] + i) % 128 + 128) % 128

=((input1[i] + i) % 128%128 + 128%128) % 128

=(input1)[i]+i)%128

对于异或,l=len(code),异或的范围应该是range(l-1),i的取值范围是l-1-1=l-2;因为code[0]到code[21]已经变化了,code[22]没有变,所以写脚本要从code[21]开始递减到code[0],上脚本

code = ['\x1f', '\x12', '\x1d', '(', '0', '4', '\x01', '\x06', '\x14', '4', ',', '\x1b', 'U', '?', 'o', '6', '*', ':',
        '\x01', 'D', ';', '%', '\x13']
l = len(code)
# print(l)
flag = ''
for i in range(l - 2,-1,-1):
        code[i] = chr(ord(code[i]) ^ ord(code[i + 1]))
# print(code)
for i in range(l):
        code[i] = chr((ord(code[i]) - i) % 128)
        flag += code[i]
print(flag)

运行得出flag

将GWHT换成flag提交

flag{Just_Re_1s_Ha66y!}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值