关注这个靶场的其他相关笔记:XSS - LABS —— 靶场笔记合集
0x01:过关流程
经过前三关的积累,我们基本也摸清了一套测试 XSS 漏洞的流程了:上传数据 => 查看源码,查找上传数据 => 针对每个回显点,进行测试,尝试绕过。
那么,首先,查看页面源代码,搜索try harder!
(它默认的,我也懒的搜新关键词了):
我们继承上关的经验,尝试直接给 input
标签添加鼠标移动的监听事件,可以看到,没啥新意,换了个闭合标签而已,速通(详细分析查看 Level 3 的介绍):
" onmouseover="alert(1)
看一下触发漏洞的页面实际源码:
0x02:源码分析
下面是 XSS LABS Level 4 的源码,以及我对其做的笔记:
<!DOCTYPE html><!--STATUS OK-->
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<script>
// 修改 alert 的默认行为,跳转到下一关
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); // 将 $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>'; // 直接将 $str3 回显,觉得过滤了尖括号就没 XSS 了?
?>
<center><img src=level4.png></center>
<?php
echo "<h3 align=center>payload的长度:" . strlen($str3) . "</h3>";
?>
</body>
</html>
和 Level 3 问题一样,将关注点都放在了可能新增的标签上,但是忽略了 XSS 攻击也可以通过修改标签属性完成。