@@ -549,7 +549,6 @@ def create_smbv1_conn(self):
549549 preferredDialect = SMB_DIALECT ,
550550 timeout = self .args .smb_timeout ,
551551 )
552- self .smbv1 = True
553552 except OSError as e :
554553 if "Connection reset by peer" in str (e ):
555554 self .logger .info (f"SMBv1 might be disabled on { self .host } " )
@@ -577,7 +576,6 @@ def create_smbv3_conn(self):
577576 self .port ,
578577 timeout = self .args .smb_timeout ,
579578 )
580- self .smbv1 = False
581579 except (Exception , NetBIOSTimeout , OSError ) as e :
582580 self .logger .info (f"Error creating SMBv3 connection to { self .host } : { e } " )
583581 return False
@@ -591,6 +589,8 @@ def create_conn_obj(self, no_smbv1=False):
591589
592590 :param no_smbv1: If True, it will not try to create a SMBv1 connection
593591 """
592+ no_smbv1 = self .args .no_smbv1 if self .args .no_smbv1 else no_smbv1
593+
594594 # Initial negotiation
595595 if not no_smbv1 and self .smbv1 is None :
596596 self .smbv1 = self .create_smbv1_conn ()
@@ -840,6 +840,7 @@ def shares(self):
840840 temp_dir = ntpath .normpath ("\\ " + gen_random_string ())
841841 temp_file = ntpath .normpath ("\\ " + gen_random_string () + ".txt" )
842842 permissions = []
843+ write_check = True if not self .args .no_write_check else False
843844
844845 try :
845846 self .logger .debug (f"domain: { self .domain } " )
@@ -886,8 +887,14 @@ def shares(self):
886887 except SessionError as e :
887888 error = get_error_string (e )
888889 self .logger .debug (f"Error checking READ access on share { share_name } : { error } " )
890+ except (NetBIOSError , UnicodeEncodeError ) as e :
891+ write_check = False
892+ share_info ["access" ].append ("UNKNOWN (try '--no-smbv1')" )
893+ error = get_error_string (e )
894+ self .logger .debug (f"Error checking READ access on share { share_name } : { error } . This exception always caused by special character in share name with SMBv1" )
895+ self .logger .info (f"Skipping WRITE permission check on share { share_name } " )
889896
890- if not self . args . no_write_check :
897+ if write_check :
891898 try :
892899 self .conn .createDirectory (share_name , temp_dir )
893900 write_dir = True
0 commit comments