Python逆向Pyinstaller打包的exe文件
用到的工具
pyinstaller:pip install pyinstaller
pyinstxtractor.py:下载地址:https://sourceforge.net/projects/pyinstallerextractor/
或 https://github.com/extremecoders-re/pyinstxtractor
WinHex编辑器:下载地址:https://down.52pojie.cn/Tools/Editors/WinHex_v19.9.zip
uncompyle库:pip install uncompyle6
先打包一个测试py文件
pyinstaller -F -w test.py
打包好的exe文件在 dist 文件夹中 test.exe
下面开始解包
- cd 到dist文件夹下,将
pyinstxtractor.py
文件也下载到这里,执行:python pyinstxtractor.py test.exe
- 执行完毕,会生成测试脚本 .exe_extracted 文件夹,进入该文件夹,找到 struct 与 test 文件,添加 .pyc 后缀;
- 补全Magic Number:使用WinHex打开两个文件,
a. 若test 的 “E3” 前有值则直接进行第4步;
b. 若无值,则将 struct 中 “E3” 前面的16进制数添加到 test 的 “E3” 前,如果两文件前面相同,就在解包的文件夹中随便找一个 .pyc 的文件,将其 “E3” 前面的16进制数据添加到 test中; - 安装.pyc转.py所使用的库uncompyle6
找到测试脚本 .pyc 所在的文件夹,cd 到此路径下,并输入以下命令:pip install uncompyle6
命令执行完毕后,会看到successfully,test.py源码文件已成功生成在同路径下。uncompyle6 -o test.py test.pyc