mirror of https://github.com/cowrie/cowrie.git
parent
cd480394da
commit
f5633927ff
|
@ -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 = []
|
||||
|
|
|
@ -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 = '\'"'
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue