Skip to content

Commit e64804d

Browse files
committed
Merge pull request #13 from bcook-r7/land-6039-mssql_idf
catch more network exceptions
2 parents 55895c6 + dea0142 commit e64804d

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

lib/msf/core/exploit/mssql.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,12 +385,18 @@ def mssql_login(user='sa', pass='', db='')
385385
disconnect if self.sock
386386
connect
387387

388-
# Send a prelogin packet and check that encryption is not enabled
389-
if mssql_prelogin() != ENCRYPT_NOT_SUP
390-
print_error("Encryption is not supported")
388+
begin
389+
# Send a prelogin packet and check that encryption is not enabled
390+
if mssql_prelogin() != ENCRYPT_NOT_SUP
391+
print_error("Encryption is not supported")
392+
return false
393+
end
394+
rescue EOFError
395+
print_error("Probable server or network failure.")
391396
return false
392397
end
393398

399+
394400
if datastore['USE_WINDOWS_AUTHENT']
395401

396402
idx = 0
@@ -623,7 +629,12 @@ def mssql_login(user='sa', pass='', db='')
623629
# Packet header and total length including header
624630
pkt = "\x10\x01" + [pkt.length + 8].pack('n') + [0].pack('n') + [1].pack('C') + "\x00" + pkt
625631

626-
resp = mssql_send_recv(pkt)
632+
begin
633+
resp = mssql_send_recv(pkt)
634+
rescue EOFError
635+
print_error("Probable server or network failure.")
636+
return false
637+
end
627638

628639
end
629640

modules/auxiliary/admin/mssql/mssql_idf.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,16 @@ def run
9494
sql += "CLOSE table_cursor "
9595
sql += "DEALLOCATE table_cursor "
9696

97-
if mssql_login_datastore
98-
result = mssql_query(sql, false)
99-
else
100-
print_error('Login failed')
97+
begin
98+
if mssql_login_datastore
99+
result = mssql_query(sql, false)
100+
column_data = result[:rows]
101+
else
102+
print_error('Login failed')
103+
return
104+
end
105+
rescue Rex::ConnectionRefused => e
106+
print_error("Connection failed: #{e}")
101107
return
102108
end
103109

0 commit comments

Comments
 (0)