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

View File

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