send unicode to shlex

This commit is contained in:
Michel Oosterhof 2017-07-16 12:21:56 +04:00
parent c15449d029
commit 83e7995178
2 changed files with 6 additions and 4 deletions

View File

@ -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:

View File

@ -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