Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save C0axx/3371cbfd3c67a57e5bf287ee5e02269d to your computer and use it in GitHub Desktop.
Save C0axx/3371cbfd3c67a57e5bf287ee5e02269d to your computer and use it in GitHub Desktop.
How to turn a python script into a statically linked executable with pyinstaller and staticx
// 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment