Reimplement running commands in a bit more sane way - should allow for easier

interactive commands (eg. passwd).

Fix history (uparrow)



git-svn-id: https://kippo.googlecode.com/svn/trunk@20 951d7100-d841-11de-b865-b3884708a8e2
This commit is contained in:
desaster
2009-11-17 21:49:37 +00:00
parent 29569cb639
commit 12f83ccb6f
3 changed files with 99 additions and 98 deletions

View File

@@ -1,8 +1,8 @@
from core.Kippo import HoneyPotCommand
class command_ssh(HoneyPotCommand):
def call(self, args):
if not len(args.strip()):
def start(self):
if not len(self.args.strip()):
for l in (
'usage: ssh [-1246AaCfgKkMNnqsTtVvXxY] [-b bind_address] [-c cipher_spec]',
' [-D [bind_address:]port] [-e escape_char] [-F configfile]',
@@ -12,33 +12,34 @@ class command_ssh(HoneyPotCommand):
' [-w local_tun[:remote_tun]] [user@]hostname [command]',
):
self.honeypot.writeln(l)
self.exit()
return
self.honeypot.writeln('The authenticity of host \'127.0.0.4 (127.0.0.4)\' can\'t be established.')
self.honeypot.writeln('RSA key fingerprint is 9c:30:97:8e:9e:f8:0d:de:04:8d:76:3a:7b:4b:30:f8.')
self.host = self.args.strip()
self.honeypot.writeln('The authenticity of host \'187.42.2.9 (187.42.2.9)\' can\'t be established.')
self.honeypot.writeln('RSA key fingerprint is 9d:30:97:8a:9e:48:0d:de:04:8d:76:3a:7b:4b:30:f8.')
self.honeypot.terminal.write('Are you sure you want to continue connecting (yes/no)? ')
self.callback = (callback_connect, args)
self.callbacks = [self.yesno, self.finish]
class callback_connect(HoneyPotCommand):
def call(self, line, args):
def yesno(self, args):
host = args.strip()
self.honeypot.writeln(
'Warning: Permanently added \'%s\' (RSA) to the list of known hosts.' % \
host)
self.honeypot.terminal.write('%s\'s password: ' % args)
self.honeypot.terminal.write('%s\'s password: ' % self.host)
self.honeypot.password_input = True
self.callback = (callback_done, args)
class callback_done(HoneyPotCommand):
def call(self, line, args):
user = 'root'
if args.count('@'):
user, rest = args.split('@', 1)
else:
rest = args
host = rest.strip().split('.')
if len(host) and host[0].isalpha():
host = host[0]
else:
host = 'localhost'
def finish(self, args):
user, rest, host = 'root', self.host, 'localhost'
if self.host.count('@'):
user, rest = self.host.split('@', 1)
rest = rest.strip().split('.')
if len(rest) and rest[0].isalpha():
host = rest[0]
self.honeypot.hostname = host
self.honeypot.password_input = False
self.honeypot.prompt = '%s:%%(path)s# ' % host
self.exit()
def lineReceived(self, line):
print 'ssh input:', line
self.callbacks.pop(0)(line)