0

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.

  • "The console appears for a millisecond and disappears." run the EXE from the Command Prompt instead of double-clicking on it. That way, you'll see any errors. –  Jul 19 '21 at 14:09
  • Thank you for your answer! I have executed the EXE and got several errors. I've posted the bugs in an answer below. – Duschjenkovic Jul 19 '21 at 14:20
  • [edit] your question to include the traceback. Do not post additional information as an answer. –  Jul 19 '21 at 14:21
  • See [this post](https://stackoverflow.com/questions/10098444/py2exe-include-modules-when-should-they-be-managed-manually). Try adding the module `cffi` to the list of modules to include. –  Jul 19 '21 at 14:24
  • BTW, I thought py2exe was abandoned but since you're using it on python 3.9 then I must be mistaken. –  Jul 19 '21 at 14:26
  • Thank you. Yeah I've heard similar things about py2exe and Python 3.x maybe some modules still work with the old version. – Duschjenkovic Jul 19 '21 at 14:32

0 Answers0