0x00 环境准备

711CMS官网: https://www.711cms.com/

网站源码版本:711CMS 1.0.5 正式版(发布时间:2018-01-20)

程序源码下载:https://www.711cms.com/versions/711cms_V1.0.5.zip

测试网站首页:

 

【代码审计】711cms_V1.0.5前台XSS跨站脚本漏洞分析_源码下载

0x01 代码分析

1、首先我们来看一下全局防护代码: /system/core/Security.php,代码太长,摘录部分函数,第352-387行中:


1. public function xss_clean($str, $is_image = FALSE)  
2. {  
3.     // Is the string an array?  
4.     if (is_array($str))  
5.     {  
6.         foreach ($str as $key => &$value)  
7.         {  
8.             $str[$key] = $this->xss_clean($value);  
9.         }  
10. 10.   
11. 11.         return $str;  
12. 12.     }  
13. 13.   
14. 14.     // Remove Invisible Characters  
15. 15.     $str = remove_invisible_characters($str);  
16. 16.   
17. 17.     /* 
18. 18.      * URL Decode 
19. 19.      * 
20. 20.      * Just in case stuff like this is submitted: 
21. 21.      * 
22. 22.      * <a href="http://%77%77%77%2E%67%6F%6F%67%6C%65%2E%63%6F%6D">Google</a> 
23. 23.      * 
24. 24.      * Note: Use rawurldecode() so it does not remove plus signs 
25. 25.      */  
26. 26.     if (stripos($str, '%') !== false)  
27. 27.     {  
28. 28.         do  
29. 29.         {  
30. 30.             $oldstr = $str;  
31. 31.             $str = rawurldecode($str);  
32. 32.             $str = preg_replace_callback('#%(?:\s*[0-9a-f]){2,}#i', array($this, '_urldecodespaces'), $str);  
33. 33.         }  
34. 34.         while ($oldstr !== $str);  
35. 35.         unset($oldstr);  
36. 36.     }



这段函数对XSS攻击进行过滤,比如<script>将被转换为[removed],接着看:

2、漏洞文件位置:/cms/controllers/Index.php 第77-88行:


1. public function search($keywords='')  
2. {  
3.     $keywords = urldecode($keywords);  
4.     if(!$keywords)  
5.         $keywords = $this->input->get('keywords', true);  
6.     if (!$keywords) {  
7.         redirect('/');  
8.     }  
9.     $this->template->assign('keywords', $keywords);  
10. 10.     $this->template->assign('show_sort_id', 1);  
11. 11.     $this->template->display('search.php');  
12. }



这段search函数中,对接收到的参数进行url解码,然后带入数据库中执行,keyword在输入输出过程中只有全局防护代码在防护,全局防护代码过滤不严谨,存在被绕过的情况,导致程序在实现上存在反射型XSS跨站脚本漏洞,允许攻击者可在页面中插入恶意js代码,获得用户cookie等信息,导致用户被劫持。

0x02 漏洞利用

1、网站首页搜索框---XSS Payload:

111"οnclick="\u0061\u006C\u0065\u0072\u0074(/xss/)

 

【代码审计】711cms_V1.0.5前台XSS跨站脚本漏洞分析_html_02

0x03 修复建议

1、全局防护是有必要的,但是并不是万能的,过滤能更严谨些;

2、建议对参数做html转义过滤(要过滤的字符包括:单引号、双引号、大于号、小于号,&符号),防止脚本执行。在变量输出时进行HTML ENCODE处理。 PHP应用:可以使用htmlspecialchars对用户参数进行编码 。

安全代码示例:


1. <?php  
2.      $aa=$_GET['dd'];  
3.      echo htmlspecialchars($aa)."123";  
4.  ?>



 

最后

欢迎关注个人微信公众号:Bypass--,每周原创一篇技术干货。 

【代码审计】711cms_V1.0.5前台XSS跨站脚本漏洞分析_php_03