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..')
self.write(b'^C\n')
self.write('^C\n')
self.exit()
@ -230,7 +230,7 @@ class HoneyPotShell(object):
continue
else:
self.protocol.terminal.write(
b'-bash: syntax error near unexpected token `{}\'\n'.format(tok))
'-bash: syntax error near unexpected token `{}\'\n'.format(tok))
break
elif tok == '$?':
tok = "0"
@ -254,7 +254,7 @@ class HoneyPotShell(object):
tokens.append(tok)
except Exception as e:
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
log.msg( "exception: {}".format(e) )
self.cmdpending = []
@ -365,7 +365,7 @@ class HoneyPotShell(object):
lastpp = pp
else:
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()
if pp:
self.protocol.call_command(pp, cmdclass, *cmd_array[0]['rargs'])
@ -406,7 +406,7 @@ class HoneyPotShell(object):
else:
prompt += '$ ' # "Non-Root" user
self.protocol.terminal.write(prompt)
self.protocol.ps = (prompt , b'> ')
self.protocol.ps = (prompt , '> ')
def eofReceived(self):
@ -423,7 +423,7 @@ class HoneyPotShell(object):
"""
self.protocol.lineBuffer = []
self.protocol.lineBufferIndex = 0
self.protocol.terminal.write(b'\n')
self.protocol.terminal.write('\n')
self.showPrompt()
@ -494,17 +494,17 @@ class HoneyPotShell(object):
first = l.split(' ')[:-1]
newbuf = ' '.join(first + ['%s%s' % (basedir, prefix)])
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
perline = int(self.protocol.user.windowSize[1] / (maxlen + 1))
count = 0
for file in files:
if count == perline:
count = 0
self.protocol.terminal.write(b'\n')
self.protocol.terminal.write('\n')
self.protocol.terminal.write(file[fs.A_NAME].ljust(maxlen))
count += 1
self.protocol.terminal.write(b'\n')
self.protocol.terminal.write('\n')
self.showPrompt()
self.protocol.lineBuffer = list(newbuf)