diff --git a/requirements.txt b/requirements.txt index 20dcd949..7a7c75d9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,3 +11,4 @@ service_identity==18.1.0 python-dateutil==2.8.0 tftpy==0.8.0 bcrypt==3.1.7 +treq diff --git a/src/backend_pool/ssh_exec.py b/src/backend_pool/ssh_exec.py index 5237652c..5f196eae 100644 --- a/src/backend_pool/ssh_exec.py +++ b/src/backend_pool/ssh_exec.py @@ -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 diff --git a/src/cowrie/commands/tftp.py b/src/cowrie/commands/tftp.py index 8fa96ca5..3817226c 100644 --- a/src/cowrie/commands/tftp.py +++ b/src/cowrie/commands/tftp.py @@ -7,7 +7,7 @@ from twisted.python import log from cowrie.core.artifact import Artifact from cowrie.core.config import CowrieConfig from cowrie.shell.command import HoneyPotCommand -from cowrie.shell.customparser import CustomParser, OptionNotFound +from cowrie.shell.customparser import CustomParser commands = {} @@ -94,7 +94,7 @@ class command_tftp(HoneyPotCommand): if len(args.c) > 1: self.file_to_get = args.c[1] if args.hostname is None: - raise OptionNotFound("Hostname is invalid") + self.exit() self.hostname = args.hostname elif args.r: @@ -102,10 +102,10 @@ class command_tftp(HoneyPotCommand): self.hostname = args.g else: parser.print_usage() - raise OptionNotFound("Missing!!") + self.exit() if self.hostname is None: - raise OptionNotFound("Hostname is invalid") + self.exit() if self.hostname.find(':') != -1: host, port = self.hostname.split(':') diff --git a/src/cowrie/ssh/factory.py b/src/cowrie/ssh/factory.py index b9b5a449..93d4d939 100644 --- a/src/cowrie/ssh/factory.py +++ b/src/cowrie/ssh/factory.py @@ -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): """ diff --git a/src/cowrie/ssh_proxy/userauth.py b/src/cowrie/ssh_proxy/userauth.py index 8a36d678..0911f1fa 100644 --- a/src/cowrie/ssh_proxy/userauth.py +++ b/src/cowrie/ssh_proxy/userauth.py @@ -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): """ diff --git a/src/cowrie/telnet/factory.py b/src/cowrie/telnet/factory.py index 6acd41fc..023c80ba 100644 --- a/src/cowrie/telnet/factory.py +++ b/src/cowrie/telnet/factory.py @@ -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): diff --git a/src/cowrie/telnet_proxy/client_transport.py b/src/cowrie/telnet_proxy/client_transport.py index c3ca6e7f..e413237d 100644 --- a/src/cowrie/telnet_proxy/client_transport.py +++ b/src/cowrie/telnet_proxy/client_transport.py @@ -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): diff --git a/src/cowrie/telnet_proxy/server_transport.py b/src/cowrie/telnet_proxy/server_transport.py index 37b856fa..fa30fd27 100644 --- a/src/cowrie/telnet_proxy/server_transport.py +++ b/src/cowrie/telnet_proxy/server_transport.py @@ -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