mysql 中with rollup的用法
今天看到一个审计的题目,解析里面说需要用到mysql的group by xxx with rollup这个语句。没用过,不知道干什么的,度娘之后那些博客解释得很难受,那种感觉就是你觉得他写的好xx,但就是看不懂。 使用效果如图:
![](https://img.haomeiwen.com/i3846885/f4ae6ed1c8927eec.png)
不知道有没有人和我想的一样,null那里是怎么回事。
然后我想起电脑里有mysql官方文档,查了一下。然后我发现我的智商可以理解。我把截图贴下:
![](https://img.haomeiwen.com/i3846885/5b20523ddd40d526.png)
![](https://img.haomeiwen.com/i3846885/cb1025a48abb3b6f.png)
![](https://img.haomeiwen.com/i3846885/68af9738abc7c2b9.png)
![](https://img.haomeiwen.com/i3846885/a28144593835e511.png)
![](https://img.haomeiwen.com/i3846885/b7ad44ed54042df9.png)
Null就是将高聚集的user或者password标出。文档里介绍很详细。
那个题代码如下:
<?php
error_reporting(0);
i f (!isset($_POST['uname']) || !isset($_POST['pwd'])) {
echo '<form action="" method="post">'."
";
echo '<input name="uname" type="text"/>'."
";
echo '<input name="pwd" type="text"/>'."
";
echo '<input type="submit" />'."
";
echo '</form>'."
";
echo ''."
";
die;
}
function AttackFilter($StrKey,$StrValue,$ArrReq){
if (is_array($StrValue)){
$StrValue=implode($StrValue);
}
if (preg_match("/".$ArrReq."/is",$StrValue)==1){
print "水可载舟,亦可赛艇!";
exit();
}
}
$filter = "and|select|from|where|union|join|sleep|benchmark|,|(|)";
foreach($_POST as $key=>$value){
AttackFilter($key,$value,$filter);
}
$con = mysql_connect("XXXXXX","XXXXXX","XXXXXX");
if (!$con){
die('Could not connect: ' . mysql_error());
}
$db="XXXXXX";
mysql_select_db($db, $con);
$sql="SELECT * FROM interest WHERE uname = '{$_POST['uname']}'";
$query = mysql_query($sql);
if (mysql_num_rows($query) == 1) {
$key = mysql_fetch_array($query);
if($key['pwd'] == $_POST['pwd']) {
print "CTF{XXXXXX}";
}else{
print "亦可赛艇!";
}
}else{
print "一颗赛艇!";
}
mysql_close($con);
?>
在$key['pwd'] == $_POST['pwd']
这里,如果key的值是Null,post提交的pwd也是null,就可以绕过。在user那里使用万能密钥配合with rollup一下' or 1=1 group by pwd with rollup limit 1 offset 2
即可。上面过滤逗号,offset可以解决。
mysql官方文档密码:wing