|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
请问如何让它可以输入任何账号密码都可以登录
# Run via `python injection.py` -- compatible with Python 2 and Python 3
from __future__ import print_function
# If raw_input doesn't exist, we're in Python 3 (which uses `input`)
try:
raw_input
except NameError:
raw_input = input
import sqlite3
import sys
def database_setup():
cur.execute("""CREATE TABLE Users(Id INT,
username TEXT,
password TEXT,
status TEXT,
admin INT
)""")
cur.execute("""INSERT INTO Users
VALUES(1, 'Hulk', 'greengrocer', 'SMASHING THINGS', 0)""")
cur.execute("""INSERT INTO Users
VALUES(2, 'Bobby', 'lolcats', 'serving tables', 1)""")
conn.commit()
conn = sqlite3.connect(":memory:")
cur = conn.cursor()
database_setup()
username = raw_input(">>> Enter your username... ")
password = raw_input(">>> Enter your password... ")
cur.execute("""SELECT 1 FROM Users
WHERE username = '%s' AND password = '%s'""" % (username, password))
if cur.fetchone():
print("You've successfully logged in as %s" % username)
else:
print("Your username or password was incorrect")
print()
username = raw_input(">>> Find out the status for which user? ")
cur.execute("SELECT status FROM Users WHERE username = '%s'" % username)
data = cur.fetchone()
if data:
print("User %s is %s" % (username, data[0]))
else:
print("No such user...")
conn.close()
这是sql注入中,常见的万能密码
SELECT 1 FROM Users WHERE username = '%s' AND password = '%s'""" % (username, password))
当username是'or'1'='1'or'1'='1的时候,构造的sql语句是
SELECT 1 FROM Users WHERE username = ''or'1'='1'or'1'='1' AND password = ''
执行逻辑是
步骤一:‘1’=‘1’and password=‘’返回False
步骤二:‘1’=‘1’or False 返回True
步骤三:username=‘’or True 返回True
最后也就是select 1 from users where True
也就是 select 1from users
|
|