mirror of
https://github.com/cowrie/cowrie.git
synced 2025-07-01 18:07:27 -04:00
Add wildcard support for file system creation
This commit is contained in:
@ -1,18 +1,42 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import os, pickle, sys, locale, getopt
|
###############################################################
|
||||||
|
# This program creates a cowrie file system pickle file.
|
||||||
|
#
|
||||||
|
# This is meant to build a brand new filesystem.
|
||||||
|
# To edit the file structure, please use './utils/fsctl.py'
|
||||||
|
#
|
||||||
|
##############################################################
|
||||||
|
|
||||||
|
import os, pickle, sys, locale, getopt, fnmatch
|
||||||
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 = 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 = range(0, 7)
|
||||||
PROC = False
|
PROC = False
|
||||||
VERBOSE = False
|
VERBOSE = False
|
||||||
|
|
||||||
|
blacklist_files = [
|
||||||
|
'/root/fs.pickle',
|
||||||
|
'/root/createfs.py',
|
||||||
|
'/root/.bash_history',
|
||||||
|
'*cowrie*',
|
||||||
|
'*kippo*',
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def logit(ftxt):
|
def logit(ftxt):
|
||||||
if VERBOSE:
|
if VERBOSE:
|
||||||
sys.stderr.write(ftxt)
|
sys.stderr.write(ftxt)
|
||||||
|
|
||||||
|
def checkblacklist(ftxt):
|
||||||
|
for value in blacklist_files:
|
||||||
|
if fnmatch.fnmatch(ftxt, value):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def recurse(localroot, root, tree, maxdepth = sys.maxint):
|
def recurse(localroot, root, tree, maxdepth = sys.maxint):
|
||||||
if maxdepth == 0: return
|
if maxdepth == 0: return
|
||||||
|
|
||||||
@ -26,13 +50,10 @@ def recurse(localroot, root, tree, maxdepth = sys.maxint):
|
|||||||
|
|
||||||
for name in os.listdir(localpath):
|
for name in os.listdir(localpath):
|
||||||
fspath = os.path.join(root, name)
|
fspath = os.path.join(root, name)
|
||||||
if fspath in (
|
if checkblacklist(fspath):
|
||||||
'/root/fs.pickle',
|
|
||||||
'/root/createfs.py',
|
|
||||||
'/root/.bash_history',
|
|
||||||
):
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
path = os.path.join(localpath, name)
|
path = os.path.join(localpath, name)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -124,4 +145,3 @@ if __name__ == '__main__':
|
|||||||
pickle.dump(tree, open(output, 'wb'))
|
pickle.dump(tree, open(output, 'wb'))
|
||||||
else:
|
else:
|
||||||
print pickle.dumps(tree)
|
print pickle.dumps(tree)
|
||||||
|
|
||||||
|
|||||||
@ -97,7 +97,7 @@ class fseditCmd(cmd.Cmd):
|
|||||||
|
|
||||||
self.update_pwd("/")
|
self.update_pwd("/")
|
||||||
|
|
||||||
self.intro = "\nKippo file system interactive editor\n" + \
|
self.intro = "\nKippo/Cowrie file system interactive editor\n" + \
|
||||||
"Donovan Hubbard, Douglas Hubbard, March 2013\n" + \
|
"Donovan Hubbard, Douglas Hubbard, March 2013\n" + \
|
||||||
"Type 'help' for help\n"
|
"Type 'help' for help\n"
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ class fseditCmd(cmd.Cmd):
|
|||||||
|
|
||||||
def do_EOF(self, args):
|
def do_EOF(self, args):
|
||||||
'''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 automaticaly
|
#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
|
||||||
@ -474,7 +474,7 @@ class fseditCmd(cmd.Cmd):
|
|||||||
#Get the object for source
|
#Get the object for source
|
||||||
srcl = getpath(self.fs, src)
|
srcl = getpath(self.fs, src)
|
||||||
|
|
||||||
#Get the ojbect for the source's parent
|
#Get the object for the source's parent
|
||||||
srcparentl = getpath(self.fs, srcparent)
|
srcparentl = getpath(self.fs, srcparent)
|
||||||
|
|
||||||
#if the specified filepath is a directory, maintain the current name
|
#if the specified filepath is a directory, maintain the current name
|
||||||
@ -553,7 +553,7 @@ class fseditCmd(cmd.Cmd):
|
|||||||
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 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 " + \
|
||||||
|
|||||||
Reference in New Issue
Block a user