DedeCMS 如何修补XSS跨站脚本攻击

前端之家收集整理的这篇文章主要介绍了DedeCMS 如何修补XSS跨站脚本攻击前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
 XSS又叫CSS (Cross Site Script) ,跨站脚本攻击。它指的是恶意攻击者往Web页面里插入恶意HTML代码,当用户浏览该页之时,嵌入其中Web里面的HTML代码会被执行,从而达到恶意攻击用户的特殊目的。XSS属于被动式的攻击,因为其被动且不好利用,所以许多人常忽略其危害性。而本文主要讲的是利用XSS得到目标服务器的shell。技术虽然是老技术,但是其思路希望对大家有帮助。
 
  首先打开文件:/include/common.func.PHP
 
  在文件中加入函数
 
Copy to ClipboardLiehuo.Net Codes引用的内容:[www.jb51.cc]
function RemoveXSS($val) { 
$val = preg_replace('/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/','',$val); 
 
$search = 'abcdefghijklmnopqrstuvwxyz'; 
$search .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; 
$search .= '1234567890!@#$%^&*()'; 
$search .= '~`";:?+/={}[]-_|\'\\'; 
for ($i = 0; $i < strlen($search); $i++) { 
$val = preg_replace('/(&#[xX]0{0,8}'.dechex(ord($search[$i])).';?)/i',$search[$i],$val); 
$val = preg_replace('/(&#0{0,8}'.ord($search[$i]).';?)/',$val); 
 
$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; 
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 .= '(&#[xX]0{0,8}([9ab]);)'; 
$pattern .= '|'; 
$pattern .= '|(&#0{0,8}([9|10|13]);)'; 
$pattern .= ')*'; 
$pattern .= $ra[$i][$j]; 
$pattern .= '/i'; 
$replacement = substr($ra[$i],2).'
$val = preg_replace($pattern,$replacement,$val); 
if ($val_before == $val) { 
$found = false; 
return $val; 
}
然后在过滤显示标签修改,例如:/templets/default/search.htm,将:
 
Copy to ClipboardLiehuo.Net Codes引用的内容:[www.jb51.cc]
搜索
修改为:
 
Copy to ClipboardLiehuo.Net Codes引用的内容:[www.jb51.cc]
搜索
这样就可以了,当然其他地方显示的地方也可以通过这个函数过滤掉。
原文链接:https://www.f2er.com/dedecms/447479.html

猜你在找的Dedecms相关文章