如何在Python中测试Bobby表SQL注入?

如何在Python中测试Bobby表SQL注入?,python,sql,python-3.x,sqlite,Python,Sql,Python 3.x,Sqlite,我正试图从Python 3.x中的这张图片测试SQL注入: 资料来源: Python SQLite3库文档页面中提到了这个SQL注入示例。我试图在python代码中对此进行测试,但得到警告:“sqlite3.warning:一次只能执行一条语句。”他们是否已经修复了此漏洞?我做错什么了吗 代码段: import sqlite3 conn = sqlite3.connect('example.db') c = conn.cursor() c.execute('''CREATE TABLE t

我正试图从Python 3.x中的这张图片测试SQL注入:

资料来源:

Python SQLite3库文档页面中提到了这个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:\test.py”,第10行,在
c、 执行(“从测试中选择*,其中firstname='%s'%firstname”)
警告:一次只能执行一条语句。

c.execute(…)只允许一条语句。使用c.executescript(…)或c.executemany(…)。

看起来您已经修复了它。通过使用只允许一条语句的函数。请尝试
executescript
。但是在Python SQLite3库文档页面中,他们在本例中使用了execute函数。感谢您的回答,但是在Python SQLite3库文档页面中,他们在本例中使用了execute函数。