python - input() vs raw_input() 相关安全问题的简单解释

标签 python security input built-in

<分区>

我正在阅读这个 Python 2.7 教程,他们正在阅读 raw_input(),其中提到:

The input() function will try to convert things you enter as if they were Python code, but it has security problems so you should avoid it.

我试着用谷歌搜索一些解释,但我还是有点不清楚; input() vs raw_input() 所谓的固有安全问题的简单解释是什么?

最佳答案

Python 2.x 中的 input() 函数会在返回之前评估事物。

作为示例,您可以看一下这个 -

>>> input("Enter Something : ")
Enter Something : exit()

这会导致程序退出(因为它会评估 exit())。

另一个例子-

>>> input("Enter something else :")
Enter something else :__import__("os").listdir('.')
['.gtkrc-1.2-gnome2', ...]

这将列出当前目录的内容,您还可以使用 os.chdir()os.remove()os 等函数.removedirs() , os.rmdir()

关于python - input() vs raw_input() 相关安全问题的简单解释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31175820/

相关文章:

java - Java 6 上的签名 Applet

javascript - 编写一个简单的插件/组件

c - 有没有办法让程序在等待输入时保持运行?

python - Matplotlib - 如何使用 rc_context()?

azure - 如何将 AzSK 集成到 VSTS CI-Build 中

python - 使用 BeautifulSoup 获取特定标签后的值

php - 在数据库中有一个大表安全吗?

javascript - 创建自定义 html 输入

python - 在 Drake 中,如何将 NumPy 数组转换为不同的标量类型? (例如,从 float 到 AutoDiffXd 或 Expression?)

Python - 有没有办法自动化这个? <code>itertools.product</code>