mirror of
https://github.com/aljazceru/cowrie.git
synced 2025-12-19 06:54:19 +01:00
removed list_files, which was just calling get_path
implemented wildcard aware path resolving git-svn-id: https://kippo.googlecode.com/svn/trunk@74 951d7100-d841-11de-b865-b3884708a8e2
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Copyright (c) 2009 Upi Tamminen <desaster@gmail.com>
|
||||
# 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:
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user