PHP和XSS跨站攻击
查看( 435 ) /
评论( 16 )
TAG:
-
dzjzmj 发布于2007-01-02 16:33:51
-
<?php$str = "A 'quote' is<b>bold</b>";// Outputs:A 'quote' is <b>bold</b>echo htmlentities($str);// Outputs:A 'quote' is <b>bold</b>echo htmlentities($str, ENT_QUOTES);?>这样可以使非法的脚本失效。 但是要注意一点,htmlentities()默认编码为 ISO-8859-1,如果你的非法脚本编码为其它,那么可能无法过滤掉,同时浏览器却可以识别和执行。这个问题我先找几个站点测试后再说。这里提供一个过滤非法脚本的函数:functionRemoveXSS($val) {
//remove all non-printable characters. CR(0a)and LF(0b) and TAB(9) are allowed
// this prevents some characterre-spacing such as <java\0script>
// note that you have to handlesplits with \n, \r, and \t later since they *are* allowed in some inputs
$val = preg_replace('/([\x00-\x08][\x0b-\x0c][\x0e-\x20])/', '',$val);
//straight replacements, the user should never need these since they're normalcharacters
//this prevents like <IMGSRC=@avascript:alert('XSS')>
$search = 'abcdefghijklmnopqrstuvwxyz';
$search .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$search .= '1234567890!@#$%^&*()';
$search .= '~`";:?+/={}[]-_|\'\\';
for ($i = 0; $i <strlen($search); $i++) {
// ;? matches the ;, which is optional
// 0{0,7} matches any padded zeros, which are optionaland go up to 8 chars
// @ @ search for the hex values
$val =preg_replace('/(&#[x|X]0{0,8}'.dechex(ord($search[$i])).';?)/i', $search[$i], $val); // with a ;
// @ @ 0{0,7} matches '0' zero to seven times
$val =preg_replace('/(�{0,8}'.ord($search[$i]).';?)/', $search[$i], $val); // with a ;
}
// nowthe only remaining whitespace attacks are \t, \n, and \r
$ra1 = Array('javascript', 'vbscript','expression', 'applet','meta', 'xml','blink', 'link','style', 'script','embed', 'object','iframe', 'frame','frameset', 'ilayer','layer', 'bgsound','title', 'base');
$ra2 = Array('onabort', 'onactivate','onafterprint', 'onafterupdate','onbeforeactivate', 'onbeforecopy','onbeforecut', 'onbeforedeactivate','onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint','onbeforeunload', 'onbeforeupdate','onblur', 'onbounce','oncellchange', 'onchange','onclick', 'oncontextmenu','oncontrolselect', 'oncopy','oncut', 'ondataavailable','ondatasetchanged', 'ondatasetcomplete','ondblclick', 'ondeactivate','ondrag', 'ondragend','ondragenter', 'ondragleave','ondragover', 'ondragstart','ondrop', 'onerror','onerrorupdate', 'onfilterchange','onfinish', 'onfocus','onfocusin', 'onfocusout','onhelp', 'onkeydown','onkeypress', 'onkeyup','onlayoutcomplete', 'onload','onlosecapture', 'onmousedown','onmouseenter', 'onmouseleave','onmousemove', 'onmouseout','onmouseover', 'onmouseup','onmousewheel', 'onmove','onmoveend', 'onmovestart','onpaste', 'onpropertychange','onreadystatechange', 'onreset', 'onresize','onresizeend', 'onresizestart','onrowenter', 'onrowexit','onrowsdelete', 'onrowsinserted','onscroll', 'onselect','onselectionchange', 'onselectstart', 'onstart', 'onstop', 'onsubmit','onunload');
$ra = array_merge($ra1, $ra2);
$found = true; // keep replacing as long as the previous round replacedsomething
while ($found == true) {
$val_before =$val;
for ($i = 0; $i< sizeof($ra); $i++) {
$pattern= '/';
for($j = 0; $j < strlen($ra[$i]); $j++) {
if($j > 0) {
$pattern.= '(';
$pattern.= '(&#[x|X]0{0,8}([9][a]);?)?';
$pattern.= '|(�{0,8}([9][10][13]);?)?';
$pattern.= ')?';
}
$pattern.= $ra[$i][$j];
}
$pattern.= '/i';
$replacement= substr($ra[$i], 0, 2).'<x>'.substr($ra[$i],2); // add in <> to nerf the tag
$val= preg_replace($pattern, $replacement, $val); //filter out the hex tags
if($val_before == $val) {
// no replacements were made, so exit the loop
$found= false;
}
}
}
}
-
blankyao 发布于2007-11-21 01:16:58
-
收藏了,好东西竟然没人顶
-
gdk2006发布于2007-12-08 11:09:56
-
我来顶一个,收下了。

