diff --git a/cowrie/core/fs.py b/cowrie/core/fs.py index 1ed1392..b063be9 100644 --- a/cowrie/core/fs.py +++ b/cowrie/core/fs.py @@ -65,6 +65,25 @@ class HoneyPotFilesystem(object): # Keep count of new files, so we can have an artificial limit self.newcount = 0 + # Get the honeyfs path from the config file and explore it for file + # contents: + self.init_honeyfs(self.cfg.get('honeypot', 'contents_path')) + + + def init_honeyfs(self, honeyfs_path): + """ + Explore the honeyfs at 'honeyfs_path' and set all A_REALFILE attributes on + the virtual filesystem. + """ + + for path, directories, filenames in os.walk(honeyfs_path): + for filename in filenames: + realfile_path = os.path.join(path, filename) + virtual_path = '/' + os.path.relpath(realfile_path, honeyfs_path) + + f = self.getfile(virtual_path, follow_symlinks=False) + if f and f[A_TYPE] == T_FILE: + self.update_realfile(f, realfile_path) def resolve_path(self, path, cwd): """ @@ -214,11 +233,8 @@ class HoneyPotFilesystem(object): f = self.getfile(path) if f[A_TYPE] == T_DIR: raise IsADirectoryError - elif f[A_TYPE] == T_FILE: - self.update_realfile(f, '%s/%s' % \ - (self.cfg.get('honeypot', 'contents_path'), path)) - if f[A_REALFILE]: - return file(f[A_REALFILE], 'rb').read() + elif f[A_TYPE] == T_FILE and f[A_REALFILE]: + return file(f[A_REALFILE], 'rb').read() def mkfile(self, path, uid, gid, size, mode, ctime=None):