2011-03-02 10:18:31 +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'
|
|
|
|
|
2011-10-20 01:07:08 +00:00
|
|
|
class Metasploit4 < Msf::Auxiliary
|
2011-03-02 10:18:31 +00:00
|
|
|
|
|
|
|
include Msf::Exploit::Remote::HttpClient
|
|
|
|
include Msf::Auxiliary::Report
|
|
|
|
include Msf::Auxiliary::Scanner
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
super(
|
|
|
|
'Name' => 'SAP Management Console Instance Properties',
|
|
|
|
'Version' => '$Revision$',
|
2011-07-28 22:57:47 +00:00
|
|
|
'Description' => %q{
|
|
|
|
This module simply attempts to identify the instance properties
|
|
|
|
through the SAP Management Console SOAP Interface.
|
|
|
|
},
|
2011-03-02 10:18:31 +00:00
|
|
|
'References' =>
|
|
|
|
[
|
|
|
|
# General
|
|
|
|
[ 'URL', 'http://blog.c22.cc' ]
|
|
|
|
],
|
|
|
|
'Author' => [ 'Chris John Riley' ],
|
|
|
|
'License' => MSF_LICENSE
|
|
|
|
)
|
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
Opt::RPORT(50013),
|
|
|
|
OptString.new('URI', [false, 'Path to the SAP Management Console ', '/']),
|
|
|
|
], self.class)
|
|
|
|
register_autofilter_ports([ 50013 ])
|
|
|
|
deregister_options('RHOST')
|
|
|
|
end
|
|
|
|
|
|
|
|
def rport
|
|
|
|
datastore['RPORT']
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_host(ip)
|
|
|
|
res = send_request_cgi({
|
|
|
|
'uri' => "/#{datastore['URI']}",
|
|
|
|
'method' => 'GET',
|
|
|
|
'headers' =>
|
|
|
|
{
|
|
|
|
'User-Agent' => datastore['UserAgent']
|
|
|
|
}
|
|
|
|
}, 25)
|
2011-10-20 01:07:08 +00:00
|
|
|
|
|
|
|
if not res
|
|
|
|
print_error("#{rhost}:#{rport} [SAP] Unable to connect")
|
|
|
|
return
|
|
|
|
end
|
2011-03-02 10:18:31 +00:00
|
|
|
|
|
|
|
enum_instance(ip)
|
|
|
|
end
|
|
|
|
|
|
|
|
def enum_instance(rhost)
|
|
|
|
verbose = datastore['VERBOSE']
|
2011-03-11 16:50:18 +00:00
|
|
|
print_status("#{rhost}:#{rport} [SAP] Connecting to SAP Management Console SOAP Interface")
|
2011-03-02 10:18:31 +00:00
|
|
|
success = false
|
|
|
|
soapenv='http://schemas.xmlsoap.org/soap/envelope/'
|
|
|
|
xsi='http://www.w3.org/2001/XMLSchema-instance'
|
|
|
|
xs='http://www.w3.org/2001/XMLSchema'
|
|
|
|
sapsess='http://www.sap.com/webas/630/soap/features/session/'
|
|
|
|
ns1='ns1:GetInstanceProperties'
|
|
|
|
|
|
|
|
data = '<?xml version="1.0" encoding="utf-8"?>' + "\r\n"
|
2011-11-07 17:52:02 +00:00
|
|
|
data << '<SOAP-ENV:Envelope xmlns:SOAP-ENV="' + soapenv + '" xmlns:xsi="' + xsi
|
|
|
|
data << '" xmlns:xs="' + xs + '">' + "\r\n"
|
2011-03-02 10:18:31 +00:00
|
|
|
data << '<SOAP-ENV:Header>' + "\r\n"
|
|
|
|
data << '<sapsess:Session xlmns:sapsess="' + sapsess + '">' + "\r\n"
|
|
|
|
data << '<enableSession>true</enableSession>' + "\r\n"
|
|
|
|
data << '</sapsess:Session>' + "\r\n"
|
|
|
|
data << '</SOAP-ENV:Header>' + "\r\n"
|
|
|
|
data << '<SOAP-ENV:Body>' + "\r\n"
|
|
|
|
data << '<' + ns1 + ' xmlns:ns1="urn:SAPControl"></' + ns1 + '>' + "\r\n"
|
|
|
|
data << '</SOAP-ENV:Body>' + "\r\n"
|
|
|
|
data << '</SOAP-ENV:Envelope>' + "\r\n\r\n"
|
|
|
|
|
|
|
|
begin
|
|
|
|
res = send_request_raw({
|
|
|
|
'uri' => "/#{datastore['URI']}",
|
|
|
|
'method' => 'POST',
|
|
|
|
'data' => data,
|
|
|
|
'headers' =>
|
|
|
|
{
|
|
|
|
'Content-Length' => data.length,
|
|
|
|
'SOAPAction' => '""',
|
|
|
|
'Content-Type' => 'text/xml; charset=UTF-8',
|
|
|
|
}
|
|
|
|
}, 15)
|
|
|
|
|
|
|
|
if res.code == 200
|
|
|
|
body = res.body
|
|
|
|
if body.match(/<property>CentralServices<\/property><propertytype>Attribute<\/propertytype><value>([^<]+)<\/value>/)
|
2011-03-02 18:46:00 +00:00
|
|
|
centralservices = $1.strip
|
2011-03-02 10:18:31 +00:00
|
|
|
success = true
|
|
|
|
end
|
|
|
|
if body.match(/<property>SAPSYSTEM<\/property><propertytype>Attribute<\/propertytype><value>([^<]+)<\/value>/)
|
2011-03-02 18:46:00 +00:00
|
|
|
sapsystem = $1.strip
|
2011-03-02 10:18:31 +00:00
|
|
|
success = true
|
|
|
|
end
|
|
|
|
if body.match(/<property>SAPSYSTEMNAME<\/property><propertytype>Attribute<\/propertytype><value>([^<]+)<\/value>/)
|
2011-03-02 18:46:00 +00:00
|
|
|
sapsystemname = $1.strip
|
2011-03-02 10:18:31 +00:00
|
|
|
success = true
|
|
|
|
end
|
|
|
|
if body.match(/<property>SAPLOCALHOST<\/property><propertytype>Attribute<\/propertytype><value>([^<]+)<\/value>/)
|
2011-03-02 18:46:00 +00:00
|
|
|
saplocalhost = $1.strip
|
2011-03-02 10:18:31 +00:00
|
|
|
success = true
|
|
|
|
end
|
|
|
|
if body.match(/<property>INSTANCE_NAME<\/property><propertytype>Attribute<\/propertytype><value>([^<]+)<\/value>/)
|
2011-03-02 18:46:00 +00:00
|
|
|
instancename = $1.strip
|
2011-03-02 10:18:31 +00:00
|
|
|
success = true
|
|
|
|
end
|
|
|
|
if body.match(/<property>ICM<\/property><propertytype>NodeURL<\/propertytype><value>([^<]+)<\/value>/)
|
2011-03-02 18:46:00 +00:00
|
|
|
icmurl = $1.strip
|
2011-03-02 10:18:31 +00:00
|
|
|
success = true
|
|
|
|
end
|
2011-11-07 17:52:02 +00:00
|
|
|
if body.match(/<property>IGS<\/property><propertytype>NodeURL<\/propertytype><value>([^<]+)<\/value>/)
|
|
|
|
igsurl = $1.strip
|
|
|
|
success = true
|
|
|
|
end
|
2011-03-02 10:18:31 +00:00
|
|
|
if body.match(/<property>ABAP DB Connection<\/property><propertytype>Attribute<\/propertytype><value>([^<]+)<\/value>/)
|
2011-03-02 18:46:00 +00:00
|
|
|
dbstring = $1.strip
|
2011-03-02 10:18:31 +00:00
|
|
|
success = true
|
|
|
|
end
|
2011-11-07 17:52:02 +00:00
|
|
|
if body.match(/<property>J2EE DB Connection<\/property><propertytype>Attribute<\/propertytype><value>([^<]+)<\/value>/)
|
|
|
|
j2eedbstring = $1.strip
|
|
|
|
success = true
|
|
|
|
end
|
|
|
|
if body.match(/<property>Webmethods<\/property><propertytype>Attribute<\/propertytype><value>([^<]+)<\/value>/)
|
|
|
|
webmethods = $1.strip
|
|
|
|
success = true
|
|
|
|
end
|
|
|
|
if body.match(/<property>Protected Webmethods<\/property><propertytype>Attribute<\/propertytype><value>([^<]+)<\/value>/)
|
2011-03-02 18:46:00 +00:00
|
|
|
protectedweb = $1.strip
|
2011-03-02 10:18:31 +00:00
|
|
|
success = true
|
|
|
|
end
|
|
|
|
elsif res.code == 500
|
|
|
|
case res.body
|
|
|
|
when /<faultstring>(.*)<\/faultstring>/i
|
2011-03-02 18:46:00 +00:00
|
|
|
faultcode = $1.strip
|
2011-03-02 10:18:31 +00:00
|
|
|
fault = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
rescue ::Rex::ConnectionError
|
2011-03-11 16:50:18 +00:00
|
|
|
print_error("#{rhost}:#{rport} [SAP] Unable to connect")
|
2011-03-02 18:46:00 +00:00
|
|
|
return
|
2011-03-02 10:18:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if success
|
2011-03-11 16:50:18 +00:00
|
|
|
print_good("#{rhost}:#{rport} [SAP] Instance Properties Extracted")
|
2011-03-02 10:18:31 +00:00
|
|
|
if centralservices
|
2011-03-11 16:50:18 +00:00
|
|
|
print_good("#{rhost}:#{rport} [SAP] Central Services: #{centralservices}")
|
2011-03-02 10:18:31 +00:00
|
|
|
end
|
|
|
|
if sapsystem
|
2011-03-11 16:50:18 +00:00
|
|
|
print_good("#{rhost}:#{rport} [SAP] SAP System Number: #{sapsystem}")
|
2011-04-27 19:39:28 +00:00
|
|
|
report_note(:host => "#{rhost}",
|
2011-03-02 18:46:00 +00:00
|
|
|
:proto => 'tcp',
|
2011-04-27 19:39:28 +00:00
|
|
|
:port => "#{rport}",
|
2011-03-02 18:46:00 +00:00
|
|
|
:type => 'sap.sapsystem',
|
|
|
|
:data => {:proto => "soap", :sapsystem => sapsystem})
|
2011-03-02 10:18:31 +00:00
|
|
|
end
|
|
|
|
if sapsystemname
|
2011-03-11 16:50:18 +00:00
|
|
|
print_good("#{rhost}:#{rport} [SAP] SAP System Name: #{sapsystemname}")
|
2011-04-27 19:39:28 +00:00
|
|
|
report_note(:host => "#{rhost}",
|
2011-03-02 18:46:00 +00:00
|
|
|
:proto => 'tcp',
|
2011-04-27 19:39:28 +00:00
|
|
|
:port => "#{rport}",
|
2011-03-02 18:46:00 +00:00
|
|
|
:type => 'sap.systemname',
|
|
|
|
:data => {:proto => "soap", :sapsystemname => sapsystemname})
|
2011-03-02 10:18:31 +00:00
|
|
|
end
|
|
|
|
if saplocalhost
|
2011-03-11 16:50:18 +00:00
|
|
|
print_good("#{rhost}:#{rport} [SAP] SAP Localhost: #{saplocalhost}")
|
2011-04-27 19:39:28 +00:00
|
|
|
report_note(:host => "#{rhost}",
|
2011-03-02 18:46:00 +00:00
|
|
|
:proto => 'tcp',
|
2011-04-27 19:39:28 +00:00
|
|
|
:port => "#{rport}",
|
2011-03-02 18:46:00 +00:00
|
|
|
:type => 'sap.localhost',
|
|
|
|
:data => {:proto => "soap", :saplocalhost => saplocalhost})
|
2011-03-02 10:18:31 +00:00
|
|
|
end
|
|
|
|
if instancename
|
2011-03-11 16:50:18 +00:00
|
|
|
print_good("#{rhost}:#{rport} [SAP] Instance Name: #{instancename}")
|
2011-04-27 19:39:28 +00:00
|
|
|
report_note(:host => "#{rhost}",
|
2011-03-02 18:46:00 +00:00
|
|
|
:proto => 'tcp',
|
2011-04-27 19:39:28 +00:00
|
|
|
:port => "#{rport}",
|
2011-03-02 18:46:00 +00:00
|
|
|
:type => 'sap.instancename',
|
|
|
|
:data => {:proto => "soap", :instancename => instancename})
|
2011-03-02 10:18:31 +00:00
|
|
|
end
|
|
|
|
if icmurl
|
2011-03-11 16:50:18 +00:00
|
|
|
print_good("#{rhost}:#{rport} [SAP] ICM URL: #{icmurl}")
|
2011-04-27 19:39:28 +00:00
|
|
|
report_note(:host => "#{rhost}",
|
2011-03-02 18:46:00 +00:00
|
|
|
:proto => 'tcp',
|
2011-04-27 19:39:28 +00:00
|
|
|
:port => "#{rport}",
|
2011-03-02 18:46:00 +00:00
|
|
|
:type => 'sap.icm.url',
|
|
|
|
:data => {:proto => "soap", :icmurl => icmurl})
|
2011-03-02 10:18:31 +00:00
|
|
|
end
|
2011-11-07 17:52:02 +00:00
|
|
|
if igsurl
|
|
|
|
print_good("#{rhost}:#{rport} [SAP] IGS URL: #{igsurl}")
|
|
|
|
report_note(:host => "#{rhost}",
|
|
|
|
:proto => 'tcp',
|
|
|
|
:port => "#{rport}",
|
|
|
|
:type => 'sap.igs.url',
|
|
|
|
:data => {:proto => "soap", :igsurl => igsurl})
|
|
|
|
end
|
2011-03-02 10:18:31 +00:00
|
|
|
if dbstring
|
2011-11-07 17:52:02 +00:00
|
|
|
dbstring = CGI.unescapeHTML(dbstring)
|
|
|
|
print_good("#{rhost}:#{rport} [SAP] ABAP DATABASE: #{dbstring}")
|
2011-04-27 19:39:28 +00:00
|
|
|
report_note(:host => "#{rhost}",
|
2011-03-02 18:46:00 +00:00
|
|
|
:proto => 'tcp',
|
2011-04-27 19:39:28 +00:00
|
|
|
:port => "#{rport}",
|
2011-03-02 18:46:00 +00:00
|
|
|
:type => 'sap.dbstring',
|
|
|
|
:data => {:proto => "soap", :dbstring => dbstring},
|
|
|
|
:update => :unique_data )
|
2011-03-02 10:18:31 +00:00
|
|
|
end
|
2011-11-07 17:52:02 +00:00
|
|
|
if j2eedbstring
|
|
|
|
j2eedbstring = CGI.unescapeHTML(j2eedbstring)
|
|
|
|
print_good("#{rhost}:#{rport} [SAP] J2EE DATABASE: #{j2eedbstring}")
|
|
|
|
report_note(:host => "#{rhost}",
|
|
|
|
:proto => 'tcp',
|
|
|
|
:port => "#{rport}",
|
|
|
|
:type => 'sap.j2eedbstring',
|
|
|
|
:data => {:proto => "soap", :j2eedbstring => j2eedbstring},
|
|
|
|
:update => :unique_data )
|
|
|
|
end
|
2011-03-02 10:18:31 +00:00
|
|
|
if protectedweb
|
2011-11-07 17:52:02 +00:00
|
|
|
protectedweb_arr = protectedweb.split(",")
|
|
|
|
print_good("#{rhost}:#{rport} [SAP] Protected Webmethods (auth required) :")
|
|
|
|
protectedweb_arr.each do | pweb |
|
|
|
|
print_status("#{pweb}")
|
|
|
|
end
|
2011-04-27 19:39:28 +00:00
|
|
|
report_note(:host => "#{rhost}",
|
2011-03-02 18:46:00 +00:00
|
|
|
:proto => 'tcp',
|
2011-04-27 19:39:28 +00:00
|
|
|
:port => "#{rport}",
|
2011-03-02 18:46:00 +00:00
|
|
|
:type => 'sap.protected.web.methods',
|
|
|
|
:data => {:proto => "soap", :protectedweb => protectedweb},
|
|
|
|
:update => :unique_data )
|
2011-03-02 10:18:31 +00:00
|
|
|
end
|
2011-11-07 17:52:02 +00:00
|
|
|
if webmethods
|
|
|
|
webmethods_arr = webmethods.split(",")
|
|
|
|
print_good("#{rhost}:#{rport} [SAP] Unprotected Webmethods :")
|
|
|
|
webmethods_arr.each do | webm |
|
|
|
|
# Only print webmethods not found in protectedweb_arr
|
|
|
|
print_status("#{webm}") if not protectedweb_arr.include?(webm)
|
|
|
|
end
|
|
|
|
report_note(:host => "#{rhost}",
|
|
|
|
:proto => 'tcp',
|
|
|
|
:port => "#{rport}",
|
|
|
|
:type => 'sap.web.methods',
|
|
|
|
:data => {:proto => "soap", :webmethods => webmethods},
|
|
|
|
:update => :unique_data )
|
|
|
|
end
|
|
|
|
|
2011-03-02 10:18:31 +00:00
|
|
|
return
|
|
|
|
elsif fault
|
2011-10-18 00:54:05 +00:00
|
|
|
print_error("#{rhost}:#{rport} [SAP] Error code: #{faultcode}")
|
2011-03-02 10:18:31 +00:00
|
|
|
return
|
|
|
|
else
|
2011-11-07 17:52:02 +00:00
|
|
|
print_error("#{rhost}:#{rport} [SAP] Failed to identify instance properties")
|
2011-03-02 10:18:31 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|