⚝
One Hat Cyber Team
⚝
Your IP:
3.23.102.227
Server IP:
97.74.87.16
Server:
Linux 16.87.74.97.host.secureserver.net 5.14.0-503.38.1.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Apr 18 08:52:10 EDT 2025 x86_64
Server Software:
Apache
PHP Version:
8.2.28
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
lib
/
fm-agent
/
plugins
/
View File Name :
file_presence.py
import logging import agent_util import glob import os import datetime import re import time import sys from agent_util import float class FilePresencePlugin(agent_util.Plugin): textkey = "files" label = "Filesystem" # this is here because it's used in 2 different places newer_than_regex = re.compile(r"(?P<op>(a|c|m)time)<(?P<delta>\d+)(?P<metric>d|h|m|s)") @classmethod def get_metadata(self, config): data = { "file.exists": { "label": "File exists", "options": None, "status": agent_util.SUPPORTED, "error_message": None, "unit": "boolean", "option_string": True }, "file.count": { "label": "File count", "options": None, "status": agent_util.SUPPORTED, "error_message": None, "unit": "files", "option_string": True }, "file.created": { "label": "Creation age", "options": None, "status": agent_util.SUPPORTED, "error_message": None, "unit": "minutes", "option_string": True }, "file.modified": { "label": "Modification age", "options": None, "status": agent_util.SUPPORTED, "error_message": None, "unit": "minutes", "option_string": True }, "directory.size": { "label": "Directory size (KB)", "options": None, "status": agent_util.SUPPORTED, "error_message": None, "unit": "kilobytes", "option_string": True }, "file.size": { "label": "File size (KB)", "options": None, "status": agent_util.SUPPORTED, "error_message": None, "unit": "kilobytes", "option_string": True } } return data def check(self, textkey, path, config): path = path.strip() for date in re.findall(r"\$.[^$]+", path): date_format = date \ .replace("YYYY", "%Y") \ .replace("YY", "%y") \ .replace("MM", "%m") \ .replace("DD", "%d") \ .replace("D", "%w") \ .replace("ww", "%W") \ .replace("hh", "%H") \ .replace("mm", "%M") \ .replace("ss", "%S") \ .replace("Z", "%z") \ .replace("$", "") \ .strip() date_string = datetime.datetime.now().strftime(date_format) path = path.replace(date, date_string) self.log.debug("File path for file_presence plugin: %s" % path) if textkey == "file.exists": glob_results = glob.glob(path) has_results = len(glob_results) > 0 return_val = has_results self.log.debug("Return value for file.exists textkey: %s" % str(return_val)) return return_val elif textkey == "file.count": if os.path.isdir(path): glob_results = glob.glob(path+"/*") return_val = len(glob_results) self.log.debug("Return value for file.count textkey: %s" % str(return_val)) else: glob_results = glob.glob(path) return_val = len(glob_results) self.log.debug("Return value for file.count textkey: %s" % str(return_val)) return return_val elif textkey == "file.created": if not os.path.exists(path): return 0.0 age = time.time() - os.path.getctime(path) return_val = float(age) / 60.0 self.log.debug("Return value for file.created textkey: %s" % str(return_val)) return return_val elif textkey == "file.modified": if not os.path.exists(path): return 0.0 age = time.time() - os.path.getmtime(path) return_val = float(age) / 60.0 self.log.debug("Return value for file.modified textkey: %s" % str(return_val)) return return_val elif textkey == "file.size": if not os.path.exists(path): return 0.0 return_val = float(os.path.getsize(path)) / 1024.0 self.log.debug("Return value for file.size textkey: %s" % str(return_val)) return return_val elif textkey == "directory.size": if not os.path.exists(path): return 0.0 ret, output = agent_util.execute_command('du -sk ' + path) return_val =float(output.split()[0]) self.log.debug("Return value for file.size textkey: %s" % str(return_val)) return return_val