Python逆向
Python逆向特点
-
在文件信息中出现 PyInstaller 即为 Python 文件经过 pyinstaller 打包生成的可执行 .exe 文件
-
这类由 Python 生成的可执行文件无法通过 IDA 反编译,需要使用
pyinstxtractor.py
文件进行解包得到 Python 的反编译文件 .pyc
Python 逆向流程
-
将
pyinstxtractor.py
文件置于 pyinstaller 打包成的 .exe 文件夹下 -
在该目录下执行 cmd,输入:
python pyinstxtractor.py exe文件名
-
转换后会在该目录下生成一个文件夹,其中必定存在一个无后缀名的
struct
文件,通过 exeinfo pe 可查看该文件为 .pyc 文件 【必要时可用它恢复文件头】
pyc 反编译
pip install
uncompyle6
uncompyle6 pyc文件名
uncompyle6 -o py文件名 pyc文件名
获取 pyc 文件头
# 代码开头需导入py_compile
import py_compile
# 随意写正确的python代码即可
def print_hi(name):
print(f'Hi, {name}')