This commit is contained in:
Michel Oosterhof
2018-07-13 13:44:32 +04:00
parent 0286511ef1
commit d737ca8c36
2 changed files with 46 additions and 46 deletions

View File

@ -16,7 +16,7 @@ import os.path
from twisted.python import log
from cowrie.shell.command import HoneyPotCommand
from cowrie.shell.fs import *
import cowrie.shell.fs as fs
commands = {}
@ -252,7 +252,7 @@ class command_cd(HoneyPotCommand):
if inode is None or inode is False:
self.errorWrite('bash: cd: {}: No such file or directory\n'.format(pname))
return
if inode[A_TYPE] != T_DIR:
if inode[fs.A_TYPE] != fs.T_DIR:
self.errorWrite('bash: cd: {}: Not a directory\n'.format(pname))
return
self.protocol.cwd = newpath
@ -282,10 +282,10 @@ class command_rm(HoneyPotCommand):
basename = pname.split('/')[-1]
contents = [x for x in dir]
for i in dir[:]:
if i[A_NAME] == basename:
if i[A_TYPE] == T_DIR and not recursive:
if i[fs.A_NAME] == basename:
if i[fs.A_TYPE] == fs.T_DIR and not recursive:
self.errorWrite(
'rm: cannot remove `{}\': Is a directory\n'.format(i[A_NAME]))
'rm: cannot remove `{}\': Is a directory\n'.format(i[fs.A_NAME]))
else:
dir.remove(i)
@ -356,9 +356,9 @@ class command_cp(HoneyPotCommand):
else:
dir = self.fs.get_path(os.path.dirname(resolv(dest)))
outfile = os.path.basename(dest.rstrip('/'))
if outfile in [x[A_NAME] for x in dir]:
dir.remove([x for x in dir if x[A_NAME] == outfile][0])
s[A_NAME] = outfile
if outfile in [x[fs.A_NAME] for x in dir]:
dir.remove([x for x in dir if x[fs.A_NAME] == outfile][0])
s[fs.A_NAME] = outfile
dir.append(s)
@ -420,12 +420,12 @@ class command_mv(HoneyPotCommand):
dir = self.fs.get_path(os.path.dirname(resolv(dest)))
outfile = os.path.basename(dest)
if dir != os.path.dirname(resolv(src)):
s[A_NAME] = outfile
s[fs.A_NAME] = outfile
dir.append(s)
sdir = self.fs.get_path(os.path.dirname(resolv(src)))
sdir.remove(s)
else:
s[A_NAME] = outfile
s[fs.A_NAME] = outfile
commands['/bin/mv'] = command_mv
@ -471,14 +471,14 @@ class command_rmdir(HoneyPotCommand):
except (IndexError, FileNotFound):
dir = None
fname = os.path.basename(f)
if not dir or fname not in [x[A_NAME] for x in dir]:
if not dir or fname not in [x[fs.A_NAME] for x in dir]:
self.errorWrite(
'rmdir: failed to remove `{}\': '.format(f) + \
'No such file or directory\n')
continue
for i in dir[:]:
if i[A_NAME] == fname:
if i[A_TYPE] != T_DIR:
if i[fs.A_NAME] == fname:
if i[fs.A_TYPE] != fs.T_DIR:
self.errorWrite("rmdir: failed to remove '{}': Not a directory\n".format(f))
return
dir.remove(i)

View File

