mirror of
https://github.com/aljazceru/cowrie.git
synced 2025-12-17 05:54:21 +01:00
python3 compat
This commit is contained in:
@@ -89,13 +89,13 @@ def playlog(fd, settings):
|
|||||||
|
|
||||||
def help(verbose=False):
|
def help(verbose=False):
|
||||||
|
|
||||||
print 'usage: %s [-c] [-o output] <tty-log-file> <tty-log-file>...' % \
|
print(( 'usage: %s [-c] [-o output] <tty-log-file> <tty-log-file>...' % \
|
||||||
os.path.basename(sys.argv[0])
|
os.path.basename(sys.argv[0])))
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
print ' -c colorify the output based on what streams are being received'
|
print(' -c colorify the output based on what streams are being received')
|
||||||
print ' -h display this help'
|
print(' -h display this help')
|
||||||
print ' -o write to the specified output file'
|
print(' -o write to the specified output file')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@@ -107,7 +107,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
optlist, args = getopt.getopt(sys.argv[1:], 'hco:' )
|
optlist, args = getopt.getopt(sys.argv[1:], 'hco:' )
|
||||||
except getopt.GetoptError, error:
|
except getopt.GetoptError as error:
|
||||||
sys.stderr.write( '{}: {}\n'.format(sys.argv[0], error))
|
sys.stderr.write( '{}: {}\n'.format(sys.argv[0], error))
|
||||||
help()
|
help()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|||||||
139
bin/fsctl
139
bin/fsctl
@@ -22,8 +22,8 @@ import os, pickle, sys, locale, time, cmd, copy
|
|||||||
from stat import *
|
from stat import *
|
||||||
|
|
||||||
A_NAME, A_TYPE, A_UID, A_GID, A_SIZE, A_MODE, \
|
A_NAME, A_TYPE, A_UID, A_GID, A_SIZE, A_MODE, \
|
||||||
A_CTIME, A_CONTENTS, A_TARGET, A_REALFILE = range(0, 10)
|
A_CTIME, A_CONTENTS, A_TARGET, A_REALFILE = list(range(0, 10))
|
||||||
T_LINK, T_DIR, T_FILE, T_BLK, T_CHR, T_SOCK, T_FIFO = range(0, 7)
|
T_LINK, T_DIR, T_FILE, T_BLK, T_CHR, T_SOCK, T_FIFO = list(range(0, 7))
|
||||||
|
|
||||||
def getpath(fs, path):
|
def getpath(fs, path):
|
||||||
cwd = fs
|
cwd = fs
|
||||||
@@ -44,7 +44,7 @@ def exists(fs, path):
|
|||||||
try:
|
try:
|
||||||
getpath(fs, path)
|
getpath(fs, path)
|
||||||
return True
|
return True
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
if str(e) == 'File not found':
|
if str(e) == 'File not found':
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
@@ -73,21 +73,21 @@ class fseditCmd(cmd.Cmd):
|
|||||||
cmd.Cmd.__init__(self)
|
cmd.Cmd.__init__(self)
|
||||||
|
|
||||||
if not os.path.isfile(pickle_file_path):
|
if not os.path.isfile(pickle_file_path):
|
||||||
print "File %s does not exist." % pickle_file_path
|
print(("File %s does not exist." % pickle_file_path))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pickle_file = open(pickle_file_path, 'rb')
|
pickle_file = open(pickle_file_path, 'rb')
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
print "Unable to open file %s" % pickle_file_path
|
print(("Unable to open file %s" % pickle_file_path))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.fs = pickle.load(pickle_file)
|
self.fs = pickle.load(pickle_file)
|
||||||
except:
|
except:
|
||||||
print ("Unable to load file '%s'. " + \
|
print((("Unable to load file '%s'. " + \
|
||||||
"Are you sure it is a valid pickle file?") % \
|
"Are you sure it is a valid pickle file?") % \
|
||||||
(pickle_file_path,)
|
(pickle_file_path,)))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
self.pickle_file_path=pickle_file_path
|
self.pickle_file_path=pickle_file_path
|
||||||
@@ -107,9 +107,9 @@ class fseditCmd(cmd.Cmd):
|
|||||||
try:
|
try:
|
||||||
pickle.dump(self.fs, file(self.pickle_file_path, 'wb'))
|
pickle.dump(self.fs, file(self.pickle_file_path, 'wb'))
|
||||||
except:
|
except:
|
||||||
print ("Unable to save pickle file '%s'. " + \
|
print((("Unable to save pickle file '%s'. " + \
|
||||||
"Are you sure you have write access?") % \
|
"Are you sure you have write access?") % \
|
||||||
(self.pickle_file_path,)
|
(self.pickle_file_path,)))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def do_exit(self, args):
|
def do_exit(self, args):
|
||||||
@@ -120,7 +120,7 @@ class fseditCmd(cmd.Cmd):
|
|||||||
'''The escape character ctrl+d exits the session'''
|
'''The escape character ctrl+d exits the session'''
|
||||||
#exiting from the do_EOF method does not create a newline automatically
|
#exiting from the do_EOF method does not create a newline automatically
|
||||||
#so we add it manually
|
#so we add it manually
|
||||||
print
|
print()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def do_ls(self, args):
|
def do_ls(self, args):
|
||||||
@@ -139,11 +139,11 @@ class fseditCmd(cmd.Cmd):
|
|||||||
path = resolve_reference(self.pwd, args)
|
path = resolve_reference(self.pwd, args)
|
||||||
|
|
||||||
if exists(self.fs, path) == False:
|
if exists(self.fs, path) == False:
|
||||||
print "ls: cannot access %s: No such file or directory" % (path,)
|
print(("ls: cannot access %s: No such file or directory" % (path,)))
|
||||||
return
|
return
|
||||||
|
|
||||||
if is_directory(self.fs, path) == False:
|
if is_directory(self.fs, path) == False:
|
||||||
print "ls: %s is not a directory" % (path,)
|
print(("ls: %s is not a directory" % (path,)))
|
||||||
return
|
return
|
||||||
|
|
||||||
cwd = getpath(self.fs, path)
|
cwd = getpath(self.fs, path)
|
||||||
@@ -155,12 +155,11 @@ class fseditCmd(cmd.Cmd):
|
|||||||
largest = max([x[A_SIZE] for x in files])
|
largest = max([x[A_SIZE] for x in files])
|
||||||
|
|
||||||
for file in files:
|
for file in files:
|
||||||
|
|
||||||
if not longls:
|
if not longls:
|
||||||
if file[A_TYPE] == T_DIR:
|
if file[A_TYPE] == T_DIR:
|
||||||
print file[A_NAME] + '/'
|
print((file[A_NAME] + '/'))
|
||||||
else:
|
else:
|
||||||
print file[A_NAME]
|
print((file[A_NAME]))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
perms = ['-'] * 10
|
perms = ['-'] * 10
|
||||||
@@ -200,14 +199,14 @@ class fseditCmd(cmd.Cmd):
|
|||||||
else:
|
else:
|
||||||
gid=str(gid).rjust(4)
|
gid=str(gid).rjust(4)
|
||||||
|
|
||||||
print '%s 1 %s %s %s %s %s%s' % \
|
print(('%s 1 %s %s %s %s %s%s' % \
|
||||||
(perms,
|
(perms,
|
||||||
uid,
|
uid,
|
||||||
gid,
|
gid,
|
||||||
str(file[A_SIZE]).rjust(len(str(largest))),
|
str(file[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[A_NAME],
|
||||||
linktarget)
|
linktarget)))
|
||||||
|
|
||||||
def update_pwd(self, directory):
|
def update_pwd(self, directory):
|
||||||
self.pwd = directory
|
self.pwd = directory
|
||||||
@@ -229,15 +228,15 @@ class fseditCmd(cmd.Cmd):
|
|||||||
target_dir = resolve_reference(self.pwd, relative_dir)
|
target_dir = resolve_reference(self.pwd, relative_dir)
|
||||||
|
|
||||||
if exists(self.fs, target_dir) == False:
|
if exists(self.fs, target_dir) == False:
|
||||||
print "cd: %s: No such file or directory" % target_dir
|
print(("cd: %s: No such file or directory" % target_dir))
|
||||||
elif is_directory(self.fs, target_dir):
|
elif is_directory(self.fs, target_dir):
|
||||||
self.update_pwd(target_dir)
|
self.update_pwd(target_dir)
|
||||||
else:
|
else:
|
||||||
print "cd: %s: Not a directory" % target_dir
|
print(("cd: %s: Not a directory" % target_dir))
|
||||||
|
|
||||||
def do_pwd(self, args):
|
def do_pwd(self, args):
|
||||||
'''Prints the current working directory'''
|
'''Prints the current working directory'''
|
||||||
print self.pwd
|
print((self.pwd))
|
||||||
|
|
||||||
def do_mkdir(self, args):
|
def do_mkdir(self, args):
|
||||||
"""Add a new directory in the target directory.
|
"""Add a new directory in the target directory.
|
||||||
@@ -246,7 +245,7 @@ class fseditCmd(cmd.Cmd):
|
|||||||
|
|
||||||
arg_list=args.split()
|
arg_list=args.split()
|
||||||
if len(arg_list) < 1:
|
if len(arg_list) < 1:
|
||||||
print "usage: mkdir <new directory> <new directory>..."
|
print("usage: mkdir <new directory> <new directory>...")
|
||||||
else:
|
else:
|
||||||
for arg in arg_list:
|
for arg in arg_list:
|
||||||
self.mkfile(arg.split(), T_DIR)
|
self.mkfile(arg.split(), T_DIR)
|
||||||
@@ -259,7 +258,7 @@ class fseditCmd(cmd.Cmd):
|
|||||||
arg_list=args.split()
|
arg_list=args.split()
|
||||||
|
|
||||||
if len(arg_list) < 1:
|
if len(arg_list) < 1:
|
||||||
print 'Usage: touch <destination> (<size in bytes>)'
|
print('Usage: touch <destination> (<size in bytes>)')
|
||||||
else:
|
else:
|
||||||
self.mkfile(arg_list, T_FILE)
|
self.mkfile(arg_list, T_FILE)
|
||||||
|
|
||||||
@@ -272,12 +271,12 @@ class fseditCmd(cmd.Cmd):
|
|||||||
fileName = pathList[len(pathList) - 1]
|
fileName = pathList[len(pathList) - 1]
|
||||||
|
|
||||||
if not exists(self.fs, parentdir):
|
if not exists(self.fs, parentdir):
|
||||||
print ('Parent directory %s doesn\'t exist!') % \
|
print((('Parent directory %s doesn\'t exist!') % \
|
||||||
(parentdir,)
|
(parentdir,)))
|
||||||
self.mkfile(parentdir.split(), T_DIR)
|
self.mkfile(parentdir.split(), T_DIR)
|
||||||
|
|
||||||
if exists(self.fs, path):
|
if exists(self.fs, path):
|
||||||
print 'Error: %s already exists!' % (path,)
|
print(('Error: %s already exists!' % (path,)))
|
||||||
return
|
return
|
||||||
|
|
||||||
cwd = getpath(self.fs, parentdir)
|
cwd = getpath(self.fs, parentdir)
|
||||||
@@ -301,7 +300,7 @@ class fseditCmd(cmd.Cmd):
|
|||||||
|
|
||||||
self.save_pickle()
|
self.save_pickle()
|
||||||
|
|
||||||
print "Added '%s'" % path
|
print(("Added '%s'" % path))
|
||||||
|
|
||||||
def do_rm(self, arguments):
|
def do_rm(self, arguments):
|
||||||
'''Remove an object from the file system.
|
'''Remove an object from the file system.
|
||||||
@@ -311,11 +310,11 @@ class fseditCmd(cmd.Cmd):
|
|||||||
args = arguments.split()
|
args = arguments.split()
|
||||||
|
|
||||||
if len(args) < 1 or len(args) > 2:
|
if len(args) < 1 or len(args) > 2:
|
||||||
print 'Usage: rm [-r] <target>'
|
print('Usage: rm [-r] <target>')
|
||||||
return
|
return
|
||||||
|
|
||||||
if len(args) == 2 and args[0] != "-r":
|
if len(args) == 2 and args[0] != "-r":
|
||||||
print 'Usage: rm [-r] <target>'
|
print('Usage: rm [-r] <target>')
|
||||||
return
|
return
|
||||||
|
|
||||||
if len(args) == 1:
|
if len(args) == 1:
|
||||||
@@ -324,17 +323,17 @@ class fseditCmd(cmd.Cmd):
|
|||||||
target_path = resolve_reference(self.pwd, args[1])
|
target_path = resolve_reference(self.pwd, args[1])
|
||||||
|
|
||||||
if exists(self.fs, target_path) == False:
|
if exists(self.fs, target_path) == False:
|
||||||
print "File \'%s\' doesn\'t exist" % (target_path,)
|
print(("File \'%s\' doesn\'t exist" % (target_path,)))
|
||||||
return
|
return
|
||||||
|
|
||||||
if target_path == "/":
|
if target_path == "/":
|
||||||
print "rm: cannot delete root directory '/'"
|
print("rm: cannot delete root directory '/'")
|
||||||
return
|
return
|
||||||
|
|
||||||
target_object = getpath(self.fs, target_path)
|
target_object = getpath(self.fs, target_path)
|
||||||
|
|
||||||
if target_object[A_TYPE]==T_DIR and args[0] != "-r":
|
if target_object[A_TYPE]==T_DIR and args[0] != "-r":
|
||||||
print "rm: cannot remove '%s': Is a directory" % (target_path,)
|
print(("rm: cannot remove '%s': Is a directory" % (target_path,)))
|
||||||
return
|
return
|
||||||
|
|
||||||
parent_path = '/'.join(target_path.split('/')[:-1])
|
parent_path = '/'.join(target_path.split('/')[:-1])
|
||||||
@@ -344,7 +343,7 @@ class fseditCmd(cmd.Cmd):
|
|||||||
|
|
||||||
self.save_pickle()
|
self.save_pickle()
|
||||||
|
|
||||||
print "Deleted %s" % target_path
|
print(("Deleted %s" % target_path))
|
||||||
|
|
||||||
def do_rmdir(self, arguments):
|
def do_rmdir(self, arguments):
|
||||||
'''Remove a file object. Like the unix command,
|
'''Remove a file object. Like the unix command,
|
||||||
@@ -354,27 +353,27 @@ class fseditCmd(cmd.Cmd):
|
|||||||
args = arguments.split()
|
args = arguments.split()
|
||||||
|
|
||||||
if len(args) != 1:
|
if len(args) != 1:
|
||||||
print 'Usage: rmdir <target>'
|
print('Usage: rmdir <target>')
|
||||||
return
|
return
|
||||||
|
|
||||||
target_path = resolve_reference(self.pwd, args[0])
|
target_path = resolve_reference(self.pwd, args[0])
|
||||||
|
|
||||||
if exists(self.fs, target_path) == False:
|
if exists(self.fs, target_path) == False:
|
||||||
print "File \'%s\' doesn\'t exist" % (target_path,)
|
print(("File \'%s\' doesn\'t exist" % (target_path,)))
|
||||||
return
|
return
|
||||||
|
|
||||||
target_object = getpath(self.fs, target_path)
|
target_object = getpath(self.fs, target_path)
|
||||||
|
|
||||||
if target_object[A_TYPE] != T_DIR:
|
if target_object[A_TYPE] != T_DIR:
|
||||||
print "rmdir: failed to remove '%s': Not a directory" % \
|
print(("rmdir: failed to remove '%s': Not a directory" % \
|
||||||
(target_path,)
|
(target_path,)))
|
||||||
return
|
return
|
||||||
|
|
||||||
#The unix rmdir command does not delete directories if they are not
|
#The unix rmdir command does not delete directories if they are not
|
||||||
#empty
|
#empty
|
||||||
if len(target_object[A_CONTENTS]) != 0:
|
if len(target_object[A_CONTENTS]) != 0:
|
||||||
print "rmdir: failed to remove '%s': Directory not empty" % \
|
print(("rmdir: failed to remove '%s': Directory not empty" % \
|
||||||
(target_path,)
|
(target_path,)))
|
||||||
return
|
return
|
||||||
|
|
||||||
parent_path = '/'.join(target_path.split('/')[:-1])
|
parent_path = '/'.join(target_path.split('/')[:-1])
|
||||||
@@ -387,27 +386,27 @@ class fseditCmd(cmd.Cmd):
|
|||||||
if self.pwd == target_path:
|
if self.pwd == target_path:
|
||||||
self.do_cd("..")
|
self.do_cd("..")
|
||||||
|
|
||||||
print "Deleted %s" % target_path
|
print(("Deleted %s" % target_path))
|
||||||
|
|
||||||
def do_mv(self, arguments):
|
def do_mv(self, arguments):
|
||||||
'''Moves a file/directory from one directory to another.\n
|
'''Moves a file/directory from one directory to another.\n
|
||||||
Usage: mv <source file> <destination file>'''
|
Usage: mv <source file> <destination file>'''
|
||||||
args = arguments.split()
|
args = arguments.split()
|
||||||
if len(args) != 2:
|
if len(args) != 2:
|
||||||
print 'Usage: mv <source> <destination>'
|
print('Usage: mv <source> <destination>')
|
||||||
return
|
return
|
||||||
src = resolve_reference(self.pwd, args[0])
|
src = resolve_reference(self.pwd, args[0])
|
||||||
dst = resolve_reference(self.pwd, args[1])
|
dst = resolve_reference(self.pwd, args[1])
|
||||||
|
|
||||||
if src == "/":
|
if src == "/":
|
||||||
print "mv: cannot move the root directory '/'"
|
print("mv: cannot move the root directory '/'")
|
||||||
return
|
return
|
||||||
|
|
||||||
src = src.strip('/')
|
src = src.strip('/')
|
||||||
dst = dst.strip('/')
|
dst = dst.strip('/')
|
||||||
|
|
||||||
if not exists(self.fs, src):
|
if not exists(self.fs, src):
|
||||||
print "Source file \'%s\' does not exist!" % src
|
print(("Source file \'%s\' does not exist!" % src))
|
||||||
return
|
return
|
||||||
|
|
||||||
#Get the parent directory of the source file
|
#Get the parent directory of the source file
|
||||||
@@ -429,11 +428,11 @@ class fseditCmd(cmd.Cmd):
|
|||||||
dstname = dst.split('/')[-1]
|
dstname = dst.split('/')[-1]
|
||||||
|
|
||||||
if exists(self.fs, dstparent + '/' + dstname):
|
if exists(self.fs, dstparent + '/' + dstname):
|
||||||
print "A file already exists at "+dst+"!"
|
print(("A file already exists at "+dst+"!"))
|
||||||
return
|
return
|
||||||
|
|
||||||
if not exists(self.fs, dstparent):
|
if not exists(self.fs, dstparent):
|
||||||
print 'Destination directory \'%s\' doesn\'t exist!' % dst
|
print(('Destination directory \'%s\' doesn\'t exist!' % dst))
|
||||||
return
|
return
|
||||||
|
|
||||||
if src == self.pwd:
|
if src == self.pwd:
|
||||||
@@ -447,14 +446,14 @@ class fseditCmd(cmd.Cmd):
|
|||||||
|
|
||||||
self.save_pickle()
|
self.save_pickle()
|
||||||
|
|
||||||
print 'File moved from /%s to /%s' % (src, dst)
|
print(('File moved from /%s to /%s' % (src, dst)))
|
||||||
|
|
||||||
def do_cp(self, arguments):
|
def do_cp(self, arguments):
|
||||||
'''Copies a file/directory from one directory to another.\n
|
'''Copies a file/directory from one directory to another.\n
|
||||||
Usage: cp <source file> <destination file>'''
|
Usage: cp <source file> <destination file>'''
|
||||||
args = arguments.split()
|
args = arguments.split()
|
||||||
if len(args) != 2:
|
if len(args) != 2:
|
||||||
print 'Usage: cp <source> <destination>'
|
print('Usage: cp <source> <destination>')
|
||||||
return
|
return
|
||||||
|
|
||||||
#src, dst = args[0], args[1]
|
#src, dst = args[0], args[1]
|
||||||
@@ -466,7 +465,7 @@ class fseditCmd(cmd.Cmd):
|
|||||||
dst = dst.strip('/')
|
dst = dst.strip('/')
|
||||||
|
|
||||||
if not exists(self.fs, src):
|
if not exists(self.fs, src):
|
||||||
print "Source file '%s' does not exist!" % (src,)
|
print(("Source file '%s' does not exist!" % (src,)))
|
||||||
return
|
return
|
||||||
|
|
||||||
#Get the parent directory of the source file
|
#Get the parent directory of the source file
|
||||||
@@ -487,11 +486,11 @@ class fseditCmd(cmd.Cmd):
|
|||||||
dstname = dst.split('/')[-1]
|
dstname = dst.split('/')[-1]
|
||||||
|
|
||||||
if exists(self.fs, dstparent + '/' + dstname):
|
if exists(self.fs, dstparent + '/' + dstname):
|
||||||
print 'A file already exists at %s/%s!' % (dstparent, dstname)
|
print(('A file already exists at %s/%s!' % (dstparent, dstname)))
|
||||||
return
|
return
|
||||||
|
|
||||||
if not exists(self.fs, dstparent):
|
if not exists(self.fs, dstparent):
|
||||||
print 'Destination directory %s doesn\'t exist!' % (dstparent,)
|
print(('Destination directory %s doesn\'t exist!' % (dstparent,)))
|
||||||
return
|
return
|
||||||
|
|
||||||
dstparentl = getpath(self.fs, dstparent)
|
dstparentl = getpath(self.fs, dstparent)
|
||||||
@@ -501,27 +500,27 @@ class fseditCmd(cmd.Cmd):
|
|||||||
|
|
||||||
self.save_pickle()
|
self.save_pickle()
|
||||||
|
|
||||||
print 'File copied from /%s to /%s/%s' % (src, dstparent, dstname)
|
print(('File copied from /%s to /%s/%s' % (src, dstparent, dstname)))
|
||||||
|
|
||||||
def do_chown(self, args):
|
def do_chown(self, args):
|
||||||
'''Change file ownership'''
|
'''Change file ownership'''
|
||||||
arg_list = args.split()
|
arg_list = args.split()
|
||||||
|
|
||||||
if len(arg_list) != 2:
|
if len(arg_list) != 2:
|
||||||
print "Incorrect number of arguments.\nUsage: chown <uid> <file>"
|
print("Incorrect number of arguments.\nUsage: chown <uid> <file>")
|
||||||
return
|
return
|
||||||
|
|
||||||
uid = arg_list[0]
|
uid = arg_list[0]
|
||||||
target_path = resolve_reference(self.pwd, arg_list[1])
|
target_path = resolve_reference(self.pwd, arg_list[1])
|
||||||
|
|
||||||
if not exists(self.fs, target_path):
|
if not exists(self.fs, target_path):
|
||||||
print "File '%s' doesn't exist." % target_path
|
print(("File '%s' doesn't exist." % target_path))
|
||||||
return
|
return
|
||||||
|
|
||||||
target_object = getpath(self.fs, target_path)
|
target_object = getpath(self.fs, target_path)
|
||||||
olduid = target_object[A_UID]
|
olduid = target_object[A_UID]
|
||||||
target_object[A_UID] = int(uid)
|
target_object[A_UID] = int(uid)
|
||||||
print "former UID: " + str(olduid) + ". New UID: " + str(uid)
|
print(("former UID: " + str(olduid) + ". New UID: " + str(uid)))
|
||||||
self.save_pickle()
|
self.save_pickle()
|
||||||
|
|
||||||
def do_chgrp(self, args):
|
def do_chgrp(self, args):
|
||||||
@@ -529,20 +528,20 @@ class fseditCmd(cmd.Cmd):
|
|||||||
arg_list = args.split()
|
arg_list = args.split()
|
||||||
|
|
||||||
if len(arg_list) != 2:
|
if len(arg_list) != 2:
|
||||||
print "Incorrect number of arguments.\nUsage: chgrp <gid> <file>"
|
print("Incorrect number of arguments.\nUsage: chgrp <gid> <file>")
|
||||||
return
|
return
|
||||||
|
|
||||||
gid = arg_list[0]
|
gid = arg_list[0]
|
||||||
target_path = resolve_reference(self.pwd, arg_list[1])
|
target_path = resolve_reference(self.pwd, arg_list[1])
|
||||||
|
|
||||||
if not exists(self.fs, target_path):
|
if not exists(self.fs, target_path):
|
||||||
print "File '%s' doesn't exist." % target_path
|
print(("File '%s' doesn't exist." % target_path))
|
||||||
return
|
return
|
||||||
|
|
||||||
target_object = getpath(self.fs, target_path)
|
target_object = getpath(self.fs, target_path)
|
||||||
oldgid = target_object[A_GID]
|
oldgid = target_object[A_GID]
|
||||||
target_object[A_GID] = int(gid)
|
target_object[A_GID] = int(gid)
|
||||||
print "former GID: " + str(oldgid) + ". New GID: " + str(gid)
|
print(("former GID: " + str(oldgid) + ". New GID: " + str(gid)))
|
||||||
self.save_pickle()
|
self.save_pickle()
|
||||||
|
|
||||||
def do_chmod(self, args):
|
def do_chmod(self, args):
|
||||||
@@ -552,34 +551,34 @@ class fseditCmd(cmd.Cmd):
|
|||||||
arg_list = args.split()
|
arg_list = args.split()
|
||||||
|
|
||||||
if len(arg_list) != 2:
|
if len(arg_list) != 2:
|
||||||
print "Incorrect number of arguments.\nUsage: chmod <mode> <file>"
|
print("Incorrect number of arguments.\nUsage: chmod <mode> <file>")
|
||||||
return
|
return
|
||||||
|
|
||||||
mode = arg_list[0]
|
mode = arg_list[0]
|
||||||
target_path = resolve_reference(self.pwd, arg_list[1])
|
target_path = resolve_reference(self.pwd, arg_list[1])
|
||||||
|
|
||||||
if not exists(self.fs, target_path):
|
if not exists(self.fs, target_path):
|
||||||
print "File '%s' doesn't exist." % target_path
|
print("File '%s' doesn't exist." % target_path)
|
||||||
return
|
return
|
||||||
|
|
||||||
target_object = getpath(self.fs, target_path)
|
target_object = getpath(self.fs, target_path)
|
||||||
oldmode = target_object[A_MODE]
|
oldmode = target_object[A_MODE]
|
||||||
|
|
||||||
if target_object [A_TYPE] == T_LINK:
|
if target_object [A_TYPE] == T_LINK:
|
||||||
print target_path + " is a link, nothing changed."
|
print(target_path + " is a link, nothing changed.")
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
num = int(mode, 8)
|
num = int(mode, 8)
|
||||||
except:
|
except:
|
||||||
print "Incorrect mode: " + mode
|
print("Incorrect mode: " + mode)
|
||||||
return
|
return
|
||||||
|
|
||||||
if num < 0 or num > 511:
|
if num < 0 or num > 511:
|
||||||
print "Incorrect mode: " + mode
|
print("Incorrect mode: " + mode)
|
||||||
return
|
return
|
||||||
|
|
||||||
target_object[A_MODE] = (oldmode & 07777000) | (num & 0777)
|
target_object[A_MODE] = (oldmode & 0o7777000) | (num & 0o777)
|
||||||
self.save_pickle()
|
self.save_pickle()
|
||||||
|
|
||||||
def do_file(self, args):
|
def do_file(self, args):
|
||||||
@@ -587,13 +586,13 @@ class fseditCmd(cmd.Cmd):
|
|||||||
arg_list = args.split()
|
arg_list = args.split()
|
||||||
|
|
||||||
if len(arg_list) != 1:
|
if len(arg_list) != 1:
|
||||||
print "Incorrect number of arguments.\nUsage: file <file>"
|
print("Incorrect number of arguments.\nUsage: file <file>")
|
||||||
return
|
return
|
||||||
|
|
||||||
target_path = resolve_reference(self.pwd, arg_list[0])
|
target_path = resolve_reference(self.pwd, arg_list[0])
|
||||||
|
|
||||||
if not exists(self.fs, target_path):
|
if not exists(self.fs, target_path):
|
||||||
print "File '%s' doesn't exist." % target_path
|
print("File '%s' doesn't exist." % target_path)
|
||||||
return
|
return
|
||||||
|
|
||||||
target_object = getpath(self.fs, target_path)
|
target_object = getpath(self.fs, target_path)
|
||||||
@@ -617,7 +616,7 @@ class fseditCmd(cmd.Cmd):
|
|||||||
else:
|
else:
|
||||||
msg = "unrecognized file"
|
msg = "unrecognized file"
|
||||||
|
|
||||||
print target_path+" is a "+msg
|
print(target_path+" is a "+msg)
|
||||||
|
|
||||||
def do_clear(self, args):
|
def do_clear(self, args):
|
||||||
'''Clears the screen'''
|
'''Clears the screen'''
|
||||||
@@ -630,10 +629,10 @@ class fseditCmd(cmd.Cmd):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def help_help(self):
|
def help_help(self):
|
||||||
print "Type help <topic> to get more information."
|
print("Type help <topic> to get more information.")
|
||||||
|
|
||||||
def help_about(self):
|
def help_about(self):
|
||||||
print "Kippo/Cowrie stores information about its file systems in a " + \
|
print("Kippo/Cowrie stores information about its file systems in a " + \
|
||||||
"series of nested lists. Once the lists are made, they are " + \
|
"series of nested lists. Once the lists are made, they are " + \
|
||||||
"stored in a pickle file on the hard drive. Every time cowrie " + \
|
"stored in a pickle file on the hard drive. Every time cowrie " + \
|
||||||
"gets a new client, it reads from the pickle file and loads " + \
|
"gets a new client, it reads from the pickle file and loads " + \
|
||||||
@@ -648,15 +647,15 @@ class fseditCmd(cmd.Cmd):
|
|||||||
"paths. Keep in mind that you need to restart the " + \
|
"paths. Keep in mind that you need to restart the " + \
|
||||||
"cowrie process in order for the new file system to be " + \
|
"cowrie process in order for the new file system to be " + \
|
||||||
"reloaded into memory.\n\nDonovan Hubbard, Douglas Hubbard, " + \
|
"reloaded into memory.\n\nDonovan Hubbard, Douglas Hubbard, " + \
|
||||||
"March 2013\nVersion 1.0"
|
"March 2013\nVersion 1.0")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if len(sys.argv) != 2:
|
if len(sys.argv) != 2:
|
||||||
print "Usage: %s <fs.pickle>" % os.path.basename(sys.argv[0],)
|
print("Usage: %s <fs.pickle>" % os.path.basename(sys.argv[0],))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
pickle_file_name = sys.argv[1].strip()
|
pickle_file_name = sys.argv[1].strip()
|
||||||
print pickle_file_name
|
print(pickle_file_name)
|
||||||
|
|
||||||
fseditCmd(pickle_file_name).cmdloop()
|
fseditCmd(pickle_file_name).cmdloop()
|
||||||
|
|
||||||
|
|||||||
24
bin/playlog
24
bin/playlog
@@ -63,18 +63,18 @@ def playlog(fd, settings):
|
|||||||
|
|
||||||
def help(brief = 0):
|
def help(brief = 0):
|
||||||
|
|
||||||
print 'Usage: %s [-bfhi] [-m secs] [-w file] <tty-log-file> <tty-log-file>...\n' % \
|
print('Usage: %s [-bfhi] [-m secs] [-w file] <tty-log-file> <tty-log-file>...\n' % \
|
||||||
os.path.basename(sys.argv[0])
|
os.path.basename(sys.argv[0]))
|
||||||
|
|
||||||
if not brief:
|
if not brief:
|
||||||
print ' -f keep trying to read the log until it\'s closed'
|
print(' -f keep trying to read the log until it\'s closed')
|
||||||
print ' -m <seconds> maximum delay in seconds, to avoid' + \
|
print(' -m <seconds> maximum delay in seconds, to avoid' + \
|
||||||
' boredom or fast-forward\n' + \
|
' boredom or fast-forward\n' + \
|
||||||
' to the end. (default is 3.0)'
|
' to the end. (default is 3.0)')
|
||||||
print ' -i show the input stream instead of output'
|
print(' -i show the input stream instead of output')
|
||||||
print ' -b show both input and output streams'
|
print(' -b show both input and output streams')
|
||||||
print ' -c colorify the output stream based on what streams are being received'
|
print(' -c colorify the output stream based on what streams are being received')
|
||||||
print ' -h display this help\n'
|
print(' -h display this help\n')
|
||||||
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
@@ -90,8 +90,8 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
optlist, args = getopt.getopt(sys.argv[1:], 'fhibcm:w:', ['help'])
|
optlist, args = getopt.getopt(sys.argv[1:], 'fhibcm:w:', ['help'])
|
||||||
except getopt.GetoptError, error:
|
except getopt.GetoptError as error:
|
||||||
print 'Error: %s\n' % error
|
print('Error: %s\n' % error)
|
||||||
help()
|
help()
|
||||||
|
|
||||||
for o, a in optlist:
|
for o, a in optlist:
|
||||||
@@ -110,7 +110,7 @@ if __name__ == '__main__':
|
|||||||
logfd = open(logfile, 'rb')
|
logfd = open(logfile, 'rb')
|
||||||
playlog(logfd, settings)
|
playlog(logfd, settings)
|
||||||
except IOError:
|
except IOError:
|
||||||
print "\n\n[!] Couldn't open log file (%s)!" % logfile
|
print("\n\n[!] Couldn't open log file (%s)!" % logfile)
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
# vim: set sw=4:
|
# vim: set sw=4:
|
||||||
|
|||||||
Reference in New Issue
Block a user