From 8fa666b75d47ead50be208c9b05034fd09725d7f Mon Sep 17 00:00:00 2001 From: HD Moore Date: Sun, 28 Sep 2014 17:41:21 -0700 Subject: [PATCH] Verbose messages on why a connection is closed --- lib/msf/core/exploit/smb.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/msf/core/exploit/smb.rb b/lib/msf/core/exploit/smb.rb index 85b1bfc07f..587d716c98 100644 --- a/lib/msf/core/exploit/smb.rb +++ b/lib/msf/core/exploit/smb.rb @@ -760,13 +760,15 @@ module Exploit::Remote::SMBServer # Handle any number of errors that a read can trigger depending on socket state rescue ::IOError, ::EOFError, ::Errno::ECONNRESET, ::Errno::ENOTCONN, ::Errno::ECONNABORTED, - ::Errno::ETIMEDOUT, ::Errno::ENETRESET, ::Errno::ESHUTDOWN + ::Errno::ETIMEDOUT, ::Errno::ENETRESET, ::Errno::ESHUTDOWN + vprint_status("Dropping connection from #{smb[:name]} due to exception: #{$!.class} #{$!}") smb_stop(c) return end # The client said it had data, but lied, kill the session unless buff and buff.length > 0 + vprint_status("Dropping connection from #{smb[:name]} due to empty payload...") smb_stop(c) return end @@ -776,6 +778,7 @@ module Exploit::Remote::SMBServer # Prevent a simplistic DoS if the buffer is too big if smb[:data].length > (1024*1024*datastore['SMBServerMaximumBuffer']) + vprint_status("Dropping connection from #{smb[:name]} due to oversized buffer of #{smb[:data].length} bytes...") smb_stop(c) return end @@ -823,10 +826,11 @@ module Exploit::Remote::SMBServer pkt = CONST::SMB_BASE_PKT.make_struct pkt.from_s(buff) - # Only response to requests, ignore server replies + # Only respond to requests, ignore server replies if (pkt['Payload']['SMB'].v['Flags1'] & 128 != 0) - print_status("Ignoring server response from #{smb[:name]}") - next + vprint_status("Dropping connection from #{smb[:name]} due to missing client request flag") + smb_stop(c) + return end cmd = pkt['Payload']['SMB'].v['Command'] @@ -895,7 +899,10 @@ module Exploit::Remote::SMBServer end # Purge any idle connections to rescue file descriptors - purge_list.each { |sc| smb_stop(sc) } + purge_list.each do |sc| + vprint_status("Dropping connection from #{@state[sc][:name]} due to idle timeout...") + smb_stop(sc) + end end end