Implement command input

git-svn-id: https://kippo.googlecode.com/svn/trunk@15 951d7100-d841-11de-b865-b3884708a8e2
This commit is contained in:
desaster 2009-11-17 07:08:16 +00:00
parent 342c95941e
commit e00b0c3c59
3 changed files with 59 additions and 25 deletions

View File

@ -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):

View File

@ -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()

View File

@ -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,