SHARE:

Making a Windows Executable from Python Code on Kali

Spread the love

So I have seen a couple of Python exploits floating around that are useful for privilege escalation on a Windows box. Often than not I find that the exploited Windows boxes do not have python installed and so the answer is using pyinstaller to make the script an executable. Having to have a Windows VM for this and such, why not use Wine?

Digging around I found a fairly good blog post about getting the environment all setup unfortunately it didn’t quite work for me even with a vanilla Kali linux workstation.

Essentially I followed Milkator’s steps but added pip.exe and from there used pip to install pyinstaller. After that all was golden and things worked like champ.

# test.py
print "Hello, this is a test!"
-
git clone https://github.com/pyinstaller/pyinstaller
-
git clone https://github.com/htgoebel/virtual-wine.git
apt-get install scons
./virtual-wine/vwine-setup venv_wine

# Choose your Windows OS of choice. A number of errors about registry occur
-
# Get into your virtual wine environment and install Python and PyWin32
. venv_wine/bin/activate
wine msiexec -i python-2.7.8.msi
wine pywin32-218.win32-py2.7.exe

# Download get-pip.py https://pip.pypa.io/en/stable/installing/
wine c:/Python27/python.exe get-pip.py
wine c:/Python27/Scripts/pip.exe install pyinstaller
-
# Now compile your test.py
wine c:/Python27/python.exe pyinstaller/pyinstaller.py --onefile test.py

Voila!

Written by

gseeto

Technology, Science and Philosophy