9

XSS-labs通关挑战(xss challenge)

 3 years ago
source link: http://www.cnblogs.com/ruoli-s/p/14285233.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

XSS-labs通关挑战(xss challenge)

0x00 xss-labs

最近在看xss,今天也就来做一下xss-labs通过挑战。找了好久的源码,终于被我给找到了,因为在GitHub上大家也知道那个下载速度,所以,我也就直接转接到自己的码云上去了,在这也贴出来,欢迎大家下载使用。

源码链接请点击:https://gitee.com/ruoli-s/xss-labs

安装没啥好说的,直接放进自己搭建好的www目录下,就可以开始闯关了,xss-labs一共有level 20,做着看吧。

(其实觉得这些图片才是我真正想做xss challenge的最大原因 UVbMJvE.gif!mobile )

FbAFje6.png!mobile

0x01 Level 1 无过滤机制

muQvmy2.png!mobile

看了半天,原来参数在地址栏里放着呢,

e26NRn7.png!mobile

修改参数,页面也随之变动,右键查看源代码,发现有跳转到level 2 的 JS ,而我们传入的参数是几位的,下面就显示payload的长度。

yiArMnU.png!mobile

OK,直接走代码:

<script>alert(/xss/)</script>

aiemA3U.png!mobile

0x02 Leval 2 闭合标签

yiQf6bI.png!mobile

我们直接输入level 1 的 payload ,发现直接输出了,这里应该是做了实体转义。

yUJJzqI.png!mobile

F12 查看源代码:

63YZFfN.png!mobile

第一处就是显示在页面上的代码,第二处是我们输入的代码,这里应该是做了转义,我们构造payload,使用 "> 尝试闭合 input 标签:

"><script>alert(/xss/)</script>

VvMriuQ.png!mobile

0x03 Leval 3 单引号闭合htmlspecialchar() 函数

6FVfUzb.png!mobile

来到Leval 3,我们还是先使用上两关测试的payload来验证:

Vb2qy2f.png!mobile

发现全部被实体转义了,我们去看源代码:

<!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 "<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 
echo "<h3 align=center>payload的长度:".strlen($str)."</h3>";
?>
</body>
</html>

咳咳,发现对双引号 做了限制,但是却放行了单引号 ' ,而且居然在value这里也加了 htmlspecialchars 函数,这种情况我们可以通过 事件标签 触发表单执行。这里开始构造payload:

'onmouseover='alert(/xss/)

I7fu6v.png!mobile

可以看到,在提交之后,没有立刻弹出,这里我们还需要将鼠标移动到文本框,让事件触发。

22uuqqY.png!mobile

补充:

htmlspecialchars函数

html事件属性

0x04 Leval 4

VRvue2.png!mobile

我们还是一样,使用前面测试过的,先一一过一遍,当然,结果必然是失败的,那么接下来我们看全端代码:

zeYBJzQ.png!mobile

可以发现源代码对 >< 进行了过滤,我们看源代码:

<?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>';
?>

确实使用 str_replace()尖括号 进行了过滤,而且对单引号 ' 做了防御,所以,我们直接模仿上一题,使用HTML事件,构造payload:

"onmouseover="alert(/xss/)

FRZJbaM.png!mobile

这里也是成功过关。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK