I am developing a simple ransomware script for my bachelor thesis to see how different firewall manufacturer solved threat protection/prevention. I wrote a simple python script using cryptography.fernet to generate a key and encrypt some example files. To run my script on a testmachine which haven't installed python I need to build a .exe and execute it. I have tried different Modules for example pyinstaller but the windows defender immediatly triggered an alert. However I managed to solve this problem using py2exe. I have created the python script and everything works perfectly until I am building the .exe file.
I am receiving 4 errors when I execute following command: python setup.py py2exe
4 missing Modules
-----------------
? _posixshmem imported from multiprocessing.resource_tracker, multiprocessing.shared_memory
? bcrypt imported from cryptography.hazmat.primitives.serialization.ssh
? readline imported from cmd, code, pdb
? resource imported from test.support
For some reason the .exe file will be build in dist folder but do not work properly when I start execute the file. The console appears for a millisecond and disappears. The example files are are still readable. I tried to comment out almost everything but I still have the same problem. I think some of the above used modules are not compatible with py2exe...
My setup.py is:
from distutils.core import setup
import py2exe
import os
import time
import getpass
import pathlib
import ctypes
from cryptography.fernet import Fernet
setup(console=['dll32.py'])
I started the .exe with Command Prompt and received following errors:
C:\Users\dj\Desktop\win64\dist>dll32.exe
Traceback (most recent call last):
File "dll32.py", line 6, in <module>
File "<frozen zipimport>", line 259, in load_module
File "cryptography\fernet.pyc", line 16, in <module>
File "<frozen zipimport>", line 259, in load_module
File "cryptography\hazmat\primitives\padding.pyc", line 11, in <module>
File "<frozen zipimport>", line 259, in load_module
File "<loader>", line 10, in <module>
File "<loader>", line 8, in __load
ImportError: (No module named '_cffi_backend') 'C:\\Users\\dj\\Desktop\\win64\\dist\\cryptography.hazmat.bindings._padding.pyd'
I am using Python 3.9.4
Thank you for your time.