Skip to content

Commit

Permalink
Recognise broken SMB sessions and close them
Browse files Browse the repository at this point in the history
  • Loading branch information
smashery committed Dec 16, 2024
1 parent 50b1259 commit 40f2eaa
Show file tree
Hide file tree
Showing 16 changed files with 226 additions and 204 deletions.
10 changes: 8 additions & 2 deletions lib/msf/base/sessions/smb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Msf::Sessions::SMB
# @option opts [RubySMB::Client] :client
def initialize(rstream, opts = {})
@client = opts.fetch(:client)
@simple_client = ::Rex::Proto::SMB::SimpleClient.new(client.dispatcher.tcp_socket, client: client)
@simple_client = ::Rex::Proto::SMB::SimpleClient.new(client.dispatcher.tcp_socket, client: client, msf_session: self)
self.console = Rex::Post::SMB::Ui::Console.new(self)
super(rstream, opts)
end
Expand Down Expand Up @@ -53,6 +53,13 @@ def process_autoruns(datastore)
end
end

def verify_connectivity
@client.dispatcher.tcp_socket.peerinfo
rescue Errno::ENOTCONN
self.kill
raise
end

def type
self.class.type
end
Expand Down Expand Up @@ -140,5 +147,4 @@ def _interact_stream
# the EOFError so we can drop this handle like a bad habit.
raise EOFError if (console.stopped? == true)
end

end
Loading

0 comments on commit 40f2eaa

Please sign in to comment.