From 950541b42ecee5a31770eda8ba47e9b9a96b94fa Mon Sep 17 00:00:00 2001 From: fe7ch Date: Sat, 29 Jul 2017 20:19:15 +0300 Subject: [PATCH] Fix unicode issue (#559) * Fix unicode issue * Fix unicode issue --- cowrie/commands/base.py | 8 ++++---- cowrie/telnet/transport.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cowrie/commands/base.py b/cowrie/commands/base.py index 2221def6..f8c49d43 100644 --- a/cowrie/commands/base.py +++ b/cowrie/commands/base.py @@ -131,7 +131,7 @@ class command_echo(HoneyPotCommand): optlist, args = getopt.getopt(self.args, "eEn") for opt in optlist: if opt[0] == '-e': - escape_fn = functools.partial(str.decode, encoding="string_escape") + escape_fn = functools.partial(unicode.decode, encoding="string_escape") elif opt[0] == '-E': escape_fn = lambda s: s elif opt[0] == '-n': @@ -142,7 +142,7 @@ class command_echo(HoneyPotCommand): # FIXME: Wrap in exception, Python escape cannot handle single digit \x codes (e.g. \x1) try: self.write(escape_fn(re.sub('(?<=\\\\)x([0-9a-fA-F]{1})(?=\\\\|\"|\'|\s|$)', 'x0\g<1>', - ''.join(args).replace('\\\\x', '\\x')).strip('\"\''))) + ''.join(args).replace(b'\\\\x', b'\\x')).strip(b'\"\''))) except ValueError as e: log.msg("echo command received Python incorrect hex escape") @@ -162,9 +162,9 @@ class command_printf(HoneyPotCommand): else: if '-v' not in self.args: if len(self.args) < 2: - escape_fn = functools.partial(str.decode, encoding="string_escape") + escape_fn = functools.partial(unicode.decode, encoding="string_escape") self.write(escape_fn(re.sub('(?<=\\\\)x([0-9a-fA-F])(?=\\\\|\"|\'|\s|$)', 'x0\g<1>', - ''.join(self.args[0]).replace('\\\\x', '\\x'))).strip('\"\'')) + ''.join(self.args[0]).replace(b'\\\\x', b'\\x'))).strip(b'\"\'')) commands['printf'] = command_printf diff --git a/cowrie/telnet/transport.py b/cowrie/telnet/transport.py index 6d2982d2..8f4068c5 100644 --- a/cowrie/telnet/transport.py +++ b/cowrie/telnet/transport.py @@ -228,7 +228,7 @@ class CowrieTelnetTransport(TelnetTransport, TimeoutMixin): It is kind of a hack. I asked for a better solution here: http://stackoverflow.com/questions/35087250/twisted-telnet-server-how-to-avoid-nested-crlf """ - self.transport.write(bytes.replace('\r\n', '\n')) + self.transport.write(bytes.replace(b'\r\n', b'\n')) def connectionLost(self, reason):