攻防世界--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}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM