From 4acedc357ac1f46d7449aa87767b9dab88f1735d Mon Sep 17 00:00:00 2001 From: "Remi GASCOU (Podalirius)" <79218792+p0dalirius@users.noreply.github.com> Date: Thu, 4 Jul 2024 10:18:18 +0200 Subject: [PATCH] Implemented an alias 'find' to 'module find', Fixes #77 --- smbclientng/core/CommandCompleter.py | 10 +++++++++ smbclientng/core/InteractiveShell.py | 32 +++++++++++++++++++--------- smbclientng/modules/Find.py | 4 ++-- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/smbclientng/core/CommandCompleter.py b/smbclientng/core/CommandCompleter.py index 8aea77f..f068c90 100644 --- a/smbclientng/core/CommandCompleter.py +++ b/smbclientng/core/CommandCompleter.py @@ -91,6 +91,16 @@ class CommandCompleter(object): "subcommands": [], "autocomplete": [] }, + "find": { + "description": [ + "Search for files in a directory hierarchy", + "Syntax: find [-h] [-name NAME] [-iname INAME] [-type TYPE] [-size SIZE] [-ls]", + " [-download] [-maxdepth MAXDEPTH] [-mindepth MINDEPTH]", + " [PATH ...]" + ], + "subcommands": [], + "autocomplete": [] + }, "get": { "description": [ "Get a remote file.", diff --git a/smbclientng/core/InteractiveShell.py b/smbclientng/core/InteractiveShell.py index 01f791d..dcb2baa 100644 --- a/smbclientng/core/InteractiveShell.py +++ b/smbclientng/core/InteractiveShell.py @@ -183,6 +183,10 @@ def process_line(self, commandLine): # debug elif command == "debug": self.command_debug(arguments, command) + + # Find + elif command == "find": + self.command_find(arguments, command) # Get a file elif command == "get": @@ -196,14 +200,6 @@ def process_line(self, commandLine): elif command in ["ls", "dir"]: self.command_ls(arguments, command) - # Creates a new remote directory - elif command == "mkdir": - self.command_mkdir(arguments, command) - - # Put a file - elif command == "put": - self.command_put(arguments, command) - # Shows the content of a local file elif command == "lcat": self.command_lcat(arguments, command) @@ -248,6 +244,10 @@ def process_line(self, commandLine): elif command == "ltree": self.command_ltree(arguments, command) + # Creates a new remote directory + elif command == "mkdir": + self.command_mkdir(arguments, command) + # Modules elif command == "module": self.command_module(arguments, command) @@ -256,6 +256,10 @@ def process_line(self, commandLine): elif command == "mount": self.command_mount(arguments, command) + # Put a file + elif command == "put": + self.command_put(arguments, command) + # Reconnects the current SMB session elif command in ["connect", "reconnect"]: self.command_reconnect(arguments, command) @@ -391,6 +395,16 @@ def command_close(self, arguments, command): if self.sessionsManager.current_session.connected: self.sessionsManager.current_session.close_smb_session() + def command_find(self, arguments, command): + module_name = "find" + + if module_name in self.modules.keys(): + module = self.modules[module_name](self.sessionsManager.current_session, self.config, self.logger) + arguments_string = ' '.join(arguments) + module.run(arguments_string) + else: + self.logger.error("Module '%s' does not exist." % module_name) + @command_arguments_required @active_smb_connection_needed @smb_share_is_set @@ -741,8 +755,6 @@ def command_mkdir(self, arguments, command): self.sessionsManager.current_session.mkdir(path=arguments[0]) @command_arguments_required - @active_smb_connection_needed - @smb_share_is_set def command_module(self, arguments, command): module_name = arguments[0] diff --git a/smbclientng/modules/Find.py b/smbclientng/modules/Find.py index 648261f..bc885bb 100644 --- a/smbclientng/modules/Find.py +++ b/smbclientng/modules/Find.py @@ -181,9 +181,9 @@ def __find_callback(self, entry, fullpath, depth): windows_ls_entry(entry, fullpath) else: if entry.is_directory(): - print("%s" % fullpath) + print("%s" % fullpath.replace(ntpath.sep, '/')) else: - print("%s" % fullpath) + print("%s" % fullpath.replace(ntpath.sep, '/')) return None