mirror of
https://github.com/aljazceru/cowrie.git
synced 2025-12-19 15:04:21 +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):
|
def do_ls_normal(self, path):
|
||||||
try:
|
try:
|
||||||
files = self.honeypot.fs.list_files(path)
|
files = self.honeypot.fs.get_path(path)
|
||||||
except:
|
except:
|
||||||
self.honeypot.writeln(
|
self.honeypot.writeln(
|
||||||
'ls: cannot access %s: No such file or directory' % path)
|
'ls: cannot access %s: No such file or directory' % path)
|
||||||
@@ -71,7 +71,7 @@ class command_ls(HoneyPotCommand):
|
|||||||
|
|
||||||
def do_ls_l(self, path):
|
def do_ls_l(self, path):
|
||||||
try:
|
try:
|
||||||
files = self.honeypot.fs.list_files(path)[:]
|
files = self.honeypot.fs.get_path(path)[:]
|
||||||
except:
|
except:
|
||||||
self.honeypot.writeln(
|
self.honeypot.writeln(
|
||||||
'ls: cannot access %s: No such file or directory' % path)
|
'ls: cannot access %s: No such file or directory' % path)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# Copyright (c) 2009 Upi Tamminen <desaster@gmail.com>
|
# Copyright (c) 2009 Upi Tamminen <desaster@gmail.com>
|
||||||
# See the COPYRIGHT file for more information
|
# See the COPYRIGHT file for more information
|
||||||
|
|
||||||
import os, time
|
import os, time, fnmatch
|
||||||
|
|
||||||
A_NAME, \
|
A_NAME, \
|
||||||
A_TYPE, \
|
A_TYPE, \
|
||||||
@@ -46,6 +46,29 @@ class HoneyPotFilesystem(object):
|
|||||||
|
|
||||||
return '/%s' % '/'.join(cwd)
|
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):
|
def get_path(self, path):
|
||||||
p = self.fs
|
p = self.fs
|
||||||
for i in path.split('/'):
|
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]
|
p = [x for x in p[A_CONTENTS] if x[A_NAME] == i][0]
|
||||||
return p[A_CONTENTS]
|
return p[A_CONTENTS]
|
||||||
|
|
||||||
def list_files(self, path):
|
|
||||||
return self.get_path(path)
|
|
||||||
|
|
||||||
def exists(self, path):
|
def exists(self, path):
|
||||||
f = self.getfile(path)
|
f = self.getfile(path)
|
||||||
if f is not False:
|
if f is not False:
|
||||||
|
|||||||
@@ -82,9 +82,16 @@ class HoneyPotShell(object):
|
|||||||
cmd, args = cmdAndArgs[0], []
|
cmd, args = cmdAndArgs[0], []
|
||||||
if len(cmdAndArgs) > 1:
|
if len(cmdAndArgs) > 1:
|
||||||
args = 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)
|
cmdclass = self.honeypot.getCommand(cmd)
|
||||||
if cmdclass:
|
if cmdclass:
|
||||||
obj = cmdclass(self.honeypot, *args)
|
obj = cmdclass(self.honeypot, *rargs)
|
||||||
self.honeypot.cmdstack.append(obj)
|
self.honeypot.cmdstack.append(obj)
|
||||||
self.honeypot.setTypeoverMode()
|
self.honeypot.setTypeoverMode()
|
||||||
obj.start()
|
obj.start()
|
||||||
|
|||||||
Reference in New Issue
Block a user