Repository: cowrie/cowrie

Issue:
Quote parsing bug
Output from command:
```
echo "Z""IGAZAGA148""8"
```

Is on Cowrie:

``` 
Z" "IGAZAGA148" "8
``` 

On normal system:
```
ZIGAZAGA1488
```



Discussion:

Resolving patch:
diff --git a/src/cowrie/shell/honeypot.py b/src/cowrie/shell/honeypot.py
--- a/src/cowrie/shell/honeypot.py
+++ b/src/cowrie/shell/honeypot.py
@@ -32,15 +32,21 @@ def __init__(self, protocol, interactive=True):
 
     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 @@ def lineReceived(self, line):
                 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 = []
diff --git a/src/cowrie/shell/shlex.py b/src/cowrie/shell/shlex.py
--- a/src/cowrie/shell/shlex.py
+++ b/src/cowrie/shell/shlex.py
@@ -43,9 +43,6 @@ def __init__(self, instream=None, infile=None, posix=False,
         self.commenters = '#'
         self.wordchars = ('abcdfeghijklmnopqrstuvwxyz'
                           'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_')
-        if self.posix:
-            self.wordchars += ('ßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ'
-                               'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ')
         self.whitespace = ' \t\r\n'
         self.whitespace_split = False
         self.quotes = '\'"'


Test patch:
diff --git a/src/cowrie/test/test_echo.py b/src/cowrie/test/test_echo.py
--- a/src/cowrie/test/test_echo.py
+++ b/src/cowrie/test/test_echo.py
@@ -115,5 +115,12 @@ def test_echo_command_012(self):
         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")