@ -8,7 +8,7 @@ import getopt
import time
from cowrie.shell.command import HoneyPotCommand
from cowrie.shell.fs import *
import cowrie.shell.fs as fs
from cowrie.shell.pwd import Passwd, Group
commands = {}
@ -78,14 +78,14 @@ class command_ls(HoneyPotCommand):
files = self.protocol.fs.get_path(path)[:]
if self.showHidden:
dot = self.protocol.fs.getfile(path)[:]
dot[A_NAME] = '.'
dot[fs.A_NAME] = '.'
files.append(dot)
# FIXME: should grab dotdot off the parent instead
dotdot = self.protocol.fs.getfile(path)[:]
dotdot[A_NAME] = '..'
dotdot[fs.A_NAME] = '..'
files.append(dotdot)
else:
files = [x for x in files if not x[A_NAME].startswith('.')]
files = [x for x in files if not x[fs.A_NAME].startswith('.')]
files.sort()
else:
files = (self.protocol.fs.getfile(path)[:],)
@ -94,7 +94,7 @@ class command_ls(HoneyPotCommand):
'ls: cannot access %s: No such file or directory\n' % (path,))
return
l = [x[A_NAME] for x in files]
l = [x[fs.A_NAME] for x in files]
if not l:
return
count = 0
@ -123,14 +123,14 @@ class command_ls(HoneyPotCommand):
files = self.protocol.fs.get_path(path)[:]
if self.showHidden:
dot = self.protocol.fs.getfile(path)[:]
dot[A_NAME] = '.'
dot[fs.A_NAME] = '.'
files.append(dot)
# FIXME: should grab dotdot off the parent instead
dotdot = self.protocol.fs.getfile(path)[:]
dotdot[A_NAME] = '..'
dotdot[fs.A_NAME] = '..'
files.append(dotdot)
else:
files = [x for x in files if not x[A_NAME].startswith('.')]
files = [x for x in files if not x[fs.A_NAME].startswith('.')]
files.sort()
else:
files = (self.protocol.fs.getfile(path)[:],)
@ -141,64 +141,64 @@ class command_ls(HoneyPotCommand):
largest = 0
if len(files):
largest = max([x[A_SIZE] for x in files])
largest = max([x[fs.A_SIZE] for x in files])
for file in files:
if file[A_NAME].startswith('.') and not self.showHidden:
if file[fs.A_NAME].startswith('.') and not self.showHidden:
continue
perms = ['-'] * 10
if file[A_MODE] & stat.S_IRUSR:
if file[fs.A_MODE] & stat.S_IRUSR:
perms[1] = 'r'
if file[A_MODE] & stat.S_IWUSR:
if file[fs.A_MODE] & stat.S_IWUSR:
perms[2] = 'w'
if file[A_MODE] & stat.S_IXUSR:
if file[fs.A_MODE] & stat.S_IXUSR:
perms[3] = 'x'
if file[A_MODE] & stat.S_ISUID:
if file[fs.A_MODE] & stat.S_ISUID:
perms[3] = 'S'
if file[A_MODE] & stat.S_IXUSR and file[A_MODE] & stat.S_ISUID:
if file[fs.A_MODE] & stat.S_IXUSR and file[fs.A_MODE] & stat.S_ISUID:
perms[3] = 's'
if file[A_MODE] & stat.S_IRGRP:
if file[fs.A_MODE] & stat.S_IRGRP:
perms[4] = 'r'
if file[A_MODE] & stat.S_IWGRP:
if file[fs.A_MODE] & stat.S_IWGRP:
perms[5] = 'w'
if file[A_MODE] & stat.S_IXGRP:
if file[fs.A_MODE] & stat.S_IXGRP:
perms[6] = 'x'
if file[A_MODE] & stat.S_ISGID:
if file[fs.A_MODE] & stat.S_ISGID:
perms[6] = 'S'
if file[A_MODE] & stat.S_IXGRP and file[A_MODE] & stat.S_ISGID:
if file[fs.A_MODE] & stat.S_IXGRP and file[fs.A_MODE] & stat.S_ISGID:
perms[6] = 's'
if file[A_MODE] & stat.S_IROTH:
if file[fs.A_MODE] & stat.S_IROTH:
perms[7] = 'r'
if file[A_MODE] & stat.S_IWOTH:
if file[fs.A_MODE] & stat.S_IWOTH:
perms[8] = 'w'
if file[A_MODE] & stat.S_IXOTH:
if file[fs.A_MODE] & stat.S_IXOTH:
perms[9] = 'x'
if file[A_MODE] & stat.S_ISVTX:
if file[fs.A_MODE] & stat.S_ISVTX:
perms[9] = 'T'
if file[A_MODE] & stat.S_IXOTH and file[A_MODE] & stat.S_ISVTX:
if file[fs.A_MODE] & stat.S_IXOTH and file[fs.A_MODE] & stat.S_ISVTX:
perms[9] = 't'
linktarget = ''
if file[A_TYPE] == T_DIR:
if file[fs.fs.A_TYPE] == fs.T_DIR:
perms[0] = 'd'
elif file[A_TYPE] == T_LINK:
elif file[fs.A_TYPE] == fs.T_LINK:
perms[0] = 'l'
linktarget = ' -> %s' % (file[A_TARGET],)
linktarget = ' -> %s' % (file[fs.A_TARGET],)
perms = ''.join(perms)
ctime = time.localtime(file[A_CTIME])
ctime = time.localtime(file[fs.A_CTIME])
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))),
self.uid2name(file[fs.A_UID]),
self.gid2name(file[fs.A_GID]),
str(file[fs.A_SIZE]).rjust(len(str(largest))),
time.strftime('%Y-%m-%d %H:%M', ctime),
file[A_NAME],
file[fs.A_NAME],
linktarget)
self.write('{0}\n'.format(l))