metasploit-framework/modules/auxiliary/scanner/sap/sap_icm_urlscan.rb

189 lines
5.7 KiB
Ruby
Raw Normal View History

##
# This module requires Metasploit: http://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
require 'msf/core'
class Metasploit3 < Msf::Auxiliary
2013-08-30 21:28:54 +00:00
include Msf::Exploit::Remote::HttpClient
include Msf::Auxiliary::Scanner
include Msf::Auxiliary::Report
def initialize(info = {})
super(update_info(info,
'Name' => 'SAP URL Scanner',
'Description' => %q{
This module scans for commonly found SAP Internet Communication Manager URLs
and outputs return codes for the user.
},
'Author' => [ 'Chris John Riley' ],
'References' =>
[
[ 'CVE', '2010-0738' ] # VERB auth bypass
],
'License' => MSF_LICENSE
))
register_options(
[
OptString.new('VERB', [true, "Verb for auth bypass testing", "HEAD"]),
2014-05-19 09:41:01 +00:00
OptPath.new('URLFILE', [true, "SAP ICM Paths File",
File.join(Msf::Config.data_directory, 'wordlists', 'sap_icm_paths.txt')])
2013-08-30 21:28:54 +00:00
], self.class)
end
# Base Structure of module borrowed from jboss_vulnscan
def run_host(ip)
2014-05-19 09:41:01 +00:00
res = send_request_cgi(
2013-08-30 21:28:54 +00:00
{
'uri' => "/" + Rex::Text.rand_text_alpha(12),
'method' => 'GET',
2014-05-19 09:41:01 +00:00
})
2013-08-30 21:28:54 +00:00
if res
print_status("Note: Please note these URLs may or may not be of interest based on server configuration")
@info = []
2014-05-19 09:41:01 +00:00
if res.headers['Server']
2013-08-30 21:28:54 +00:00
@info << res.headers['Server']
print_status("#{rhost}:#{rport} Server responded with the following Server Header: #{@info[0]}")
else
print_status("#{rhost}:#{rport} Server responded with a blank or missing Server Header")
end
2014-05-19 09:41:01 +00:00
if (res.body && /class="note">(.*)code:(.*)</i.match(res.body) )
2013-08-30 21:28:54 +00:00
print_error("#{rhost}:#{rport} SAP ICM error message: #{$2}")
end
# Load URLs
2014-05-19 09:41:01 +00:00
urls_to_check = check_urlprefixes
File.open(datastore['URLFILE']) do |f|
2013-08-30 21:28:54 +00:00
f.each_line do |line|
urls_to_check.push line
end
end
print_status("#{rhost}:#{rport} Beginning URL check")
2014-05-19 09:41:01 +00:00
@valid_urls = ''
2013-08-30 21:28:54 +00:00
urls_to_check.each do |url|
check_url(url.strip)
end
else
print_error("#{rhost}:#{rport} No response received")
end
2014-05-19 09:41:01 +00:00
if @valid_urls.length > 0
l = store_loot(
'sap.icm.urls',
"text/plain",
datastore['RHOST'],
@valid_urls,
"icm_urls.txt", "SAP ICM Urls"
)
print_line
print_good("Stored urls as loot: #{l}") if l
end
2013-08-30 21:28:54 +00:00
end
def check_url(url)
2014-05-19 09:41:01 +00:00
full_url = write_url(url)
2013-08-30 21:28:54 +00:00
res = send_request_cgi({
2014-05-19 09:41:01 +00:00
'uri' => normalize_uri(url),
2013-08-30 21:28:54 +00:00
'method' => 'GET',
2014-05-19 09:41:01 +00:00
})
2013-08-30 21:28:54 +00:00
if (res)
2014-05-19 09:41:01 +00:00
if res.headers['Server']
unless @info.include?(res.headers['Server'])
print_good("New server header seen [#{res.headers['Server']}]")
@info << res.headers['Server'] #Add To seen server headers
end
2013-08-30 21:28:54 +00:00
end
2014-05-19 09:41:01 +00:00
case res.code
when 200
2014-05-19 09:46:47 +00:00
print_good("#{full_url} - does not require authentication (#{res.code}) (length: #{res.headers['Content-Length']})")
2014-05-19 09:41:01 +00:00
@valid_urls << full_url << "\n"
when 403
print_status("#{full_url} - restricted (#{res.code})")
when 401
print_status("#{full_url} - requires authentication (#{res.code}): #{res.headers['WWW-Authenticate']}")
2014-05-19 09:59:38 +00:00
@valid_urls << full_url << "\n"
2013-08-30 21:28:54 +00:00
# Attempt verb tampering bypass
bypass_auth(url)
2014-05-19 09:41:01 +00:00
when 404
2013-08-30 21:28:54 +00:00
# Do not return by default, only display in verbose mode
2014-05-19 09:41:01 +00:00
vprint_status("#{full_url} - not found (#{res.code})")
2014-05-19 14:21:07 +00:00
when 400, 500
2014-05-19 09:41:01 +00:00
print_status("#{full_url} - produced a server error (#{res.code})")
2014-05-19 14:21:07 +00:00
when 301, 302
2014-05-19 09:41:01 +00:00
print_good("#{full_url} - redirected (#{res.code}) to #{res.redirection} (not following)")
@valid_urls << full_url << "\n"
when 307
2014-05-19 09:52:06 +00:00
print_status("#{full_url} - redirected (#{res.code}) to #{res.redirection} (not following)")
2013-08-30 21:28:54 +00:00
else
2014-05-19 09:41:01 +00:00
print_error("#{full_url} - unhandled response code #{res.code}")
@valid_urls << full_url << "\n"
2013-08-30 21:28:54 +00:00
end
else
2014-05-19 09:41:01 +00:00
vprint_status("#{full_url} - not found (No Repsonse code Received)")
2013-08-30 21:28:54 +00:00
end
end
2014-05-19 09:41:01 +00:00
def write_url(path)
if datastore['SSL']
protocol = 'https://'
else
protocol = 'http://'
end
"#{protocol}#{rhost}:#{rport}#{path}"
end
2013-08-30 21:28:54 +00:00
def bypass_auth(url)
2014-05-19 09:41:01 +00:00
full_url = write_url(url)
vprint_status("#{full_url} Check for verb tampering (#{datastore['VERB']})")
2013-08-30 21:28:54 +00:00
res = send_request_raw({
2014-05-19 09:41:01 +00:00
'uri' => normalize_uri(url),
2013-08-30 21:28:54 +00:00
'method' => datastore['VERB'],
'version' => '1.0' # 1.1 makes the head request wait on timeout for some reason
2014-05-19 09:41:01 +00:00
})
2013-08-30 21:28:54 +00:00
2014-05-19 09:41:01 +00:00
if (res && res.code == 200)
print_good("#{full_url} Got authentication bypass via HTTP verb tampering")
2013-08-30 21:28:54 +00:00
else
2014-05-19 09:41:01 +00:00
vprint_status("#{rhost}:#{rport} Could not get authentication bypass via HTTP verb tampering")
2013-08-30 21:28:54 +00:00
end
end
2014-05-19 09:41:01 +00:00
# "/urlprefix outputs the list of URL prefixes that are handled in the ABAP part of the SAP Web AS.
# This is how the message server finds out which URLs must be forwarded where.
# (SAP help) -> this disclose custom URLs that are also checked for authentication
def check_urlprefixes
2014-05-19 09:41:01 +00:00
urls = []
res = send_request_cgi({
'uri' => "/sap/public/icf_info/urlprefix",
'method' => 'GET',
2014-05-19 09:41:01 +00:00
})
if (res && res.code == 200)
res.body.each_line do |line|
if line =~ /PREFIX=/
url_enc = line.sub(/^PREFIX=/, '')
2014-05-19 09:41:01 +00:00
# Remove CASE and VHOST
url_enc = url_enc.sub(/&CASE=.*/, '')
url_dec = URI.unescape(url_enc).sub(/;/, '')
2014-05-19 09:41:01 +00:00
urls << url_dec.strip
end
end
2014-05-19 09:41:01 +00:00
else
print_error("#{rhost}:#{rport} Could not retrieve urlprefixes")
end
2014-05-19 09:41:01 +00:00
urls
end
end