protect python code from reverse engineering

有些话、适合烂在心里 提交于 2020-08-08 07:17:32

问题


I'm creating a program in python (2.7) and I want to protect it from reverse engineering.

I compiled it using cx_freeze (supplies basic security- obfuscation and anti-debugging)

How can I add more protections such as obfuscation, packing, anti-debugging, encrypt the code recognize VM.

I thought maybe to encrypt to payload and decrypt it on run time, but I have no clue how to do it.


回答1:


Generally speaking, it's almost impossible for you to make your program unbreakable as long as there's enough motive for the hackers.

But still you can make it harder to be reverse engineered, try to use cython to compile your core codes into pyd or so files.




回答2:


There's no way to make anything digital safe nowadays.

What you CAN do is making it hard to a point where it's frustrating to do it, but I admit I don't know python specific ways to achieve that. The amount of security of your program is not actually a function of programsecurity, but of psychology.

Yes, psychology.

Given the fact that it's an arms race between crackers and anti-crackers, where both continuously attempt to top each other, the only thing one can do is trying to make it as frustrating as possible. How do we achieve that?

By being a pain in the rear!

Every additional step you take to make sure your code is hard to decipher is a good one.

For example could you turn your program into a single compiled block of bytecode, which you call from inside your program. Use an external library to encrypt it beforehand and decrypt it afterwards. Do the same with extra steps for codeblocks of functions. Or, have functions in precompiled blocks ready, but broken. At runtime, utilizing byteplay, repair the bytecode with bytes depending on other bytes of different functions, which would then stop your program from working when modified.

There are lots of ways of messing with people's heads and while I can't tell you any python specific ways, if you think in context of "How to be difficult", you'll find the weirdest ways of making it a mess to deal with your code.

Funnily enough this is much easier in assembly, than python, so maybe you should look into executing foreign code via ctypes or whatever.

Summon your inner Troll!




回答3:


Story time: I was a Python programmer for a long time. Recently I joined in a company as a Python programmer. My manager was a Java programmer for a decade I guess. He gave me a project and at the initial review, he asked me that are we obfuscating the code? and I said, we don't do that kind of thing in Python. He said we do that kind of things in Java and we want the same thing to be implemented in python. Eventually I managed to obfuscate code just removing comments and spaces and renaming local variables) but entire python debugging process got messed up.

Then he asked me, Can we use ProGuard? I didn't know what the hell it was. After some googling I said it is for Java and cannot be used in Python. I also said whatever we are building we deploy in our own servers, so we don't need to actually protect the code. But he was reluctant and said, we have a set of procedures and they must be followed before deploying.

Eventually I quit my job after a year tired of fighting to convince them Python is not Java. I also had no interest in making them to think differently at that point of time.

TLDR; Because of the open source nature of the Python, there are no viable tools available to obfuscate or encrypt your code. I also don't think it is not a problem as long as you deploy the code in your own server (providing software as a service). But if you actually provide the product to the customer, there are some tools available to wrap up your code or byte code and give it like a executable file. But it is always possible to view your code if they want to. Or you choose some other language that provides better protection if it is absolutely necessary to protect your code. Again keep in mind that it is always possible to do reverse engineering on the code.



来源:https://stackoverflow.com/questions/41633039/protect-python-code-from-reverse-engineering

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!