spider_plus: attempt to fix reconnection infinite recursion

This commit is contained in:
Marshall Hallenbeck
2024-04-20 12:53:49 -04:00
parent 763f2f9384
commit e8ecb716ee
+10 -8
View File
@@ -73,6 +73,7 @@ class SMBSpiderPlus:
"num_files_unmodified": 0,
"num_files_updated": 0,
}
self.connection_attempts = 1 # we connect once initially
self.download_flag = download_flag
self.stats_flag = stats_flag
self.exclude_filter = exclude_filter
@@ -87,15 +88,14 @@ class SMBSpiderPlus:
"""Performs a series of reconnection attempts, up to `self.max_connection_attempts`, with a 3-second delay between each attempt.
It renegotiates the session by creating a new connection object and logging in again.
"""
for i in range(1, self.max_connection_attempts + 1):
for i in range(self.connection_attempts, self.max_connection_attempts + 1):
self.logger.display(f"Reconnection attempt #{i}/{self.max_connection_attempts} to server.")
# Renegotiate the session
time.sleep(3)
self.logger.display(f"Creating new connection object and trying to login...")
self.smb.create_conn_obj()
self.smb.login()
self.connection_attempts += 1
return True
return False
def list_path(self, share, subfolder):
@@ -104,16 +104,17 @@ class SMBSpiderPlus:
try:
# Get file list for the current folder
filelist = self.smb.conn.listPath(share, f"{subfolder}*")
except (SessionError, NetBIOSTimeout) as e:
self.logger.debug(f'Failed listing files on share "{share}" in folder "{subfolder}"')
self.logger.debug(str(e))
except SessionError as e:
self.logger.debug(f"Failed listing files on share '{share}'' in folder '{subfolder}': {e}")
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"Received a NetBIOSTimeout, moving on....")
return []
return filelist
def get_remote_file(self, share, path):
@@ -231,6 +232,7 @@ class SMBSpiderPlus:
# - It's a file then we apply the checks
for result in filelist:
next_filedir = result.get_longname()
# "ServiceProfiles", "assembly", "Boot", "CbsTemp", "Fonts", "Installer", "Microsoft.NET"
if next_filedir in [".", ".."]:
continue
next_fullpath = folder + next_filedir