From b7f2a69a7859c3dcfb8715a621f2dd817907dad3 Mon Sep 17 00:00:00 2001 From: "Remi GASCOU (Podalirius)" <79218792+p0dalirius@users.noreply.github.com> Date: Mon, 24 Jun 2024 19:10:24 +0200 Subject: [PATCH 1/2] Fixed sizeof command bug, introduced by logger --- smbclientng/core/InteractiveShell.py | 12 +++++++++--- smbclientng/core/Logger.py | 14 +++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/smbclientng/core/InteractiveShell.py b/smbclientng/core/InteractiveShell.py index c2012dc..6b71b8d 100644 --- a/smbclientng/core/InteractiveShell.py +++ b/smbclientng/core/InteractiveShell.py @@ -874,10 +874,11 @@ def command_sizeof(self, arguments, command): # SMB share needed : Yes class RecursiveSizeOfPrint(object): - def __init__(self, entry, smbSession, config): + def __init__(self, entry, sessionsManager, config, logger): self.entry = entry self.config = config - self.sessionsManager.current_session = smbSession + self.logger = logger + self.sessionsManager = sessionsManager self.size = 0 def update(self, entry, fullpath, depth): @@ -913,7 +914,12 @@ def print(self, end='\n'): total = 0 for entry in entries: - rsop = RecursiveSizeOfPrint(entry=entry, smbSession=self.sessionsManager.current_session, config=self.config) + rsop = RecursiveSizeOfPrint( + entry=entry, + sessionsManager=self.sessionsManager, + config=self.config, + logger=self.logger + ) # Directory if entry.is_directory(): self.sessionsManager.current_session.find( diff --git a/smbclientng/core/Logger.py b/smbclientng/core/Logger.py index 71e75c3..8787469 100644 --- a/smbclientng/core/Logger.py +++ b/smbclientng/core/Logger.py @@ -49,7 +49,7 @@ def __init__(self, config, logfile=None): self.logfile = self.logfile + (".%d" % k) open(self.logfile, "w").close() - def print(self, message=""): + def print(self, message="", end='\n'): """ Prints a message to stdout and logs it to a file if logging is enabled. @@ -61,10 +61,10 @@ def print(self, message=""): nocolor_message = re.sub(r"\x1b[\[]([0-9;]+)m", "", message) if self.config.no_colors: - print(nocolor_message) + print(nocolor_message, end=end) else: - print(message) - self.__write_to_logfile(nocolor_message) + print(message, end=end) + self.__write_to_logfile(nocolor_message, end=end) def info(self, message): """ @@ -118,7 +118,7 @@ def error(self, message): print("[\x1b[1;91merror\x1b[0m] %s" % message) self.__write_to_logfile("[error] %s" % nocolor_message) - def __write_to_logfile(self, message): + def __write_to_logfile(self, message, end='\n'): """ Writes the provided message to the log file specified during Logger instance initialization. @@ -127,8 +127,8 @@ def __write_to_logfile(self, message): Args: message (str): The message to be written to the log file. """ - + if self.logfile is not None: f = open(self.logfile, "a") - f.write(message + "\n") + f.write(message + end) f.close() \ No newline at end of file From 29ee8c890aef78f5ad030ac49c2dacfc20236405 Mon Sep 17 00:00:00 2001 From: "Remi GASCOU (Podalirius)" <79218792+p0dalirius@users.noreply.github.com> Date: Mon, 24 Jun 2024 21:09:31 +0200 Subject: [PATCH 2/2] Fixed 'tuple' object has no attribute 'no_colors' --- smbclientng/core/SessionsManager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smbclientng/core/SessionsManager.py b/smbclientng/core/SessionsManager.py index 1840262..cb79bb1 100644 --- a/smbclientng/core/SessionsManager.py +++ b/smbclientng/core/SessionsManager.py @@ -23,7 +23,7 @@ def __init__(self, config, logger): self.current_session = None self.current_session_id = None - self.config = config, + self.config = config self.logger = logger def create_new_session(self, credentials, host, port=445):