From b5e7d4cc14882e340f75b4c7ccdb077c45bbf58c Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Thu, 6 Oct 2016 14:25:52 -0700 Subject: [PATCH] fs: Return blank contents for zero-size files lacking a realfile. This allows reading from files newly created by touch without error. --- cowrie/core/fs.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cowrie/core/fs.py b/cowrie/core/fs.py index b063be9..462b9ee 100644 --- a/cowrie/core/fs.py +++ b/cowrie/core/fs.py @@ -235,6 +235,11 @@ class HoneyPotFilesystem(object): raise IsADirectoryError elif f[A_TYPE] == T_FILE and f[A_REALFILE]: return file(f[A_REALFILE], 'rb').read() + elif f[A_TYPE] == T_FILE and f[A_SIZE] == 0: + # Zero-byte file lacking A_REALFILE backing: probably empty. + # (The exceptions to this are some system files in /proc and /sys, + # but it's likely better to return nothing than suspiciously fail.) + return '' def mkfile(self, path, uid, gid, size, mode, ctime=None):