如果我打开交互模式并输入:
__builtins__ = 0 # breaks everything
Run Code Online (Sandbox Code Playgroud)
我完全打破了会议?如果是这样,幕后发生了什么,将__builtins__分配给内置模块,而解释器无法处理?如果没有,我该如何从中恢复?
我自己尝试修复它的一些尝试:
Ned*_*der 30
您通常可以访问所需的任何内容,即使__builtins__
已被删除.这只是一个挖掘足够远的问题.例如:
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> __builtins__ = 0
>>> open
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'open' is not defined
>>> dir
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'dir' is not defined
>>> int
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'int' is not defined
>>> float
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'float' is not defined
>>>
>>> __builtins__ = [t for t in ().__class__.__bases__[0].__subclasses__() if 'warning' in t.__name__][0]()._module.__builtins__
>>>
>>> open
<built-in function open>
>>> int
<type 'int'>
>>> float
<type 'float'>
>>>
Run Code Online (Sandbox Code Playgroud)
为了解释这里发生了什么,读Eval真的很危险,使用类似的技术来证明你不能安全地执行不受信任的Python代码.
归档时间: |
|
查看次数: |
2155 次 |
最近记录: |