Skip to content

Instantly share code, notes, and snippets.

@0xhexmex
Last active December 1, 2023 14:50
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save 0xhexmex/bbfdb6da7fe560f4aabcc271f4951e43 to your computer and use it in GitHub Desktop.
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
// 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
@pigscanflyyyy
Copy link

I've encountered an error. Any tips?
[29571] Cannot open self /tmp/staticx-vMw5W7/proxy or archive /tmp/staticx-vMw5W7/proxy.pkg

@lazywhite
Copy link

python >=3.5 , you can just pip install staticx

@0xhexmex
Copy link
Author

Ah good to know, thank you

@0xhexmex
Copy link
Author

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