MySQL root注入点是指攻击者通过利用MySQL数据库管理系统中的安全漏洞或配置不当,获取到root用户的权限,从而能够执行任意SQL命令,对数据库进行非法操作。这种注入点通常是由于应用程序没有正确地过滤用户输入,导致恶意SQL代码被执行。
import mysql.connector
# 不安全的查询示例
# query = "SELECT * FROM users WHERE username = '" + username + "' AND password = '" + password + "'"
# 安全的查询示例(使用参数化查询)
query = "SELECT * FROM users WHERE username = %s AND password = %s"
params = (username, password)
try:
connection = mysql.connector.connect(host='localhost', database='mydatabase', user='myuser', password='mypassword')
cursor = connection.cursor()
cursor.execute(query, params)
results = cursor.fetchall()
except mysql.connector.Error as error:
print("Failed to retrieve record: {}".format(error))
finally:
if connection.is_connected():
cursor.close()
connection.close()
领取专属 10元无门槛券
手把手带您无忧上云