From d1402b9298b60874d12ea7fd34c663e228bde163 Mon Sep 17 00:00:00 2001 From: Michel Oosterhof Date: Wed, 1 Jun 2016 20:09:51 +0400 Subject: [PATCH] give correct error when starting with && || or ; --- cowrie/core/honeypot.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/cowrie/core/honeypot.py b/cowrie/core/honeypot.py index e8394964..a40497dc 100644 --- a/cowrie/core/honeypot.py +++ b/cowrie/core/honeypot.py @@ -161,22 +161,22 @@ class HoneyPotShell(object): try: tok = self.lexer.get_token() #log.msg( "tok: %s" % (repr(tok)) ) - # for now, execute all after && if tok == self.lexer.eof: if len(tokens): self.cmdpending.append((tokens)) tokens = [] break - if tok == ';' or tok == '&&' or tok == '||': - self.cmdpending.append((tokens)) - tokens = [] - if tok == ';': - continue - if tok == '&&': - continue - if tok == '||': - continue - if tok == '$?': + # For now, execute all after && + elif tok == ';' or tok == '&&' or tok == '||': + if len(tokens): + self.cmdpending.append((tokens)) + tokens = [] + continue + else: + self.protocol.terminal.write( + '-bash: syntax error near unexpected token `{}\'\n'.format(tok)) + break + elif tok == '$?': tok = "0" elif tok[0] == '$': env_rex = re.compile('^\$([_a-zA-Z0-9]+)$')