Fix #883, add ',' to wordchars (#884)

* Fix #883, add ',' to wordchars
This commit is contained in:
Michel Oosterhof 2018-09-16 16:46:49 +04:00 committed by GitHub
parent cd480394da
commit f5633927ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 11 deletions

View File

@ -32,15 +32,21 @@ class HoneyPotShell(object):
def lineReceived(self, line):
log.msg(eventid='cowrie.command.input', input=line, format='CMD: %(input)s')
self.lexer = shlex.shlex(instream=line, punctuation_chars=True)
self.lexer = shlex.shlex(instream=line, punctuation_chars=True, posix=True)
# Add these special characters that are not in the default lexer
self.lexer.wordchars += '@%{}=$:+^'
self.lexer.wordchars += '@%{}=$:+^,'
tokens = []
while True:
try:
tok = self.lexer.get_token()
# log.msg("tok: %s" % (repr(tok)))
if tok == self.lexer.eof:
if tokens:
self.cmdpending.append((tokens))
tokens = []
break
# Ignore parentheses
tok_len = len(tok)
tok = tok.strip('(')
@ -48,13 +54,8 @@ class HoneyPotShell(object):
if len(tok) != tok_len and tok == '':
continue
if tok == self.lexer.eof:
if tokens:
self.cmdpending.append((tokens))
tokens = []
break
# For now, treat && and || same as ;, just execute without checking return code
elif tok == '&&' or tok == '||':
if tok == '&&' or tok == '||':
if tokens:
self.cmdpending.append((tokens))
tokens = []

View File

@ -43,9 +43,6 @@ class shlex:
self.commenters = '#'
self.wordchars = ('abcdfeghijklmnopqrstuvwxyz'
'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_')
if self.posix:
self.wordchars += ('ßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ'
'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ')
self.whitespace = ' \t\r\n'
self.whitespace_split = False
self.quotes = '\'"'

View File

@ -115,5 +115,12 @@ class ShellEchoCommandTests(unittest.TestCase):
self.proto.lineReceived(b'echo test > test012; grep test test012')
self.assertEquals(self.tr.value(), b'test\n' + PROMPT)
def test_echo_command_013(self):
"""
echo "ls""ls"
"""
self.proto.lineReceived(b'echo "ls""ls"')
self.assertEquals(self.tr.value(), b'lsls\n' + PROMPT)
def tearDown(self):
self.proto.connectionLost("tearDown From Unit Test")