Add retro-compatibility for Python 2.7 (#1198)

* add retro-compatibility for Python 2.7
This commit is contained in:
Guilherme Borges
2019-09-05 07:49:50 +01:00
committed by GitHub
parent a0e1e1251b
commit 69ced5431f
6 changed files with 23 additions and 17 deletions

View File

@ -2,20 +2,21 @@ from twisted.conch.ssh import channel, common, connection, transport, userauth
from twisted.internet import defer, protocol, reactor
class PasswordAuth(userauth.SSHUserAuthClient):
# object is added for Python 2.7 compatibility (#1198) - as is super with args
class PasswordAuth(userauth.SSHUserAuthClient, object):
def __init__(self, user, password, conn):
super().__init__(user, conn)
super(PasswordAuth, self).__init__(user, conn)
self.password = password
def getPassword(self, prompt=None):
return defer.succeed(self.password)
class CommandChannel(channel.SSHChannel):
class CommandChannel(channel.SSHChannel, object):
name = 'session'
def __init__(self, command, done_deferred, callback, *args, **kwargs):
super().__init__(*args, **kwargs)
super(CommandChannel, self).__init__(*args, **kwargs)
self.command = command
self.done_deferred = done_deferred
self.callback = callback
@ -40,9 +41,9 @@ class CommandChannel(channel.SSHChannel):
self.callback(self.data)
class ClientConnection(connection.SSHConnection):
class ClientConnection(connection.SSHConnection, object):
def __init__(self, cmd, done_deferred, callback):
super().__init__()
super(ClientConnection, self).__init__()
self.command = cmd
self.done_deferred = done_deferred
self.callback = callback

View File

@ -24,7 +24,8 @@ from cowrie.ssh_proxy import server_transport as proxyTransport
from cowrie.ssh_proxy.userauth import ProxySSHAuthServer
class CowrieSSHFactory(factory.SSHFactory):
# object is added for Python 2.7 compatibility (#1198) - as is super with args
class CowrieSSHFactory(factory.SSHFactory, object):
"""
This factory creates HoneyPotSSHTransport instances
They listen directly to the TCP port
@ -48,7 +49,7 @@ class CowrieSSHFactory(factory.SSHFactory):
b'ssh-userauth': ProxySSHAuthServer if self.backend == 'proxy' else HoneyPotSSHUserAuthServer,
b'ssh-connection': connection.CowrieSSHConnection,
}
super().__init__()
super(CowrieSSHFactory, self).__init__()
def logDispatch(self, *msg, **args):
"""

View File

@ -8,9 +8,10 @@ from twisted.conch.ssh.common import getNS
from cowrie.ssh import userauth
class ProxySSHAuthServer(userauth.HoneyPotSSHUserAuthServer):
# object is added for Python 2.7 compatibility (#1198) - as is super with args
class ProxySSHAuthServer(userauth.HoneyPotSSHUserAuthServer, object):
def __init__(self):
super().__init__()
super(ProxySSHAuthServer, self).__init__()
self.triedPassword = None
def auth_password(self, packet):
@ -19,7 +20,7 @@ class ProxySSHAuthServer(userauth.HoneyPotSSHUserAuthServer):
"""
self.triedPassword = getNS(packet[1:])[0]
return super().auth_password(packet)
return super(ProxySSHAuthServer, self).auth_password(packet)
def _cbFinishedAuth(self, result):
"""

View File

@ -19,7 +19,8 @@ from cowrie.telnet.userauth import HoneyPotTelnetAuthProtocol
from cowrie.telnet_proxy.server_transport import FrontendTelnetTransport
class HoneyPotTelnetFactory(protocol.ServerFactory):
# object is added for Python 2.7 compatibility (#1198) - as is super with args
class HoneyPotTelnetFactory(protocol.ServerFactory, object):
"""
This factory creates HoneyPotTelnetAuthProtocol instances
They listen directly to the TCP port
@ -32,7 +33,7 @@ class HoneyPotTelnetFactory(protocol.ServerFactory):
def __init__(self, backend, pool_handler):
self.backend = backend
self.pool_handler = pool_handler
super().__init__()
super(HoneyPotTelnetFactory, self).__init__()
# TODO logging clarity can be improved: see what SSH does
def logDispatch(self, *msg, **args):

View File

@ -7,7 +7,8 @@ from twisted.protocols.policies import TimeoutMixin
from twisted.python import log
class BackendTelnetTransport(TelnetTransport, TimeoutMixin):
# object is added for Python 2.7 compatibility (#1198) - as is super with args
class BackendTelnetTransport(TelnetTransport, TimeoutMixin, object):
def __init__(self):
# self.delayedPacketsToFrontend = []
self.backendConnected = False
@ -26,7 +27,7 @@ class BackendTelnetTransport(TelnetTransport, TimeoutMixin):
self.transport.write(packet)
self.factory.server.delayedPacketsToBackend = []
super().connectionMade()
super(TelnetTransport, self).connectionMade()
# TODO timeout if no backend available
def connectionLost(self, reason):

View File

@ -21,9 +21,10 @@ from cowrie.telnet_proxy import client_transport
from cowrie.telnet_proxy.handler import TelnetHandler
class FrontendTelnetTransport(TelnetTransport, TimeoutMixin):
# object is added for Python 2.7 compatibility (#1198) - as is super with args
class FrontendTelnetTransport(TelnetTransport, TimeoutMixin, object):
def __init__(self):
super().__init__()
super(FrontendTelnetTransport, self).__init__()
self.peer_ip = None
self.peer_port = 0