From 83e7995178df5acd6862447bb4450b82f26b04fd Mon Sep 17 00:00:00 2001 From: Michel Oosterhof Date: Sun, 16 Jul 2017 12:21:56 +0400 Subject: [PATCH] send unicode to shlex --- cowrie/core/honeypot.py | 2 ++ cowrie/core/shlex.py | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cowrie/core/honeypot.py b/cowrie/core/honeypot.py index 32c773c8..7ba2d9c3 100644 --- a/cowrie/core/honeypot.py +++ b/cowrie/core/honeypot.py @@ -141,6 +141,7 @@ class HoneyPotCommand(object): """ log.msg('QUEUED INPUT: {}'.format(line)) # FIXME: naive command parsing, see lineReceived below + line=unicode(line) self.protocol.cmdstack[0].cmdpending.append(shlex.split(line)) @@ -184,6 +185,7 @@ class HoneyPotShell(object): """ """ log.msg(eventid='cowrie.command.input', input=line, format='CMD: %(input)s') + line=unicode(line) self.lexer = shlex.shlex(instream=line, punctuation_chars=True) tokens = [] while True: diff --git a/cowrie/core/shlex.py b/cowrie/core/shlex.py index 9e224956..2c47dfb7 100644 --- a/cowrie/core/shlex.py +++ b/cowrie/core/shlex.py @@ -14,7 +14,7 @@ import re import sys from collections import deque -from io import StringIO, BytesIO +from io import StringIO __all__ = ["shlex", "split", "quote"] @@ -22,8 +22,8 @@ class shlex: "A lexical analyzer class for simple shell-like syntaxes." def __init__(self, instream=None, infile=None, posix=False, punctuation_chars=False): - if isinstance(instream, str): - instream = BytesIO(instream) + if isinstance(instream, basestring): + instream = StringIO(instream) if instream is not None: self.instream = instream self.infile = infile @@ -82,7 +82,7 @@ class shlex: def push_source(self, newstream, newfile=None): "Push an input source onto the lexer's input source stack." if isinstance(newstream, str): - newstream = BytesIO(newstream) + newstream = StringIO(newstream) self.filestack.appendleft((self.infile, self.instream, self.lineno)) self.infile = newfile self.instream = newstream