mirror of
https://github.com/aljazceru/cowrie.git
synced 2025-12-26 10:24:21 +01:00
fix strip executable bit
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user