mirror of https://github.com/cowrie/cowrie.git
Add support for symbolic links in ls & cat
git-svn-id: https://kippo.googlecode.com/svn/trunk@191 951d7100-d841-11de-b865-b3884708a8e2
This commit is contained in:
parent
b607e8640c
commit
524982cdec
|
@ -12,18 +12,28 @@ commands = {}
|
|||
class command_cat(HoneyPotCommand):
|
||||
def call(self):
|
||||
for arg in self.args:
|
||||
path = self.fs.resolve_path(arg, self.honeypot.cwd)
|
||||
if not path or not self.fs.exists(path):
|
||||
self.writeln('bash: cat: %s: No such file or directory' % arg)
|
||||
return
|
||||
f = self.fs.getfile(path)
|
||||
self.cat(arg)
|
||||
|
||||
def cat(self, target, count = 0):
|
||||
if count > 10:
|
||||
self.writeln('cat: %s: Too many levels of symbolic links' % target)
|
||||
return
|
||||
path = self.fs.resolve_path(target, self.honeypot.cwd)
|
||||
if not path or not self.fs.exists(path):
|
||||
self.writeln('bash: cat: %s: No such file or directory' % target)
|
||||
return
|
||||
f = self.fs.getfile(path)
|
||||
if f[A_TYPE] == T_LINK:
|
||||
self.cat(f[A_TARGET], count + 1)
|
||||
return
|
||||
|
||||
realfile = self.fs.realfile(f, '%s/%s' % \
|
||||
(self.honeypot.env.cfg.get('honeypot', 'contents_path'), path))
|
||||
if realfile:
|
||||
f = file(realfile, 'rb')
|
||||
self.write(f.read())
|
||||
f.close()
|
||||
|
||||
realfile = self.fs.realfile(f, '%s/%s' % \
|
||||
(self.honeypot.env.cfg.get('honeypot', 'contents_path'), path))
|
||||
if realfile:
|
||||
f = file(realfile, 'rb')
|
||||
self.write(f.read())
|
||||
f.close()
|
||||
commands['/bin/cat'] = command_cat
|
||||
|
||||
class command_cd(HoneyPotCommand):
|
||||
|
|
|
@ -101,19 +101,25 @@ class command_ls(HoneyPotCommand):
|
|||
if file[A_MODE] & stat.S_IWOTH: perms[8] = 'w'
|
||||
if file[A_MODE] & stat.S_IXOTH: perms[9] = 'x'
|
||||
|
||||
linktarget = ''
|
||||
|
||||
if file[A_TYPE] == T_DIR:
|
||||
perms[0] = 'd'
|
||||
elif file[A_TYPE] == T_LINK:
|
||||
perms[0] = 'l'
|
||||
linktarget = ' -> %s' % (file[A_TARGET],)
|
||||
|
||||
perms = ''.join(perms)
|
||||
ctime = time.localtime(file[A_CTIME])
|
||||
|
||||
l = '%s 1 %s %s %s %s %s' % \
|
||||
l = '%s 1 %s %s %s %s %s%s' % \
|
||||
(perms,
|
||||
self.uid2name(file[A_UID]),
|
||||
self.gid2name(file[A_GID]),
|
||||
str(file[A_SIZE]).rjust(len(str(largest))),
|
||||
time.strftime('%Y-%m-%d %H:%M', ctime),
|
||||
file[A_NAME])
|
||||
file[A_NAME],
|
||||
linktarget)
|
||||
|
||||
self.honeypot.writeln(l)
|
||||
commands['/bin/ls'] = command_ls
|
||||
|
|
Loading…
Reference in New Issue