1

I have a software with an embedded python interpreter. The software can open upon startup a given .py script and execute it. Let's assume that in my python environment I can't open other files, and I can't use external tools like Cython

I want to obfuscate the script. My only demand is that the payload part of the file (my custom business logic) could not be opened in a text editor and plain-text read.

I could imagine the flow of the script will be de-obfuscation/decryption of a payload, that resides within the .py file as the first step and then executing it.

I can store within the script any encryption key, and I don't care that the decryption part will be visible and that it can be easily reproduced.

Any ideas how can I make that happen?

  • so basically you are writing a malware and you want people to help you. – Kennet Celeste Jan 12 at 17:11
  • If I wanted to write a malware, I wouldn't write it in python, and I would really care about the chance of it to be decrypted. – macro_controller Jan 13 at 8:49
1

I did something similar on the past, here is the idea you need to carry:

  1. You create the python script that you want to execute and obfuscate:

    print('Some string')
    
  2. Another script opens the previous script, encrypts the content and base64 the encryption, and finally put in a variable like:

    text = "cHJpbnQoJ1NvbWUgc3RyaW5nJyk="
    
  3. On another python file, you stick the text variable and a routine for decryption and decode the base64.

  4. Use the method eval() for execute the previous decrypted and decoded string.

This is not perfect but at least you have something to play with and explore.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.