-
wangchun发布于2007-12-08 20:33:28
-
早就解决了
-
Ven发布于2008-03-05 01:54:08
-
Daniel Morris写了个InputFilter类,很好用。
-
goodboy11发布于2008-06-22 14:57:17
-
听说这里有火爆的帖子
听说这里有火爆的帖子,过来凑凑热闹了
He is a Chinese owned general trading and wholesale company located in Shenzhen, China right next to Hong Kong. We buy exclusively from Chinese manufacturers who produce Consumer Wholesale Electronics, gadgets, and PC accessories. Everything we buy and sell is made in China and now you can buy these products direct from China, at wholesale prices, right here in our online discount wholesale shop. We offer you a wide-selection of consumer electronic products. This is your best opportunity to directly access the Chinese wholesale electronics market.
-
SysTem128发布于2008-06-24 19:14:27
-
相关工程
http://htmlpurifier.org/
还有一个htmlfilter,自己搜搜。
-
smoon发布于2008-09-25 09:22:57
-
htmlentities()默认编码为 ISO-8859-1,如果你的非法脚本编码为其它,那么可能无法过滤掉
------
这句能不详细说说!
-
limiwaer发布于2008-10-26 01:04:06
-
赵文娟卷入副市长受贿案
10月23日新华社报道说,“江苏省苏州市原副市长姜人杰因受贿1亿多元人民币,日前被南京市中级人民法院一审判处死刑”。
稍早一天的10月22日上午,南京市检察院召开新闻发布会,作为纪念检察院机关恢复30年的系列活动,公布了改革开放后其侦办的30起大案要案,其中就包括姜人杰一案。
1948年出生的姜人杰,2001年开始担任苏州市副市长,直到2006年3月以挪用公款罪、受贿罪被起诉。主办姜案的南京市检察院透露,姜人杰受贿1亿多元,单笔受贿达8000万。
担任苏州市副市长期间,姜主要分管苏州城建、交通、房地产开发等领域,同时兼任苏州城市建设投资发展有限公司董事长和苏州市高速公路建设指挥部总指挥等职。
法院判决书说,2001年至2004年间,姜人杰即利用上述职务便利,先后收受4家房地产开发公司和一家科技公司的贿赂款,共计人民币1.0867亿元、港币5万元、美元4000元。
知情人士告诉本报记者,姜人杰目前被关押在南京市建邺区某看守所内。一审判决后,姜人杰提出了上诉。“正在等待二审。”
bartendercodesoftlabelmatrixlabelmatrixmicroscan
“大家都在关注,姜人杰一案到底还牵涉到哪些人。”苏州市政府一位官员10月23日称。
知情人士向本报记者透露,苏州市政协原副主席赵文娟即是被姜人杰揭发的地方官员之一。赵文娟已经在今年8月前后被江苏省纪委“双规”。但此信息仍未获得相关方面的证实。
苏州市纪委一位人士则表示,由于赵文娟是副厅级干部,属省管干部序列,因此依据干部管理权限,此案查处权限归江苏省纪委负责,苏州纪委只是配合。
自1990年就开始担任苏州市财政局长,直到2004年卸任,赵此番深陷姜人杰“窝案”让苏州官场吃惊。
本报记者获悉,苏州市方面已经就赵文娟问题基本情况进行一定层级的传达。赵文娟涉案金额巨大,具体涉案情节还在继续调查中。(

