xss小游戏源码分析

下载地址:https://files.cnblogs.com/files/Lmg66/xssgame-master.zip
使用:下载解压,放到www目录下(phpstudy),http服务下都行,我使用的是phpstudy

第一关 查看源码: <!DOCTYPE html> <head> <meta charset="utf-8"> <script> window.alert = function() { confirm("哎哟 不错哦!"); window.location.href="level2.php?keyword=跨站师"; } </script> <title>第1关</title> </head> <body> <h1 align=center>第1关 先热个身吧</h1> <?php ini_set("display_errors", 0); $str = $_GET["name"]; echo "<h2 align=center>欢迎用户:".$str."</h2>"; ?> <center><img src="http://dn-coding-net-tweet.codehub.cn/photo/2019/8deed969-b339-4c84-8654-b1a1e40e06de.png"></center> <?php echo "<h3 align=center>payload的长度:".strlen($str)."</h3>"; ?> </body> </html> 分析:

对name没有任何的过滤输出到标签中,基本的xss都行

payload: level1.php?name=<script>alert('xss')</script> 第二关 查看源码: <!DOCTYPE html> <head> <meta charset="utf-8"> <script> window.alert = function() { confirm("哎哟 不错哦!"); window.location.href="level3.php?writing=苦尽甘来"; } </script> <title>第2关</title> </head> <body> <h1 align=center>第2关 窒息的操作</h1> <?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="http://dn-coding-net-tweet.codehub.cn/photo/2019/688da926-8a0b-452a-9a2b-82ba919328fb.jpg"></center> <?php echo "<h3 align=center>payload的长度:".strlen($str)."</h3>"; ?> </body> </html> 分析:

用htmlspecialchars()函数,之前做过,会html实体化,<>会被转义
可以尝试"来闭合"

payload: " onclick=alert('XSS') // " onclick=alert('XSS') " 第三关 查看源码: <!DOCTYPE html> <head> <meta charset="utf-8"> <script> window.alert = function() { confirm("哎哟 不错哦!"); window.location.href="level4.php?keyword=宁静致远"; } </script> <title>第3关</title> </head> <body> <h1 align=center>第3关 这该咋办啊</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="http://dn-coding-net-tweet.codehub.cn/photo/2019/ee7a688a-d75e-4ed7-8a79-96e62d3127e2.png"></center> <?php echo "<h3 align=center>payload的长度:".strlen($str)."</h3>"; ?> </body> </html> 分析:

和第二关类似,只是变成了单引号,闭合单引号即可

payload: ' onclick=alert('xss') ' ' onclick=alert('xs') // 第四关 查看源码: <!DOCTYPE html> <head> <meta charset="utf-8"> <script> window.alert = function() { confirm("哎哟 不错哦!"); window.location.href="level5.php?keyword=逆水行舟"; } </script> <title>第4关</title> </head> <body> <h1 align=center>第4关 生无可恋</h1> <?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>'; ?> <center><img src="http://dn-coding-net-tweet.codehub.cn/photo/2019/0d3f0d24-a861-4d20-97da-f807ea842be8.jpg"></center> <?php echo "<h3 align=center>payload的长度:".strlen($str3)."</h3>"; ?> </body> </html> 分析:

在第二关的基础上进行了< >的过滤,但第二关payload没有 < >仍然可以使用

payload: " onclick=alert('XSS') // " onclick=alert('XSS') " 第五关 查看源码: <!DOCTYPE html> <head> <meta charset="utf-8"> <script> window.alert = function() { confirm("哎哟 不错哦!"); window.location.href="level6.php?keyword=柳暗花明"; } </script> <title>第5关</title> </head> <body> <h1 align=center>第5关 没错又是搜索</h1> <?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>'; ?> <center><img src="http://dn-coding-net-tweet.codehub.cn/photo/2019/cb30e912-eabc-4357-89eb-49e8de1b1961.jpg"></center> <?php echo "<h3 align=center>payload的长度:".strlen($str3)."</h3>"; ?> </body> </html> 分析:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpfygj.html