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攻擊的函數)
可以用如下函數:
<?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()就過濾了惡意內容!