diff --git a/cowrie/core/protocol.py b/cowrie/core/protocol.py index 02cfd38..1852f92 100644 --- a/cowrie/core/protocol.py +++ b/cowrie/core/protocol.py @@ -107,8 +107,6 @@ class HoneyPotBaseProtocol(insults.TerminalProtocol, TimeoutMixin): def connectionLost(self, reason): """ - this is only called on explicit logout, not on disconnect - this indicates the closing of the channel/session, not the closing of the transport """ self.setTimeout(None) insults.TerminalProtocol.connectionLost(self, reason) @@ -273,9 +271,11 @@ class HoneyPotInteractiveProtocol(HoneyPotBaseProtocol, recvline.HistoricRecvLin def connectionLost(self, reason): """ - this doesn't seem to be called upon disconnect, so please use - HoneyPotTransport.connectionLost instead """ + transport = self.terminal.transport.session.conn.transport + if transport.transport.sessionno in transport.factory.sessions: + del transport.factory.sessions[transport.transport.sessionno] + self.lastlogExit() HoneyPotBaseProtocol.connectionLost(self, reason) recvline.HistoricRecvLine.connectionLost(self, reason) diff --git a/cowrie/ssh/transport.py b/cowrie/ssh/transport.py index 2124c48..7156029 100644 --- a/cowrie/ssh/transport.py +++ b/cowrie/ssh/transport.py @@ -264,8 +264,6 @@ class HoneyPotTransport(transport.SSHServerTransport, TimeoutMixin): This seems to be the only reliable place of catching lost connection """ self.setTimeout(None) - if self.transport.sessionno in self.factory.sessions: - del self.factory.sessions[self.transport.sessionno] transport.SSHServerTransport.connectionLost(self, reason) self.transport.connectionLost(reason) self.transport = None