Last active
December 2, 2024 12:15
-
-
Save 0xhexmex/bbfdb6da7fe560f4aabcc271f4951e43 to your computer and use it in GitHub Desktop.
How to turn a python script into a statically linked executable with pyinstaller and staticx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example below is with mitm6 (https://github.com/fox-it/mitm6/) | |
// Note: Adding the '--add-binary' option here is specific to mitm6, not required in all cases. | |
# pip install pyinstaller | |
# pyinstaller --clean -F --add-binary="/usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0:." ./mitm6.py | |
// The step above will create a single binary in the ./dist/ directory called mitm6 | |
// Install staticx and dependencies | |
# apt update && apt install binutils patchelf | |
# pip install patchelf-wrapper | |
# pip install scons | |
# git clone https://github.com/JonathonReinhart/staticx | |
# cd staticx | |
# scons | |
# python setup.py install | |
// Now create the statically linked binary using staticx and the output from PyInstaller | |
# staticx /opt/tools/mitm6/mitm6/dist/mitm6 /tmp/mitm6.static | |
# file /tmp/mitm6.static | |
/tmp/mitm6.static: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, BuildID[sha1]=bc235534bcd37c68e25822e87e19cac99377d865, for GNU/Linux 3.2.0, not stripped |
python >=3.5 , you can just pip install staticx
Ah good to know, thank you
I've encountered an error. Any tips?
[29571] Cannot open self /tmp/staticx-vMw5W7/proxy or archive /tmp/staticx-vMw5W7/proxy.pkg
Sorry just seeing this now. Did you get it figured out?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've encountered an error. Any tips?
[29571] Cannot open self /tmp/staticx-vMw5W7/proxy or archive /tmp/staticx-vMw5W7/proxy.pkg