From 0cc9a452f21b29380835434e79e729fb6c7519a4 Mon Sep 17 00:00:00 2001 From: Alexander Neff Date: Tue, 18 Feb 2025 12:26:00 -0500 Subject: [PATCH] Add exception handling for NetBIOSTimeout Exceptions --- nxc/modules/spider_plus.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/nxc/modules/spider_plus.py b/nxc/modules/spider_plus.py index 4526aa512..9ccc148dd 100755 --- a/nxc/modules/spider_plus.py +++ b/nxc/modules/spider_plus.py @@ -117,8 +117,7 @@ def list_path(self, share, subfolder): filelist = self.smb.conn.listPath(share, subfolder + "*") except SessionError as e: - self.logger.debug(f'Failed listing files on share "{share}" in folder "{subfolder}".') - self.logger.debug(str(e)) + self.logger.debug(f'Failed listing files on share "{share}" in folder "{subfolder}": {e!s}') if "STATUS_ACCESS_DENIED" in str(e): self.logger.debug(f'Cannot list files in folder "{subfolder}".') @@ -126,6 +125,8 @@ def list_path(self, share, subfolder): self.logger.debug(f"The folder {subfolder} does not exist.") elif self.reconnect(): filelist = self.list_path(share, subfolder) + except NetBIOSTimeout as e: + self.logger.debug(f'Failed listing files on share "{share}" in folder "{subfolder}": {e!s}') return filelist def get_remote_file(self, share, path): @@ -164,7 +165,7 @@ def read_chunk(self, remote_file, chunk_size=CHUNK_SIZE): def get_file_save_path(self, remote_file): r"""Processes the remote file path to extract the filename and the folder path where the file should be saved locally. - + It converts forward slashes (/) and backslashes (\) in the remote file path to the appropriate path separator for the local file system. The folder path and filename are then obtained separately. """ @@ -236,11 +237,7 @@ def spider_folder(self, share_name, folder): """ self.logger.info(f'Spider share "{share_name}" in folder "{folder}".') - try: - filelist = self.list_path(share_name, folder + "*") - except Exception: - self.logger.fail(f"Error listing path: {share_name}:/{folder}. Skipping...") - return + filelist = self.list_path(share_name, folder + "*") # For each entry: # - It's a folder then we spider it (skipping `.` and `..`) @@ -376,7 +373,7 @@ def save_file(self, remote_file, share_name): def dump_folder_metadata(self, results): """Takes the metadata results as input and writes them to a JSON file in the `self.output_folder`. - + The results are formatted with indentation and sorted keys before being written to the file. """ metadata_path = join(self.output_folder, f"{self.host}.json")