@@ -760,13 +760,15 @@ def smb_recv(c)
760
760
# Handle any number of errors that a read can trigger depending on socket state
761
761
rescue ::IOError , ::EOFError ,
762
762
::Errno ::ECONNRESET , ::Errno ::ENOTCONN , ::Errno ::ECONNABORTED ,
763
- ::Errno ::ETIMEDOUT , ::Errno ::ENETRESET , ::Errno ::ESHUTDOWN
763
+ ::Errno ::ETIMEDOUT , ::Errno ::ENETRESET , ::Errno ::ESHUTDOWN
764
+ vprint_status ( "Dropping connection from #{ smb [ :name ] } due to exception: #{ $!. class } #{ $!} " )
764
765
smb_stop ( c )
765
766
return
766
767
end
767
768
768
769
# The client said it had data, but lied, kill the session
769
770
unless buff and buff . length > 0
771
+ vprint_status ( "Dropping connection from #{ smb [ :name ] } due to empty payload..." )
770
772
smb_stop ( c )
771
773
return
772
774
end
@@ -776,6 +778,7 @@ def smb_recv(c)
776
778
777
779
# Prevent a simplistic DoS if the buffer is too big
778
780
if smb [ :data ] . length > ( 1024 *1024 *datastore [ 'SMBServerMaximumBuffer' ] )
781
+ vprint_status ( "Dropping connection from #{ smb [ :name ] } due to oversized buffer of #{ smb [ :data ] . length } bytes..." )
779
782
smb_stop ( c )
780
783
return
781
784
end
@@ -823,10 +826,11 @@ def smb_recv(c)
823
826
pkt = CONST ::SMB_BASE_PKT . make_struct
824
827
pkt . from_s ( buff )
825
828
826
- # Only response to requests, ignore server replies
829
+ # Only respond to requests, ignore server replies
827
830
if ( pkt [ 'Payload' ] [ 'SMB' ] . v [ 'Flags1' ] & 128 != 0 )
828
- print_status ( "Ignoring server response from #{ smb [ :name ] } " )
829
- next
831
+ vprint_status ( "Dropping connection from #{ smb [ :name ] } due to missing client request flag" )
832
+ smb_stop ( c )
833
+ return
830
834
end
831
835
832
836
cmd = pkt [ 'Payload' ] [ 'SMB' ] . v [ 'Command' ]
@@ -895,7 +899,10 @@ def smb_pool_update(c)
895
899
end
896
900
897
901
# Purge any idle connections to rescue file descriptors
898
- purge_list . each { |sc | smb_stop ( sc ) }
902
+ purge_list . each do |sc |
903
+ vprint_status ( "Dropping connection from #{ @state [ sc ] [ :name ] } due to idle timeout..." )
904
+ smb_stop ( sc )
905
+ end
899
906
end
900
907
end
901
908
0 commit comments