From 7fb70e0c7ceb26d218490fb712d7d580611071f6 Mon Sep 17 00:00:00 2001 From: "Remi GASCOU (Podalirius)" <79218792+p0dalirius@users.noreply.github.com> Date: Fri, 31 May 2024 14:06:08 +0200 Subject: [PATCH] Added config object to __init__ of modules and no_colors in ls function --- smbclientng/core/InteractiveShell.py | 2 +- smbclientng/core/Module.py | 4 ++-- smbclientng/core/utils.py | 12 +++++++++--- smbclientng/modules/Find.py | 4 ---- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/smbclientng/core/InteractiveShell.py b/smbclientng/core/InteractiveShell.py index 68eab34..7e03cd6 100644 --- a/smbclientng/core/InteractiveShell.py +++ b/smbclientng/core/InteractiveShell.py @@ -447,7 +447,7 @@ def command_module(self, arguments, command): module_name = arguments[0] if module_name in self.modules.keys(): - module = self.modules[module_name](self.smbSession) + module = self.modules[module_name](self.smbSession, self.config) module.run(' '.join(arguments[1:])) else: print("[!] Module '%s' does not exist." % module_name) diff --git a/smbclientng/core/Module.py b/smbclientng/core/Module.py index c669b52..70b0777 100644 --- a/smbclientng/core/Module.py +++ b/smbclientng/core/Module.py @@ -20,9 +20,9 @@ class Module(object): smbSession = None options = None - def __init__(self, smbSession): + def __init__(self, smbSession, config): self.smbSession = smbSession - self.options = None + self.config = config def parseArgs(self): raise NotImplementedError("Subclasses must implement this method") diff --git a/smbclientng/core/utils.py b/smbclientng/core/utils.py index 09cfee5..b85cf56 100644 --- a/smbclientng/core/utils.py +++ b/smbclientng/core/utils.py @@ -137,7 +137,7 @@ def STYPE_MASK(stype_value): return flags -def windows_ls_entry(entry, pathToPrint=None): +def windows_ls_entry(entry, config, pathToPrint=None): """ This function generates a metadata string based on the attributes of the provided entry object. @@ -166,6 +166,12 @@ def windows_ls_entry(entry, pathToPrint=None): date_str = datetime.datetime.fromtimestamp(entry.get_atime_epoch()).strftime("%Y-%m-%d %H:%M") if entry.is_directory(): - print("%s %10s %s \x1b[1;96m%s\x1b[0m\\" % (meta_string, size_str, date_str, pathToPrint)) + if config.no_colors: + print("%s %10s %s %s\\" % (meta_string, size_str, date_str, pathToPrint)) + else: + print("%s %10s %s \x1b[1;96m%s\x1b[0m\\" % (meta_string, size_str, date_str, pathToPrint)) else: - print("%s %10s %s \x1b[1m%s\x1b[0m" % (meta_string, size_str, date_str, pathToPrint)) \ No newline at end of file + if config.no_colors: + print("%s %10s %s %s" % (meta_string, size_str, date_str, pathToPrint)) + else: + print("%s %10s %s \x1b[1m%s\x1b[0m" % (meta_string, size_str, date_str, pathToPrint)) \ No newline at end of file diff --git a/smbclientng/modules/Find.py b/smbclientng/modules/Find.py index f84c813..7911231 100644 --- a/smbclientng/modules/Find.py +++ b/smbclientng/modules/Find.py @@ -23,10 +23,6 @@ class Find(Module): name = "find" description = "Search for files in a directory hierarchy" - def __init__(self, smbSession): - super(Find, self).__init__(smbSession) - self.smbSession = smbSession - def parseArgs(self, arguments): parser = ModuleArgumentParser(prog=self.name, description=self.description)