本文最后更新于 2020 年 8 月 14 日,文章已超过 6 个月!内容可能已失效,请自行测试 ~
$link=connect();
$is_login_id=check_xss_login($link);
if(!$is_login_id){
header("location:post_login.php");
}
$state = '你已经登陆成功,<a href="xss_reflected_post.php?logout=1">退出登陆</a>';
$html='';
if(isset($_POST['submit'])){
if(empty($_POST['message'])){
$html.="<p class='notice'>输入'kobe'试试-_-</p>";
}else{
//下面直接将前端输入的参数原封不动的输出了,出现xss
if($_POST['message']=='kobe'){
$html.="<p class='notice'>愿你和{$_POST['message']}一样,永远年轻,永远热血沸腾!</p><img src='{$PIKA_ROOT_DIR}assets/images/nbaplayer/kobe.png' />";
}else{
$html.="<p class='notice'>who is {$_POST['message']},i don't care!</p>";
}
}
}
if(isset($_GET['logout']) && $_GET['logout'] == '1'){
setcookie('ant[uname]','');
setcookie('ant[pw]','');
header("location:post_login.php");
}
其中的一个函数:
/*xss里面的logincheck*/
function check_xss_login($link){
if(isset($_COOKIE['ant']['uname']) && isset($_COOKIE['ant']['pw'])){
//这里如果不对获取的cookie进行转义,则会存在SQL注入漏洞,也会导致验证被绕过
$username=escape($link, $_COOKIE['ant']['uname']);
$password=escape($link, $_COOKIE['ant']['pw']);
// $username=$_COOKIE['ant']['uname'];
// $password=$_COOKIE['ant']['pw'];
$query="select * from users where username='$username' and sha1(password)='$password'";
$result=execute($link,$query);
if(mysqli_num_rows($result)==1){
$data=mysqli_fetch_assoc($result);
return $data['id'];
}else{
return false;
}
}else{
return false;
}
}
isset($var) — 检测变量是否已设置并且非 NULL。
escape(str) 该方法不会对 ASCII 字母和数字进行编码,也不会对下面这些 ASCII 标点符号进行编码: * @ – _ + . / 。其他所有的字符都会被转义序列替换。
execute() 把字符串当命令执行。
mysqli_fetch_assoc() 从结果集中取得一行作为关联数组
2行是检测login的XSS
2-4如果都非空
5-6 escape过滤 应该有绕过这个函数的操作。实现漏洞
7-8 是没过滤的
9 查询语句
10 执行数据库操作
11 如果 返回结果集中行的数量==1
12 从结果集中取得一行作为关联数组。
13 返回 关联数组的id
这就是数据库的连接和防止sql注入,感觉可以绕
正文:
header(“Location:”):转向对header请求重定向到另外一个页面
6-11 如果没有通过之前的check_xss_login()函数则重定向
20-23 如果message参数==’kobe’,可以改成其他的吧。然后{$_POST[‘message’]}直接嵌入到p标签之间。造成的xss就出现在这里,不能直接嵌入,要过滤
该文章采用「CC 协议」,转载必须注明作者和本文链接.