Young87

SmartCat's Blog

So happy to code my life!

游戏开发交流QQ群号60398951

当前位置:首页 >跨站数据测试

攻防世界--python-trade

测试文件:https://adworld.xctf.org.cn/media/task/attachments/69c8f29912ae4f679d92a6cd36c33196.pyc

 

这里需要用到一个pyc文件反编译的工具,可以使用在线https://tool.lu/pyc/,也可以使用命令下载

pip install uncompyle

 

1.准备

pyc文件就是 py程序编译后得到的字节码文件 (py->pyc)

 

2.pyc文件逆向

在命令窗口执行

uncompyle6 test.pyc > test.py

打开得到的test.py

# uncompyle6 version 3.4.0
# Python bytecode 2.7 (62211)
# Decompiled from: Python 2.7.16 (default, Apr  6 2019, 01:42:57) 
# [GCC 8.3.0]
# Embedded file name: 1.py
# Compiled at: 2017-06-03 10:20:43
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'
# okay decompiling test.pyc

 

2.1 代码分析

通过查看这段Python2代码,我们知道flag进行encode函数中的操作,得到‘XlNkVmtUI1MgXWBZXCFeKY+AaXNt’。

因此,我们只要反过来执行,就能够得到flag,写出代码

import base64

def decode(message):
    s = ''
    imessage = base64.b64decode(message)

    for i in imessage:
        x = ord(i) - 16
        x = x ^ 32
        s += chr(x)

    return s

correct = 'XlNkVmtUI1MgXWBZXCFeKY+AaXNt'

flag = decode(correct)
print(flag)

 

3.get flag!

nctf{d3c0mpil1n9_PyC}

转载于:https://www.cnblogs.com/Mayfly-nymph/p/11420487.html

除特别声明,本站所有文章均为原创,如需转载请以超级链接形式注明出处:SmartCat's Blog

上一篇: 量子通信,到底是什么工作原理?

下一篇: 火星财经“POW'ER 2019全球开发者大会”在京成功举办,中国版“Consensus大会”呼之欲出

精华推荐