This commit is contained in:
Michel Oosterhof
2019-09-06 14:02:51 +01:00
8 changed files with 28 additions and 21 deletions

View File

@ -11,3 +11,4 @@ service_identity==18.1.0
python-dateutil==2.8.0
tftpy==0.8.0
bcrypt==3.1.7
treq

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

@ -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(':')

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