mirror of
https://github.com/aljazceru/cowrie.git
synced 2025-12-17 22:14:19 +01:00
Implement command input
git-svn-id: https://kippo.googlecode.com/svn/trunk@15 951d7100-d841-11de-b865-b3884708a8e2
This commit is contained in:
@@ -140,13 +140,22 @@ class command_pwd(HoneyPotCommand):
|
|||||||
|
|
||||||
class command_passwd(HoneyPotCommand):
|
class command_passwd(HoneyPotCommand):
|
||||||
def call(self, args):
|
def call(self, args):
|
||||||
# Until we learn how to be interactive
|
self.honeypot.terminal.write('Enter new UNIX password: ')
|
||||||
for i in [
|
self.honeypot.next_callback = callback_passwd1
|
||||||
'Changing password for root.',
|
self.honeypot.password_input = True
|
||||||
'passwd: Authentication information cannot be recovered',
|
|
||||||
'passwd: password unchanged',
|
class callback_passwd1(HoneyPotCommand):
|
||||||
]:
|
def call(self, args):
|
||||||
self.honeypot.writeln(i)
|
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):
|
class command_nop(HoneyPotCommand):
|
||||||
def call(self, args):
|
def call(self, args):
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ class HoneyPotProtocol(recvline.HistoricRecvLine):
|
|||||||
self.cwd = '/root'
|
self.cwd = '/root'
|
||||||
self.fs = HoneyPotFilesystem(deepcopy(self.env.fs))
|
self.fs = HoneyPotFilesystem(deepcopy(self.env.fs))
|
||||||
self.prompt = 'sales:%(path)s# '
|
self.prompt = 'sales:%(path)s# '
|
||||||
|
self.next_callback = None
|
||||||
|
self.password_input = False
|
||||||
|
|
||||||
def connectionMade(self):
|
def connectionMade(self):
|
||||||
recvline.HistoricRecvLine.connectionMade(self)
|
recvline.HistoricRecvLine.connectionMade(self)
|
||||||
@@ -38,9 +40,6 @@ class HoneyPotProtocol(recvline.HistoricRecvLine):
|
|||||||
}
|
}
|
||||||
self.terminal.write(self.prompt % attrs)
|
self.terminal.write(self.prompt % attrs)
|
||||||
|
|
||||||
def getCommandFunc(self, cmd):
|
|
||||||
return getattr(self, 'do_' + cmd, None)
|
|
||||||
|
|
||||||
def getCommand(self, cmd, args):
|
def getCommand(self, cmd, args):
|
||||||
path = None
|
path = None
|
||||||
|
|
||||||
@@ -64,29 +63,54 @@ class HoneyPotProtocol(recvline.HistoricRecvLine):
|
|||||||
def lineReceived(self, line):
|
def lineReceived(self, line):
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if line:
|
if line:
|
||||||
print 'CMD: %s' % line
|
# Hack to allow password prompts, etc
|
||||||
cmdAndArgs = line.split(' ', 1)
|
if self.next_callback:
|
||||||
cmd = cmdAndArgs[0]
|
print 'INPUT: %s' % line
|
||||||
args = ''
|
cmd = self.next_callback
|
||||||
if len(cmdAndArgs) > 1:
|
self.next_callback = None
|
||||||
args = cmdAndArgs[1]
|
obj = cmd(self)
|
||||||
obj = self.getCommand(cmd, args)
|
|
||||||
if obj:
|
|
||||||
try:
|
try:
|
||||||
obj.call(args)
|
obj.call(line)
|
||||||
del obj
|
del obj
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print e
|
print e
|
||||||
self.writeln("Segmentation fault")
|
self.writeln("Segmentation fault")
|
||||||
else:
|
else:
|
||||||
self.writeln('bash: %s: command not found' % cmd)
|
print 'CMD: %s' % line
|
||||||
self.showPrompt()
|
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):
|
def keystrokeReceived(self, keyID, modifier):
|
||||||
ttylog.ttylog_write(self.terminal.ttylog_file, len(keyID),
|
ttylog.ttylog_write(self.terminal.ttylog_file, len(keyID),
|
||||||
ttylog.DIR_READ, time.time(), keyID)
|
ttylog.DIR_READ, time.time(), keyID)
|
||||||
recvline.HistoricRecvLine.keystrokeReceived(self, keyID, modifier)
|
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):
|
def writeln(self, data):
|
||||||
self.terminal.write(data)
|
self.terminal.write(data)
|
||||||
self.terminal.nextLine()
|
self.terminal.nextLine()
|
||||||
|
|||||||
@@ -9,17 +9,18 @@ cmdl = {
|
|||||||
'exit': base.command_quit,
|
'exit': base.command_quit,
|
||||||
'/usr/bin/clear': base.command_clear,
|
'/usr/bin/clear': base.command_clear,
|
||||||
'/bin/rm': base.command_rm,
|
'/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/uptime': base.command_uptime,
|
||||||
'/usr/bin/w': base.command_w,
|
'/usr/bin/w': base.command_w,
|
||||||
'/usr/bin/who': base.command_w,
|
'/usr/bin/who': base.command_w,
|
||||||
'/usr/bin/vi': base.command_vi,
|
'/usr/bin/vi': base.command_vi,
|
||||||
'/usr/bin/vim': 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/id': base.command_id,
|
||||||
'/usr/bin/passwd': base.command_passwd,
|
'/usr/bin/passwd': base.command_passwd,
|
||||||
'/bin/mkdir': base.command_mkdir,
|
|
||||||
'set': base.command_nop,
|
'set': base.command_nop,
|
||||||
'unset': base.command_nop,
|
'unset': base.command_nop,
|
||||||
'history': base.command_nop,
|
'history': base.command_nop,
|
||||||
|
|||||||
Reference in New Issue
Block a user