@@ -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,20 +576,20 @@ 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
584582 return True
585583
586- def create_conn_obj (self ):
584+ def create_conn_obj (self , no_smbv1 = False ):
587585 """
588586 Tries to create a connection object to the target host.
589587 On first try, it will try to create a SMBv1 connection.
590588 On further tries, it will remember which SMB version is supported and create a connection object accordingly.
589+
590+ :param no_smbv1: If True, it will not try to create a SMBv1 connection
591591 """
592- if self .args .force_smbv2 :
593- return self .create_smbv3_conn ()
592+ no_smbv1 = self .args .no_smbv1 if self .args .no_smbv1 else no_smbv1
594593
595594 # Initial negotiation
596595 if self .smbv1 is None :
@@ -599,7 +598,7 @@ def create_conn_obj(self):
599598 return True
600599 elif not self .is_timeouted :
601600 return self .create_smbv3_conn ()
602- elif self .smbv1 :
601+ elif not no_smbv1 and self .smbv1 :
603602 return self .create_smbv1_conn ()
604603 else :
605604 return self .create_smbv3_conn ()
@@ -841,6 +840,7 @@ def shares(self):
841840 temp_dir = ntpath .normpath ("\\ " + gen_random_string ())
842841 temp_file = ntpath .normpath ("\\ " + gen_random_string () + ".txt" )
843842 permissions = []
843+ write_check = True if not self .args .no_write_check else False
844844
845845 try :
846846 self .logger .debug (f"domain: { self .domain } " )
@@ -880,17 +880,21 @@ def shares(self):
880880 write = False
881881 write_dir = False
882882 write_file = False
883- pwd = ntpath .join ("\\ " , "*" )
884- pwd = ntpath .normpath (pwd )
885883 try :
886- self .conn .listPath (share_name , pwd )
884+ self .conn .listPath (share_name , "*" )
887885 read = True
888886 share_info ["access" ].append ("READ" )
889887 except SessionError as e :
890888 error = get_error_string (e )
891889 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 } " )
892896
893- if not self . args . no_write_check :
897+ if write_check :
894898 try :
895899 self .conn .createDirectory (share_name , temp_dir )
896900 write_dir = True
0 commit comments