XSS 全稱爲 Cross Site Scripting,用戶在表單中有意或無意輸入一些惡意字符,從而破壞頁面的表現!
看看常見的惡意字符XSS 輸入:
1.XSS 輸入通常包含 JavaScript 腳本,如彈出惡意警告框:<script>alert("XSS");</script>
2.XSS 輸入也可能是 HTML 代碼段,譬如:
(1).網頁不停地刷新 <meta http-equiv="refresh" content="0;">
(2).嵌入其它網站的鏈接 <iframe src=http://xxxx width=250 height=250></iframe>
防止XSS***測試路徑:
其實有很多測試XSS***的工具:
Paros proxy (http://www.parosproxy.org)
Fiddler (http://www.fiddlertool.com/fiddler)
Burp proxy (http://www.portswigger.net/proxy/)
TamperIE (http://www.bayden.com/dl/TamperIESetup.exe)
對於PHP開發者來說,如何去防範XSS***呢?(php防止xss***的函數)
可以用如下函數:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?PHP
/**
* @blog http://www.phpddt.com
* @param $string
* @param $low 安全別級低
*/
function clean_xss(&$string, $low = False)
{
if (! is_array ( $string ))
{
$string = trim ( $string );
$string = strip_tags ( $string );
$string = htmlspecialchars ( $string );
if ($low)
{
return True;
}
$string = str_replace ( array ('"', "\\", "'", "/", "..", "../", "./", "//" ), '', $string );
$no = '/%0[0-8bcef]/';
$string = preg_replace ( $no, '', $string );
$no = '/%1[0-9a-f]/';
$string = preg_replace ( $no, '', $string );
$no = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S';
$string = preg_replace ( $no, '', $string );
return True;
}
$keys = array_keys ( $string );
foreach ( $keys as $key )
{
clean_xss ( $string [$key] );
}
}
//just a test
$str = 'phpddt.com<meta http-equiv="refresh" content="0;">';
clean_xss($str); //如果你把這個註釋掉,你就知道xss***的厲害了
echo $str;
?>
通過clean_xss()就過濾了惡意內容!
什麼XSS***?PHP防止XSS***函數
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
註冊個博來保存一些文章
zinejo
2019-02-23 13:50:47
新e時代網站
lichenjing9
2019-02-23 14:06:52
虛擬機的使用和Linux的一些基礎
夢與時光眠
2019-02-23 13:51:55
科技部網站是這樣回答無聊問題的....
張富貴
2019-02-23 13:49:41
tomcat限制用域名訪問 禁止 ip訪問
張斌66
2019-02-23 13:44:28
brew安裝步驟
guoshuang_123
2019-02-23 13:43:55
第一週作業 模擬登錄
賈志禹
2019-02-23 14:04:57
Linxu用戶登錄監測
zhongqijian916
2019-02-23 13:54:51
虛擬機未能初始化遠程子系統找不到一個要連接有效peer進程
lhslllj
2019-02-23 13:50:59
linux初學之信號及信號的簡介
imGrt
2019-02-23 13:50:03
最高企業級多用戶商城系統
vgogirl
2019-02-23 13:45:21
禁止用戶關機
czq2008sky
2019-02-23 13:43:29
用戶 'NT AUTHORITY\NETWORK SERVICE' 登錄失敗。
czq2008sky
2019-02-23 13:43:29