简单Python逆向
简单Python逆向
笔记
getPycMagicNumber.py
1 | rd=input('Input Magic Number (ex. 3413):') |
做题
[NISACTF 2022]ezpython
python逆向
1 | pyinstxtractor *.exe |
出现 *.exe_extracted文件夹,找到src和struct,添加.pyc后缀。
用struct.pyc的Magic Number修复src.pyc($\mathrm{E3}$之前$12$个字节)
1 | uncompyle6 src.pyc>src.py |
解密得flag
[HUBUCTF 2022 新生赛]ezPython
uncompyle6
1 | from Crypto.Util.number import * |
md5 16位小写
[SWPUCTF 2022 新生赛]py2
简单python逆向
[广东省大学生攻防大赛 2022]pyre
95年编译的?????exp:
1 | c=[144,163,158,177,121,39,58,58,91,111,25,158,72,53,152,78,171,12,53,105,45,12,12,53,12,171,111,91,53,152,105,45,152,144,39,171,45,91,78,45,158,8] |
[LitCTF 2023]snake
python反编译,pygame贪吃蛇,发现玩不到1000,把flag输出代码分离得flag。
1 | flag=[30,196,52,252,49,220,7,243,3,241,24,224,40,230,25,251,28,233,40,237,4,225,4,215,40,231,22,237,14,251,10,169] |
[HNCTF 2022 Week1]你知道什么是Py嘛?
exp:
1 |
|
[MoeCTF 2021]Realezpy
1 | enc=[119,121,111,109,100,112,123,74,105,100,114,48,120,95,49,99,95,99,121,48,121,48,121,48,121,48,95,111,107,99,105,125] |
[MoeCTF 2021]midpython
1 | key=[69,70,79,72,88,75,85,127,89,85,74,19,74,122,107,103,75,77,9,73,29,28,67] |
[广东强网杯 2021 个人组]goodpy
Python字节码,对Python字节码的机制有进一步了解。
逆向得源代码:
1 | import os |
exp:
1 | enc=[56,92,6,1,47,4,2,62,129,84,97,100,5,100,87,89,60,11,84,87,244,103,118,247,47,96,47,244,98,127,81,102] |
[HZNUCTF 2023 preliminary]Bytecode
Python字节码逆向。
1 | c=[25,108,108,176,18,108,110,177,64,29,134,29,187,103,32,139,144,179,134,177,32,24,144,25,111,14,111,14] |
[FSCTF 2023]ez_pycxor
1 | ciphertxt=[168,169,185,170,160,157,197,132,226,134,134,145,255,242,130,139,234,140,180,229,179,246,243,181,183,182,249,163,254,189,246,166] |
[FSCTF 2023]ezcode
ROT_TWO用法:
1 | s_box[i],s_box[j]=s_box[j],s_box[i] |
字节码:
1 | 19 52 LOAD_FAST 1 (box) |
BUILD_SLICE数组切片方法:
1 | temp_list = bin_str[:3] |
字节码:
1 | 36 >> 70 LOAD_FAST 2 (bin_str) |
append另一种写法:
1 | temp_list.append('00000000') |
字节码:
1 | 40 >> 118 LOAD_FAST 7 (temp_list) |
INPLACE_ADD为追加,与二进制算术加法区分开。
还原后代码长这样:
1 | def func2(key): |
即为先RC4再换表Base64,Base64换表用赛博厨子,exp:
1 | import re |
[SWPUCTF 2023 秋季新生赛]蟒蛇中文破解绿色版
1 | enc=['39/1','83/3','83/2','67/3','42/1','70/3','123/2','116/3','52/1','49/3','115/2','95/3','49/2','115/3','95/2','112/3','121/2','95/3','119/2','37/1','57/1','36/1','50/1','11/1','95/2','35/1','58/1','35/1','115/2','39/1','26/1','34/1','97/2','36/1','33/2','125/3'] |
[AFCTF 2018]JPython
就是字节码的单字节替换,找一下,有不少重复的:
1 | f1 = open('./hash.pyc','rb').read() |
没去重的:
1 | { |
找个脚本替换:
1 | x={148:100,117:108,69:90,149:101,39:24,35:20,38:23} |
用uncompyle6发现还是反编译不成功,但报错信息足够多了:
1 | # file flag.pyc |
写个脚本解密:
1 | from base64 import b64decode |
发现s
中出现了俩非法字符“]”,那就挨个试,试到“B”,Base64解密即可。
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 The Blog of Monoceros406!