好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

wordpress中危xss跨站脚本攻击漏洞解决方案 - 网站

  有很长的时间是没有来发表文章的,因为最近真的是太忙了。不过,今天可以给wordress建站的朋友分享一个真正的干货,绝对让你受益匪浅。如果你的网站也出现了中危xss跨站攻击 漏洞 ,而且你也是wordpress程序建站,一定可以帮助到你。

关于什么叫wordress中危xss跨站脚本漏洞我在这就不讲了,大家可以去自己查一下资料。

我直接给大家分享像这样的

wordress中危xss跨站脚本漏洞应该如何来解决?

1:打开wp-includes\query.php,在文件处开始添加去除xss的函数(添加以下代码)  

//清除跨站漏洞 function xss_clean($data) { // Fix &entity\n; $data = str_replace(array('&','<','>'), array('&','<','>'), $data); $data = preg_replace('/(&#*\w+)[\x00-\x20]+;/u', '$1;', $data); $data = preg_replace('/(&#x*[0-9A-F]+);*/iu', '$1;', $data); $data = html_entity_decode($data, ENT_COMPAT, 'UTF-8'); // Remove any attribute starting with "on" or xmlns $data = preg_replace('#(<[^>]+?[\x00-\x20"\'])(?:on|xmlns)[^>]*+>#iu', '$1>', $data); // Remove javascript: and vbscript: protocols $data = preg_replace('#([a-z]*)[\x00-\x20]*=[\x00-\x20]*([`\'"]*)[\x00-\x20]*j[\x00-\x20]*a[\x00-\x20]*v[\x00-\x20]*a[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iu', '$1=$2nojavascript…', $data); $data = preg_replace('#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*v[\x00-\x20]*b[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iu', '$1=$2novbscript…', $data); $data = preg_replace('#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*-moz-binding[\x00-\x20]*:#u', '$1=$2nomozbinding…', $data); // Only works in IE: <span style="width: expression(alert('Ping!'));"></span> $data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?expression[\x00-\x20]*\([^>]*+>#i', '$1>', $data); $data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?behaviour[\x00-\x20]*\([^>]*+>#i', '$1>', $data); $data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:*[^>]*+>#iu', '$1>', $data); // Remove namespaced elements (we do not need them) $data = preg_replace('#</*\w+:\w[^>]*+>#i', '', $data); do { // Remove really unwanted tags $old_data = $data; $data = preg_replace('#</*(?:applet|b(?:ase|gsound|link)|embed|frame(?:set)?|i(?:frame|layer)|l(?:ayer|ink)|meta|object|s(?:cript|tyle)|title|xml)[^>]*+>#i', '', $data); } while ($old_data !== $data); // we are done… return $data; } //清除跨站漏洞

2:查找以下代码:

$q['s'] = stripslashes($q['s']);

3:在查找代码的后面添加以下代码:

//防止XSS跨站漏洞的代码 $q['s'] = xss_clean($q['s']);

 

4:保存并上传文件,然后检测。我相信这漏洞已经百分之百给解决掉了。

【小提示:】想解决这相的中危xss跨站攻击,一定要仔细看我的文章,每一步都不能马虎。

否则可能不能解决wordpress程序 xss跨站攻击。希望来的朋友们可以花几分钟的时间仔细 阅读 。

查看更多关于wordpress中危xss跨站脚本攻击漏洞解决方案 - 网站的详细内容...

  阅读:195次