python - 如何在 Python 中测试 Bobby Tables SQL 注入?
问题描述
我正在尝试在 Python 3.x 中从这张图片中测试 SQL 注入:
Python SQLite3 库文档页面https://docs.python.org/3/library/sqlite3.html中提到了这个 SQL 注入示例。我尝试在 python 代码中对此进行测试,但收到警告:“sqlite3.Warning:您一次只能执行一个语句。” 他们是否已经修复了这个漏洞?难道我做错了什么?
代码片段:
import sqlite3
conn = sqlite3.connect('example.db')
c = conn.cursor()
c.execute('''CREATE TABLE test(firstname text, lastname text)''')
c.execute("INSERT INTO test VALUES ('John','Doe')")
firstname = "John'; DROP TABLE test;"
c.execute("SELECT * FROM test WHERE firstname = '%s'" % firstname)
for i in c:
print(i)
conn.commit()
conn.close()
结果:
Traceback (most recent call last):
File "C:\test.py", line 10, in <module>
c.execute("SELECT * FROM test WHERE firstname = '%s'" % firstname)
sqlite3.Warning: You can only execute one statement at a time.
解决方案
c.execute(...) 只允许一个语句。使用 c.executescript(...) 或 c.executemany(...)。
推荐阅读
- installation - 如何使用 CMake 安装依赖库?
- swift - 当您观察该密钥时,是否也下载了父密钥?
- django - /BRMapp/view-books/ 处的 AttributeError
- regex - 正则表达式:非贪婪搜索
- r - R 中的 For 循环 - 更改每月回报的序列
- excel - 用“With”和“Do While”替换 Select 语句后,VBA 运行速度非常慢
- ios - UIImagepickercontroller - 相机不工作
- php - 如何在 PHP 中将多个本地数据库中的数据同步和合并到实时服务器数据库?
- python - 使用带有自定义参数的 subprocess.Popen 时 Python 出错
- flutter - 如果颤动中没有指定颜色,标签文本和前缀图标采用什么颜色(默认颜色)?