diff --git a/kippo/commands/ls.py b/kippo/commands/ls.py index eb0fd24..de8ccba 100644 --- a/kippo/commands/ls.py +++ b/kippo/commands/ls.py @@ -44,7 +44,7 @@ class command_ls(HoneyPotCommand): def do_ls_normal(self, path): try: - files = self.honeypot.fs.list_files(path) + files = self.honeypot.fs.get_path(path) except: self.honeypot.writeln( 'ls: cannot access %s: No such file or directory' % path) @@ -71,7 +71,7 @@ class command_ls(HoneyPotCommand): def do_ls_l(self, path): try: - files = self.honeypot.fs.list_files(path)[:] + files = self.honeypot.fs.get_path(path)[:] except: self.honeypot.writeln( 'ls: cannot access %s: No such file or directory' % path) diff --git a/kippo/core/fs.py b/kippo/core/fs.py index f823499..166e589 100644 --- a/kippo/core/fs.py +++ b/kippo/core/fs.py @@ -1,7 +1,7 @@ # Copyright (c) 2009 Upi Tamminen # See the COPYRIGHT file for more information -import os, time +import os, time, fnmatch A_NAME, \ A_TYPE, \ @@ -46,6 +46,29 @@ class HoneyPotFilesystem(object): return '/%s' % '/'.join(cwd) + def resolve_path_wc(self, path, cwd): + pieces = path.rstrip('/').split('/') + if len(pieces[0]): + cwd = [x for x in cwd.split('/') if len(x) and x is not None] + path = path[1:] + else: + cwd, pieces = [], pieces[1:] + found = [] + def foo(p, cwd): + if not len(p): + found.append('/%s' % '/'.join(cwd)) + elif p[0] == '.': + foo(p[1:], cwd) + elif p[0] == '..': + foo(p[1:], cwd[1:]) + else: + names = [x[A_NAME] for x in self.get_path('/'.join(cwd))] + matches = [x for x in names if fnmatch.fnmatchcase(x, p[0])] + for match in matches: + foo(p[1:], cwd + [match]) + foo(pieces, cwd) + return found + def get_path(self, path): p = self.fs for i in path.split('/'): @@ -54,9 +77,6 @@ class HoneyPotFilesystem(object): p = [x for x in p[A_CONTENTS] if x[A_NAME] == i][0] return p[A_CONTENTS] - def list_files(self, path): - return self.get_path(path) - def exists(self, path): f = self.getfile(path) if f is not False: diff --git a/kippo/core/honeypot.py b/kippo/core/honeypot.py index e82194b..866dcab 100644 --- a/kippo/core/honeypot.py +++ b/kippo/core/honeypot.py @@ -82,9 +82,16 @@ class HoneyPotShell(object): cmd, args = cmdAndArgs[0], [] if len(cmdAndArgs) > 1: args = cmdAndArgs[1:] + rargs = [] + for arg in args: + matches = self.honeypot.fs.resolve_path_wc(arg, self.honeypot.cwd) + if matches: + rargs.extend(matches) + else: + rargs.append(arg) cmdclass = self.honeypot.getCommand(cmd) if cmdclass: - obj = cmdclass(self.honeypot, *args) + obj = cmdclass(self.honeypot, *rargs) self.honeypot.cmdstack.append(obj) self.honeypot.setTypeoverMode() obj.start()