2013年5月30日星期四

wordpress评论者链接网址重定向跳转设置后出现的HTTP响应拆分漏洞

wordpress评论者链接网址重定向跳转设置后出现的HTTP响应拆分漏洞
2013年02月24日 12:40:16 | Wordpress | 共 1221字 | 被围观 529 次 | 7 条评论
其实这个HTTP响应拆分漏洞是‘360安全网站检测’检测出来的。
该漏洞的危害:攻击者可能注入自定义HTTP头。例如,攻击者可以注入会话cookie或HTML代码。这可能会进行类似的XSS(跨站点脚本)或会话固定漏洞。
解决方案:限制用户输入的CR和LF,或者对CR和LF字符正确编码后再输出,以防止注入自定义HTTP头。
出现这个问题,是因为添加了wordpress评论外链跳转功能,站外网址的跳转是使用“/?r=”直接跳转,没有使用中间跳转页,而且代码过滤不严格。
关于评论者链接网址重定向的方法网上很多,代码是这样的:
  1. //评论者链接的网址重定向跳转   
  2. add_filter('get_comment_author_link', 'add_redirect_comment_link', 5);   
  3. add_filter('comment_text', 'add_redirect_comment_link', 99);   
  4. function add_redirect_comment_link($text = ''){   
  5. $text=str_replace('href="', 'href="'.get_option('home').'/?r=', $text);   
  6. $text=str_replace("href='""href='".get_option('home')."/?r=", $text);   
  7. return $text;   
  8. }   
  9. add_action('init', 'redirect_comment_link');   
  10. function redirect_comment_link(){   
  11. $redirect = $_GET['r'];   
  12. $host = $_SERVER['HTTP_HOST'];   
  13. if($redirect){   
  14. if(strpos($_SERVER['HTTP_REFERER'],get_option('home')) !== false){   
  15. header("Location: $redirect#from:$host");   
  16. exit;   
  17. }   
  18. else {   
  19. header("Location: $redirect#from:$host");   
  20. exit;   
  21. }   
  22. }   
  23. }  

解决参数r的HTTP响应拆分漏洞:
$redirect = $_GET['r'];后面必须过滤CR和LF字符,在该代码后面加上以下代码:
  1. $redirect = trim(str_replace("\r","",str_replace("\r\n","",strip_tags(str_replace("'","",str_replace("\n", "", str_replace(" ","",str_replace("\t","",trim($redirect))))),""))));
即可成功修复HTTP响应拆分漏洞。

没有评论:

发表评论