我目前正在开发Flask Restful API,该API可根据区域在一定距离内搜索医生。我想确切地知道它容易受到哪种SQL注入,因为sqllite3不允许在一条语句中使用多个命令。它具有几个与之相关的不同表,但我已经包括了相关的表以及sqllite查询在API代码中的外观。该API本身很大,因此您必须原谅我没有发布全部内容。
from flask import Flask
from flask_restful import Api, Resource, reqparse
import sqlite3
app = Flask(__name__)
api = Api(app)
class fullname(Resource):
def get(self, zipcode,distance,fname,lname):
con = sqlite3.connect('DoctorZipLookup.db')
with con:
cur = con.cursor()
cur.execute("SELECT Latitude, Longitude FROM Zipcodes WHERE Zip = " + zipcode)
#does some math and finds zipcodes less than distance away
cur.execute("SELECT * FROM Doctors WHERE Zip IN(SELECT Zip FROM closezipcodes) AND FirstName LIKE '" + fname + "%' AND LastName LIKE '" + lname + "%' ORDER BY Zip")
cur.execute("SELECT * FROM Comments ORDER BY id")
#put doctors and their comments in a JSON object and return it
api.add_resource(fullname, "/fullname/<string:zipcode>&<string:distance>&<string:fname>&<string:lname>")
app.run(debug=True)
我知道这样编写的查询很容易受到SQL注入的影响,并且我一直在尝试一些示例,以便更好地了解它的工作方式。到目前为止,尽管我还没有做很多事情。我在网上找到的大多数示例都包含一个;执行第二条语句并删除表或吐出更多信息。但是sqlite3不允许您一次执行2条语句,有没有办法解决这个问题并执行其他操作?或者,通过修改这样格式化的单个语句实际上可以造成什么伤害? 到目前为止,我所知道的只是在做类似的事情
import requests
zip = '27265 or Zip LIKE \'%\''
resp = requests.get('http://127.0.0.1:5002/fullname/' + zip + '&10&first&last')
这将导致Zipcodes表吐出其所有内容。设置方式还能做什么?