Py3 fix for command not found. send str not bytes to terminal

This commit is contained in:
Michel Oosterhof
2017-12-26 06:12:07 +04:00
parent e585229c4a
commit e696b9f47f

View File

@ -147,7 +147,7 @@ class HoneyPotCommand(object):
""" """
""" """
log.msg('Received CTRL-C, exiting..') log.msg('Received CTRL-C, exiting..')
self.write(b'^C\n') self.write('^C\n')
self.exit() self.exit()
@ -230,7 +230,7 @@ class HoneyPotShell(object):
continue continue
else: else:
self.protocol.terminal.write( self.protocol.terminal.write(
b'-bash: syntax error near unexpected token `{}\'\n'.format(tok)) '-bash: syntax error near unexpected token `{}\'\n'.format(tok))
break break
elif tok == '$?': elif tok == '$?':
tok = "0" tok = "0"
@ -254,7 +254,7 @@ class HoneyPotShell(object):
tokens.append(tok) tokens.append(tok)
except Exception as e: except Exception as e:
self.protocol.terminal.write( self.protocol.terminal.write(
b'bash: syntax error: unexpected end of file\n') 'bash: syntax error: unexpected end of file\n')
# Could run runCommand here, but i'll just clear the list instead # Could run runCommand here, but i'll just clear the list instead
log.msg( "exception: {}".format(e) ) log.msg( "exception: {}".format(e) )
self.cmdpending = [] self.cmdpending = []
@ -365,7 +365,7 @@ class HoneyPotShell(object):
lastpp = pp lastpp = pp
else: else:
log.msg(eventid='cowrie.command.failed', input=' '.join(cmd2), format='Command not found: %(input)s') log.msg(eventid='cowrie.command.failed', input=' '.join(cmd2), format='Command not found: %(input)s')
self.protocol.terminal.write(b'bash: %s: command not found\n' % (cmd['command'],)) self.protocol.terminal.write('bash: {}: command not found\n'.format(cmd['command']))
runOrPrompt() runOrPrompt()
if pp: if pp:
self.protocol.call_command(pp, cmdclass, *cmd_array[0]['rargs']) self.protocol.call_command(pp, cmdclass, *cmd_array[0]['rargs'])
@ -406,7 +406,7 @@ class HoneyPotShell(object):
else: else:
prompt += '$ ' # "Non-Root" user prompt += '$ ' # "Non-Root" user
self.protocol.terminal.write(prompt) self.protocol.terminal.write(prompt)
self.protocol.ps = (prompt , b'> ') self.protocol.ps = (prompt , '> ')
def eofReceived(self): def eofReceived(self):
@ -423,7 +423,7 @@ class HoneyPotShell(object):
""" """
self.protocol.lineBuffer = [] self.protocol.lineBuffer = []
self.protocol.lineBufferIndex = 0 self.protocol.lineBufferIndex = 0
self.protocol.terminal.write(b'\n') self.protocol.terminal.write('\n')
self.showPrompt() self.showPrompt()
@ -494,17 +494,17 @@ class HoneyPotShell(object):
first = l.split(' ')[:-1] first = l.split(' ')[:-1]
newbuf = ' '.join(first + ['%s%s' % (basedir, prefix)]) newbuf = ' '.join(first + ['%s%s' % (basedir, prefix)])
if newbuf == ''.join(self.protocol.lineBuffer): if newbuf == ''.join(self.protocol.lineBuffer):
self.protocol.terminal.write(b'\n') self.protocol.terminal.write('\n')
maxlen = max([len(x[fs.A_NAME]) for x in files]) + 1 maxlen = max([len(x[fs.A_NAME]) for x in files]) + 1
perline = int(self.protocol.user.windowSize[1] / (maxlen + 1)) perline = int(self.protocol.user.windowSize[1] / (maxlen + 1))
count = 0 count = 0
for file in files: for file in files:
if count == perline: if count == perline:
count = 0 count = 0
self.protocol.terminal.write(b'\n') self.protocol.terminal.write('\n')
self.protocol.terminal.write(file[fs.A_NAME].ljust(maxlen)) self.protocol.terminal.write(file[fs.A_NAME].ljust(maxlen))
count += 1 count += 1
self.protocol.terminal.write(b'\n') self.protocol.terminal.write('\n')
self.showPrompt() self.showPrompt()
self.protocol.lineBuffer = list(newbuf) self.protocol.lineBuffer = list(newbuf)