rename loginTime->startTime. Interactive timeout. Fix str/bytes

This commit is contained in:
Michel Oosterhof 2018-07-15 14:53:45 +04:00
parent 948e9b8780
commit d957bff867
1 changed files with 10 additions and 7 deletions

View File

@ -30,7 +30,7 @@ from twisted.python.compat import _bytesChr as chr
class HoneyPotSSHTransport(transport.SSHServerTransport, TimeoutMixin): class HoneyPotSSHTransport(transport.SSHServerTransport, TimeoutMixin):
""" """
""" """
logintime = None startTime = None
gotVersion = False gotVersion = False
def __repr__(self): def __repr__(self):
@ -71,7 +71,7 @@ class HoneyPotSSHTransport(transport.SSHServerTransport, TimeoutMixin):
self.currentEncryptions = transport.SSHCiphers(b'none', b'none', b'none', b'none') self.currentEncryptions = transport.SSHCiphers(b'none', b'none', b'none', b'none')
self.currentEncryptions.setKeys(b'', b'', b'', b'', b'', b'') self.currentEncryptions.setKeys(b'', b'', b'', b'', b'', b'')
self.logintime = time.time() self.startTime = time.time()
try: try:
self.setTimeout(CONFIG.getint('honeypot', 'authentication_timeout')) self.setTimeout(CONFIG.getint('honeypot', 'authentication_timeout'))
except NoOptionError: except NoOptionError:
@ -86,6 +86,7 @@ class HoneyPotSSHTransport(transport.SSHServerTransport, TimeoutMixin):
return return
transport.SSHServerTransport.sendKexInit(self) transport.SSHServerTransport.sendKexInit(self)
def _unsupportedVersionReceived(self, remoteVersion): def _unsupportedVersionReceived(self, remoteVersion):
""" """
Change message to be like OpenSSH Change message to be like OpenSSH
@ -196,10 +197,12 @@ class HoneyPotSSHTransport(transport.SSHServerTransport, TimeoutMixin):
""" """
Remove login grace timeout, set zlib compression after auth Remove login grace timeout, set zlib compression after auth
""" """
# Reset timeout. Not everyone opens shell so need timeout at transport level
# Reset timeout. Not everyone opens shell so need timeout here also if service.name == b'ssh-connection':
if service.name == 'ssh-connection': try:
self.setTimeout(300) self.setTimeout(CONFIG.getint('honeypot', 'interactive_timeout'))
except NoOptionError:
self.setTimeout(300)
# when auth is successful we enable compression # when auth is successful we enable compression
# this is called right after MSG_USERAUTH_SUCCESS # this is called right after MSG_USERAUTH_SUCCESS
@ -220,7 +223,7 @@ class HoneyPotSSHTransport(transport.SSHServerTransport, TimeoutMixin):
transport.SSHServerTransport.connectionLost(self, reason) transport.SSHServerTransport.connectionLost(self, reason)
self.transport.connectionLost(reason) self.transport.connectionLost(reason)
self.transport = None self.transport = None
duration = time.time() - self.logintime duration = time.time() - self.startTime
log.msg(eventid='cowrie.session.closed', log.msg(eventid='cowrie.session.closed',
format="Connection lost after %(duration)d seconds", format="Connection lost after %(duration)d seconds",
duration=duration) duration=duration)