Skip to content

Commit 4966082

Browse files
author
HD Moore
committed
Replace 'rescue nil' with DRY-violating versions :(
1 parent 85c5de0 commit 4966082

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

lib/msf/core/exploit/smb.rb

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -736,8 +736,16 @@ def smb_conn(c)
736736
end
737737

738738
def smb_stop(c)
739+
739740
# Make sure the socket is closed
740-
c.close rescue nil
741+
begin
742+
c.close
743+
# Handle any number of errors that a double-close or failed shutdown can trigger
744+
rescue ::IOError, ::EOFError,
745+
::Errno::ECONNRESET, ::Errno::ENOTCONN, ::Errno::ECONNABORTED,
746+
::Errno::ETIMEDOUT, ::Errno::ENETRESET, ::Errno::ESHUTDOWN
747+
end
748+
741749
# Delete the state table entry
742750
@state.delete(c)
743751
end
@@ -746,8 +754,16 @@ def smb_recv(c)
746754
smb = @state[c]
747755
smb[:data] ||= ''
748756

749-
# Capture any low-level timeout exceptions to prevent it from bubbling
750-
buff = c.get_once(-1, 0.25) rescue nil
757+
buff = ''
758+
begin
759+
buff = c.get_once(-1, 0.25)
760+
# Handle any number of errors that a read can trigger depending on socket state
761+
rescue ::IOError, ::EOFError,
762+
::Errno::ECONNRESET, ::Errno::ENOTCONN, ::Errno::ECONNABORTED,
763+
::Errno::ETIMEDOUT, ::Errno::ENETRESET, ::Errno::ESHUTDOWN
764+
smb_stop(c)
765+
return
766+
end
751767

752768
# The client said it had data, but lied, kill the session
753769
unless buff and buff.length > 0

0 commit comments

Comments
 (0)