mirror of
https://github.com/cowrie/cowrie.git
synced 2025-07-01 18:07:27 -04:00
works again
This commit is contained in:
@ -136,19 +136,31 @@ class HoneyPotShell(object):
|
|||||||
self.lexer.push_source(line)
|
self.lexer.push_source(line)
|
||||||
tokens = []
|
tokens = []
|
||||||
while True:
|
while True:
|
||||||
tok = self.lexer.get_token()
|
try:
|
||||||
log.msg( "tok: %s" % (repr(tok)) )
|
tok = self.lexer.get_token()
|
||||||
# for now, execute all after &&
|
#log.msg( "tok: %s" % (repr(tok)) )
|
||||||
if tok == ';' or tok == self.lexer.eof or tok == '&&':
|
# for now, execute all after &&
|
||||||
self.cmdpending.append((tokens))
|
if tok == self.lexer.eof:
|
||||||
tokens = []
|
if len(tokens):
|
||||||
if tok == ';':
|
self.cmdpending.append((tokens))
|
||||||
continue
|
tokens = []
|
||||||
if tok == '&&':
|
break
|
||||||
continue
|
if tok == ';' or tok == '&&':
|
||||||
if tok == self.lexer.eof:
|
self.cmdpending.append((tokens))
|
||||||
break
|
tokens = []
|
||||||
tokens.append(tok)
|
if tok == ';':
|
||||||
|
continue
|
||||||
|
if tok == '&&':
|
||||||
|
continue
|
||||||
|
tokens.append(tok)
|
||||||
|
except Exception as e:
|
||||||
|
self.protocol.terminal.write(
|
||||||
|
'bash: syntax error: unexpected end of file\n')
|
||||||
|
# Could run runCommand here, but i'll just clear the list instead
|
||||||
|
self.cmdpending = []
|
||||||
|
self.showPrompt()
|
||||||
|
return
|
||||||
|
|
||||||
if len(self.cmdpending):
|
if len(self.cmdpending):
|
||||||
self.runCommand()
|
self.runCommand()
|
||||||
else:
|
else:
|
||||||
@ -175,18 +187,7 @@ class HoneyPotShell(object):
|
|||||||
self.protocol.terminal.transport.processEnded(ret)
|
self.protocol.terminal.transport.processEnded(ret)
|
||||||
return
|
return
|
||||||
|
|
||||||
line = self.cmdpending.pop(0)
|
cmdAndArgs = self.cmdpending.pop(0)
|
||||||
cmdAndArgs = shlex.split(unicode(line))
|
|
||||||
try:
|
|
||||||
line = line.replace('>', ' > ').replace('|', ' | ').replace('<',' < ')
|
|
||||||
cmdAndArgs = shlex.split(line)
|
|
||||||
except:
|
|
||||||
self.protocol.terminal.write(
|
|
||||||
'bash: syntax error: unexpected end of file\n')
|
|
||||||
# Could run runCommand here, but i'll just clear the list instead
|
|
||||||
self.cmdpending = []
|
|
||||||
self.showPrompt()
|
|
||||||
return
|
|
||||||
|
|
||||||
# Probably no reason to be this comprehensive for just PATH...
|
# Probably no reason to be this comprehensive for just PATH...
|
||||||
environ = copy.copy(self.environ)
|
environ = copy.copy(self.environ)
|
||||||
@ -214,14 +215,13 @@ class HoneyPotShell(object):
|
|||||||
rargs.append(arg)
|
rargs.append(arg)
|
||||||
cmdclass = self.protocol.getCommand(cmd, environ['PATH'].split(':'))
|
cmdclass = self.protocol.getCommand(cmd, environ['PATH'].split(':'))
|
||||||
if cmdclass:
|
if cmdclass:
|
||||||
log.msg(eventid='cowrie.command.success', input=line, format='Command found: %(input)s')
|
log.msg(eventid='cowrie.command.success', input=' '.join(cmdAndArgs), format='Command found: %(input)s')
|
||||||
self.protocol.call_command(cmdclass, *rargs)
|
self.protocol.call_command(cmdclass, *rargs)
|
||||||
else:
|
else:
|
||||||
log.msg(eventid='cowrie.command.failed',
|
log.msg(eventid='cowrie.command.failed',
|
||||||
input=line, format='Command not found: %(input)s')
|
input=' '.join(cmdAndArgs), format='Command not found: %(input)s')
|
||||||
if len(line):
|
self.protocol.terminal.write('bash: %s: command not found\n' % (cmd,))
|
||||||
self.protocol.terminal.write('bash: %s: command not found\n' % (cmd,))
|
runOrPrompt()
|
||||||
runOrPrompt()
|
|
||||||
|
|
||||||
|
|
||||||
def resume(self):
|
def resume(self):
|
||||||
|
@ -23,8 +23,8 @@ class shlex:
|
|||||||
def __init__(self, instream=None, infile=None, posix=False,
|
def __init__(self, instream=None, infile=None, posix=False,
|
||||||
punctuation_chars=False):
|
punctuation_chars=False):
|
||||||
if isinstance(instream, str):
|
if isinstance(instream, str):
|
||||||
#instream = StringIO(instream)
|
instream = StringIO(instream)
|
||||||
instream = BytesIO(instream)
|
#instream = BytesIO(instream)
|
||||||
if instream is not None:
|
if instream is not None:
|
||||||
self.instream = instream
|
self.instream = instream
|
||||||
self.infile = infile
|
self.infile = infile
|
||||||
|
Reference in New Issue
Block a user