diff --git a/commands/base.py b/commands/base.py index d0c9197..0990bb4 100644 --- a/commands/base.py +++ b/commands/base.py @@ -140,13 +140,22 @@ class command_pwd(HoneyPotCommand): class command_passwd(HoneyPotCommand): def call(self, args): - # Until we learn how to be interactive - for i in [ - 'Changing password for root.', - 'passwd: Authentication information cannot be recovered', - 'passwd: password unchanged', - ]: - self.honeypot.writeln(i) + self.honeypot.terminal.write('Enter new UNIX password: ') + self.honeypot.next_callback = callback_passwd1 + self.honeypot.password_input = True + +class callback_passwd1(HoneyPotCommand): + def call(self, args): + self.honeypot.terminal.write('Retype new UNIX password: ') + self.honeypot.next_callback = callback_passwd2 + +class callback_passwd2(HoneyPotCommand): + def call(self, args): + self.honeypot.password_input = False + self.honeypot.writeln('Sorry, passwords do not match') + self.honeypot.writeln( + 'passwd: Authentication information cannot be recovered') + self.honeypot.writeln('passwd: password unchanged') class command_nop(HoneyPotCommand): def call(self, args): diff --git a/core/Kippo.py b/core/Kippo.py index 2de0c9a..9a0b14f 100644 --- a/core/Kippo.py +++ b/core/Kippo.py @@ -20,6 +20,8 @@ class HoneyPotProtocol(recvline.HistoricRecvLine): self.cwd = '/root' self.fs = HoneyPotFilesystem(deepcopy(self.env.fs)) self.prompt = 'sales:%(path)s# ' + self.next_callback = None + self.password_input = False def connectionMade(self): recvline.HistoricRecvLine.connectionMade(self) @@ -38,9 +40,6 @@ class HoneyPotProtocol(recvline.HistoricRecvLine): } self.terminal.write(self.prompt % attrs) - def getCommandFunc(self, cmd): - return getattr(self, 'do_' + cmd, None) - def getCommand(self, cmd, args): path = None @@ -64,29 +63,54 @@ class HoneyPotProtocol(recvline.HistoricRecvLine): def lineReceived(self, line): line = line.strip() if line: - print 'CMD: %s' % line - cmdAndArgs = line.split(' ', 1) - cmd = cmdAndArgs[0] - args = '' - if len(cmdAndArgs) > 1: - args = cmdAndArgs[1] - obj = self.getCommand(cmd, args) - if obj: + # Hack to allow password prompts, etc + if self.next_callback: + print 'INPUT: %s' % line + cmd = self.next_callback + self.next_callback = None + obj = cmd(self) try: - obj.call(args) + obj.call(line) del obj except Exception, e: print e self.writeln("Segmentation fault") else: - self.writeln('bash: %s: command not found' % cmd) - self.showPrompt() + print 'CMD: %s' % line + cmdAndArgs = line.split(' ', 1) + cmd = cmdAndArgs[0] + args = '' + if len(cmdAndArgs) > 1: + args = cmdAndArgs[1] + obj = self.getCommand(cmd, args) + if obj: + try: + obj.call(args) + del obj + except Exception, e: + print e + self.writeln("Segmentation fault") + else: + self.writeln('bash: %s: command not found' % cmd) + + if not self.next_callback: + self.showPrompt() def keystrokeReceived(self, keyID, modifier): ttylog.ttylog_write(self.terminal.ttylog_file, len(keyID), ttylog.DIR_READ, time.time(), keyID) recvline.HistoricRecvLine.keystrokeReceived(self, keyID, modifier) + # Easier way to implement password input? + def characterReceived(self, ch, moreCharactersComing): + if self.mode == 'insert': + self.lineBuffer.insert(self.lineBufferIndex, ch) + else: + self.lineBuffer[self.lineBufferIndex:self.lineBufferIndex+1] = [ch] + self.lineBufferIndex += 1 + if not self.password_input: + self.terminal.write(ch) + def writeln(self, data): self.terminal.write(data) self.terminal.nextLine() diff --git a/core/cmdl.py b/core/cmdl.py index 5755f87..5e8f85d 100644 --- a/core/cmdl.py +++ b/core/cmdl.py @@ -9,17 +9,18 @@ cmdl = { 'exit': base.command_quit, '/usr/bin/clear': base.command_clear, '/bin/rm': base.command_rm, + '/bin/chmod': base.command_nop, + '/bin/mount': base.command_mount, + '/bin/pwd': base.command_pwd, + '/bin/uname': base.command_uname, + '/bin/mkdir': base.command_mkdir, '/usr/bin/uptime': base.command_uptime, '/usr/bin/w': base.command_w, '/usr/bin/who': base.command_w, '/usr/bin/vi': base.command_vi, '/usr/bin/vim': base.command_vi, - '/bin/mount': base.command_mount, - '/bin/pwd': base.command_pwd, - '/bin/uname': base.command_uname, '/usr/bin/id': base.command_id, '/usr/bin/passwd': base.command_passwd, - '/bin/mkdir': base.command_mkdir, 'set': base.command_nop, 'unset': base.command_nop, 'history': base.command_nop,