Skip to content

Commit

Permalink
Add exception handling for NetBIOSTimeout Exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
NeffIsBack committed Feb 18, 2025
1 parent 39f1309 commit 0cc9a45
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions nxc/modules/spider_plus.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,16 @@ 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}".')
elif "STATUS_OBJECT_PATH_NOT_FOUND" in str(e):
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):
Expand Down Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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 `..`)
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 0cc9a45

Please sign in to comment.