Skip to content

Commit 29ac27f

Browse files
author
HD Moore
committed
Lands rapid7#4813, replaces print_* with exceptions
2 parents c820431 + bf2be79 commit 29ac27f

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

lib/metasploit/framework/afp/client.rb

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ def login(user, pass)
7777
begin
7878
response = sock.timed_read(1024, self.login_timeout)
7979
rescue Timeout::Error
80-
#vprint_error("AFP #{rhost}:#{rport} Login timeout (AFP server delay response for 20 - 22 seconds after 7 incorrect logins)")
81-
return :connection_error
80+
raise RuntimeError, "AFP Login timeout (AFP server delay response for 20 - 22 seconds after 7 incorrect logins)"
8281
end
8382

8483
flags, command, request_id, error_code, length, reserved = parse_header(response)
@@ -87,8 +86,7 @@ def login(user, pass)
8786
when -5001 #kFPAuthContinue
8887
return parse_login_response_add_send_login_count(response, {:p => p, :g => g, :ra => ra, :ma => ma,
8988
:password => pass, :user => user})
90-
when -5023 #kFPUserNotAuth (User dosen't exists)
91-
#print_status("AFP #{rhost}:#{rport} User #{user} dosen't exists")
89+
when -5023 #kFPUserNotAuth (User dosen't exists)
9290
return :skip_user
9391
else
9492
return :connection_error
@@ -123,8 +121,7 @@ def no_user_authent_login
123121
begin
124122
response = sock.timed_read(1024, self.login_timeout)
125123
rescue Timeout::Error
126-
vprint_error("AFP #{rhost}:#{rport} Login timeout (AFP server delay response for 20 - 22 seconds after 7 incorrect logins)")
127-
return :connection_error
124+
raise RuntimeError, "AFP Login timeout (AFP server delay response for 20 - 22 seconds after 7 incorrect logins)"
128125
end
129126

130127
flags, command, request_id, error_code, length, reserved = parse_header(response)
@@ -180,8 +177,7 @@ def parse_login_response_add_send_login_count(response, data)
180177
begin
181178
response = sock.timed_read(1024, self.login_timeout)
182179
rescue Timeout::Error
183-
vprint_error("AFP #{rhost}:#{rport} Login timeout (AFP server delay response for 20 - 22 seconds after 7 incorrect logins)")
184-
return :connection_error
180+
raise RuntimeError, "AFP Login timeout (AFP server delay response for 20 - 22 seconds after 7 incorrect logins)"
185181
end
186182

187183
flags, command, request_id, error_code, length, reserved = parse_header(response)
@@ -201,7 +197,7 @@ def parse_info_response(response)
201197
parsed_data = {}
202198

203199
flags, command, request_id, error_code, length, reserved = parse_header(response)
204-
raise "AFP #{rhost}:#{rport} Server response with error" if error_code != 0
200+
raise RuntimeError, "AFP Server response with error" if error_code != 0
205201
body = get_body(response, length)
206202
machine_type_offset, afp_versions_offset, uam_count_offset, icon_offset, server_flags =
207203
body.unpack('nnnnn')
@@ -243,7 +239,7 @@ def parse_header(packet)
243239

244240
def get_body(packet, body_length)
245241
body = packet[16..body_length + 15]
246-
raise "AFP #{rhost}:#{rport} Invalid body length" if body.length != body_length
242+
raise RuntimeError, "AFP Invalid body length" if body.length != body_length
247243
return body
248244
end
249245

@@ -291,7 +287,7 @@ def parse_network_addresses(network_addresses)
291287
when 7 # IPv6 address (16 bytes) followed by a two-byte port number
292288
parsed_addreses << "[#{IPAddr.ntop(address[1..16])}]:#{address[17..18].unpack("n").first}"
293289
else # Something wrong?
294-
raise "Error parsing network addresses"
290+
raise RuntimeError, "Error parsing network addresses"
295291
end
296292
end
297293
return parsed_addreses

lib/metasploit/framework/login_scanner/afp.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ def attempt_login(credential)
3131
rescue Rex::ConnectionError, EOFError, Timeout::Error
3232
status = Metasploit::Model::Login::Status::UNABLE_TO_CONNECT
3333
else
34-
success = login(credential.public, credential.private)
34+
begin
35+
success = login(credential.public, credential.private)
36+
rescue RuntimeError => e
37+
return {:status => Metasploit::Model::Login::Status::UNABLE_TO_CONNECT, :proof => e.message}
38+
end
39+
3540
status = (success == true) ? Metasploit::Model::Login::Status::SUCCESSFUL : Metasploit::Model::Login::Status::INCORRECT
3641
end
3742

lib/metasploit/framework/mssql/client.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ def mssql_login(user='sa', pass='', db='', domain_name='')
5151

5252
# Send a prelogin packet and check that encryption is not enabled
5353
if mssql_prelogin() != ENCRYPT_NOT_SUP
54-
print_error("Encryption is not supported")
55-
return false
54+
raise ::Rex::ConnectionError, "Encryption is not supported"
5655
end
5756

5857
if windows_authentication

0 commit comments

Comments
 (0)