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
|
2012-02-21 01:40:50 +00:00
|
|
|
# web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/
|
2011-03-02 10:18:31 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
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 getEnvironment',
|
|
|
|
'Version' => '$Revision$',
|
2011-07-28 22:57:47 +00:00
|
|
|
'Description' => %q{
|
|
|
|
This module simply attempts to identify SAP Environment
|
|
|
|
settings 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 ])
|
2011-03-11 16:50:18 +00:00
|
|
|
deregister_options('RHOST')
|
2011-03-02 10:18:31 +00:00
|
|
|
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 16:29:15 +00:00
|
|
|
|
|
|
|
if not res
|
|
|
|
print_error("#{rhost}:#{rport} [SAP] Unable to connect")
|
|
|
|
return
|
|
|
|
end
|
2011-03-02 10:18:31 +00:00
|
|
|
|
|
|
|
getEnvironment(ip)
|
|
|
|
end
|
|
|
|
|
|
|
|
def getEnvironment(rhost)
|
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:GetEnvironment'
|
|
|
|
|
|
|
|
data = '<?xml version="1.0" encoding="utf-8"?>' + "\r\n"
|
|
|
|
data << '<SOAP-ENV:Envelope xmlns:SOAP-ENV="' + soapenv + '" xmlns:xsi="' + xsi + '" xmlns:xs="' + xs + '">' + "\r\n"
|
|
|
|
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)
|
|
|
|
|
|
|
|
env = []
|
|
|
|
|
|
|
|
if res.code == 200
|
|
|
|
case res.body
|
|
|
|
when nil
|
|
|
|
# Nothing
|
|
|
|
when /<item>([^<]+)<\/item>/i
|
|
|
|
body = []
|
|
|
|
body = res.body
|
|
|
|
env = body.scan(/<item>([^<]+)<\/item>/i)
|
|
|
|
success = true
|
|
|
|
end
|
2011-03-11 16:50:18 +00:00
|
|
|
elsif res.code == 500
|
2011-03-02 10:18:31 +00:00
|
|
|
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 10:18:31 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if success
|
2011-03-02 18:46:00 +00:00
|
|
|
print_good("#{rhost}:#{rport} [SAP] Environment Extracted: #{env.length} entries extracted")
|
|
|
|
report_note(
|
|
|
|
:host => rhost,
|
|
|
|
:proto => 'tcp',
|
|
|
|
:port => rport,
|
|
|
|
:type => 'sap.env',
|
|
|
|
:data => {:proto => "soap", :env => env},
|
2011-03-02 21:35:31 +00:00
|
|
|
:update => :unique_data
|
2011-03-02 18:46:00 +00:00
|
|
|
)
|
2011-11-20 02:12:07 +00:00
|
|
|
|
2011-03-11 16:50:18 +00:00
|
|
|
env.each do |output|
|
2011-10-20 16:29:15 +00:00
|
|
|
print_status("#{output[0]}")
|
2011-03-11 16:50:18 +00:00
|
|
|
end
|
2011-11-20 02:12:07 +00:00
|
|
|
|
2011-03-02 10:18:31 +00:00
|
|
|
elsif fault
|
2011-10-20 16:29:15 +00:00
|
|
|
print_error("#{rhost}:#{rport} [SAP] Error code: #{faultcode}")
|
2011-03-02 10:18:31 +00:00
|
|
|
return
|
|
|
|
else
|
2011-03-11 16:50:18 +00:00
|
|
|
print_error("#{rhost}:#{rport} [SAP] failed to request environment")
|
2011-03-02 10:18:31 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|