diff --git a/src/cowrie/ssh_proxy/protocols/exec_term.py b/src/cowrie/ssh_proxy/protocols/exec_term.py index 1da03489..8429c3e3 100644 --- a/src/cowrie/ssh_proxy/protocols/exec_term.py +++ b/src/cowrie/ssh_proxy/protocols/exec_term.py @@ -40,11 +40,13 @@ class ExecTerm(base_protocol.BaseProtocol): def __init__(self, uuid, channelName, ssh, channelId, command): super().__init__(uuid, channelName, ssh) - log.msg( - eventid="cowrie.command.input", - input=command.decode("ascii"), - format="CMD: %(input)s", - ) + try: + log.msg(eventid='cowrie.command.input', + input=command.decode('utf8'), + format='CMD: %(input)s') + except UnicodeDecodeError: + log.err("Unusual execcmd: {}".format(repr(command))) + self.transportId = ssh.server.transportId self.channelId = channelId diff --git a/src/cowrie/ssh_proxy/protocols/term.py b/src/cowrie/ssh_proxy/protocols/term.py index bb863680..3c6c3880 100644 --- a/src/cowrie/ssh_proxy/protocols/term.py +++ b/src/cowrie/ssh_proxy/protocols/term.py @@ -115,14 +115,16 @@ class Term(base_protocol.BaseProtocol): self.command += b"^C" self.data = self.data[1:] - if self.command != b"": - log.msg( - eventid="cowrie.command.input", - input=self.command.decode("ascii"), - format="CMD: %(input)s", - ) + + try: + if self.command != b'': + log.msg(eventid='cowrie.command.input', + input=self.command.decode('utf8'), + format='CMD: %(input)s') + except UnicodeDecodeError: + log.err("Unusual execcmd: {}".format(repr(self.command))) - self.command = b"" + self.command = b'' self.pointer = 0 # If Home Pressed elif self.data[:3] == b"\x1b\x4f\x48":