well... I know it's kind of not a complete answer but...
Do you really need to let people run code?
the reason I ask is because it's quite simple to pass an import statement even though it's blacklisted.
try running this:
x = "im"; y="port"; print(str(x+y+" module"))
Answer from Cássio Rodrigo Peluso on Stack OverflowMicrosoft Vulnerability Manager Security Recommendations - Python
Does my Python code have any security issues with the new implemented approach? - Stack Overflow
Python Security Question
How is Python used for security?
One good book I recommend is Violent Python -- it goes over how to use Python to do penetration testing, analyze network traffic, etc., and can give you some good insight into how Python can be used in the security industry.
More on reddit.comVideos
well... I know it's kind of not a complete answer but...
Do you really need to let people run code?
the reason I ask is because it's quite simple to pass an import statement even though it's blacklisted.
try running this:
x = "im"; y="port"; print(str(x+y+" module"))
The blacklist approach is inherently flawed. By it's nature, Python has a surprisingly large surface area, and you will forever be at the mercy of having to vet every possible built-in command, along with each and every side effect of the built-ins. Not to mention, I assume the real script you're using will bring in some library, itself a protentional security concern.
For instance:
__builtins__.__dict__'Exec'.lower())")
This bypasses your checks, and lets the user call exec and import. This is not the only way to bypass your checks. There are others.
There isn't really a way to vet code to verify its safe automatically. I'd be hard pressed to imagine a scenario like this where I let users run code at all in an elevated environment.
Hi
First of all, I’m no software or programmer expert, but one of our users is wanting to use Python to write scripts to help with their “job” to test products (not IT related).
After looking into it, I have concerns over the use of Python as it can do and control a lot of things these employees should not have access too.
I have read it can communicate to Cisco Switches, Servers, or other PCs.
So, from a security point of view of protecting my network and not allowing access, how secure is the use of Python?
you’ll still creds to get into the infrastructure… what about Powershell? then AD only requires read access to get a huge amount of information about your company’s systems and users.
Not more of less an issues than anything else … imho