From ca564204b82dbf604b1a0ce48ce04bd124fc0744 Mon Sep 17 00:00:00 2001 From: Michel Oosterhof Date: Sun, 27 Sep 2015 18:16:05 +0000 Subject: [PATCH] fix strip executable bit --- cowrie/core/fs.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/cowrie/core/fs.py b/cowrie/core/fs.py index 29eb2ae..e6e22d0 100644 --- a/cowrie/core/fs.py +++ b/cowrie/core/fs.py @@ -199,6 +199,7 @@ class HoneyPotFilesystem(object): ctime = time.time() dir = self.get_path(os.path.dirname(path)) outfile = os.path.basename(path) + print "mkfile path=%s outfile=%s" % (path, outfile) if outfile in [x[A_NAME] for x in dir]: dir.remove([x for x in dir if x[A_NAME] == outfile][0]) dir.append([outfile, T_FILE, uid, gid, size, mode, ctime, [], @@ -282,25 +283,18 @@ class HoneyPotFilesystem(object): # treat O_RDWR same as O_WRONLY - print "mode = %s\n" % repr(mode) - if openFlags & os.O_WRONLY == os.O_WRONLY or openFlags & os.O_RDWR == os.O_RDWR: - # ensure we do not save with executable bit set - realmode = mode & ~(stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH) - realmode = realmode | stat.S_IRUSR - print "realmode = %s\n" % repr(mode) - - #log.msg("fs.open wronly") - tempfile = '%s/%s_%s' % \ + # strip executable bit + hostmode = mode & ~(111) + hostfile = '%s/%s_%s' % \ (self.cfg.get('honeypot', 'download_path'), time.strftime('%Y%m%d%H%M%S'), re.sub('[^A-Za-z0-9]', '_', filename)) #log.msg("fs.open file for writing, saving to %s" % safeoutfile) - self.mkfile(filename, 0, 0, 0, stat.S_IFREG | mode) - fd = os.open(tempfile, openFlags, realmode) - self.update_realfile(self.getfile(filename), tempfile) - self.tempfiles[fd] = tempfile + fd = os.open(hostfile, openFlags, hostmode) + self.update_realfile(self.getfile(filename), hostfile) + self.tempfiles[fd] = hostfile self.filenames[fd] = filename return fd @@ -347,8 +341,8 @@ class HoneyPotFilesystem(object): def rmdir(self, path): path = path.rstrip('/') - parent = '/'.join(path.split('/')[:-1]) - name = path.split('/')[-1] + name = os.path.basename(path) + parent = os.path.dirname(path) dir = self.getfile(path, follow_symlinks=False) if dir == False: raise OSError(errno.EEXIST, os.strerror(errno.EEXIST), path)