@@ -157,6 +157,7 @@ def __init__(self, args, db, host):
157157 self .bootkey = None
158158 self .output_filename = None
159159 self .smbv1 = None
160+ self .smbv3 = None
160161 self .is_timeouted = False
161162 self .signing = False
162163 self .smb_share_name = smb_share_name
@@ -295,6 +296,10 @@ def enum_host_info(self):
295296 except Exception as e :
296297 self .logger .debug (f"Error logging off system: { e } " )
297298
299+ # Check smbv1
300+ if not self .args .no_smbv1 :
301+ self .smbv1 = self .create_smbv1_conn (check = True )
302+
298303 # DCOM connection with kerberos needed
299304 self .remoteName = self .host if not self .kerberos else f"{ self .hostname } .{ self .targetDomain } "
300305
@@ -538,17 +543,19 @@ def hash_login(self, domain, username, ntlm_hash):
538543 self .create_conn_obj ()
539544 return False
540545
541- def create_smbv1_conn (self ):
542- self .logger .debug (f"Creating SMBv1 connection to { self .host } " )
546+ def create_smbv1_conn (self , check = False ):
547+ self .logger .info (f"Creating SMBv1 connection to { self .host } " )
543548 try :
544- self . conn = SMBConnection (
549+ conn = SMBConnection (
545550 self .remoteName ,
546551 self .host ,
547552 None ,
548553 self .port ,
549554 preferredDialect = SMB_DIALECT ,
550555 timeout = self .args .smb_timeout ,
551556 )
557+ if check :
558+ self .conn = conn
552559 except OSError as e :
553560 if "Connection reset by peer" in str (e ):
554561 self .logger .info (f"SMBv1 might be disabled on { self .host } " )
@@ -567,7 +574,7 @@ def create_smbv1_conn(self):
567574 return True
568575
569576 def create_smbv3_conn (self ):
570- self .logger .debug (f"Creating SMBv3 connection to { self .host } " )
577+ self .logger .info (f"Creating SMBv3 connection to { self .host } " )
571578 try :
572579 self .conn = SMBConnection (
573580 self .remoteName ,
@@ -581,27 +588,26 @@ def create_smbv3_conn(self):
581588 return False
582589 return True
583590
584- def create_conn_obj (self , no_smbv1 = False ):
591+ def create_conn_obj (self ):
585592 """
586593 Tries to create a connection object to the target host.
587- On first try, it will try to create a SMBv1 connection.
594+ On first try, it will try to create a SMBv3 connection.
588595 On further tries, it will remember which SMB version is supported and create a connection object accordingly.
589596
590597 :param no_smbv1: If True, it will not try to create a SMBv1 connection
591598 """
592- no_smbv1 = self .args .no_smbv1 if self .args .no_smbv1 else no_smbv1
593599
594600 # Initial negotiation
595- if not no_smbv1 and self .smbv1 is None :
596- self .smbv1 = self .create_smbv1_conn ()
597- if self .smbv1 :
601+ if self .smbv3 is None :
602+ self .smbv3 = self .create_smbv3_conn ()
603+ if self .smbv3 :
598604 return True
599605 elif not self .is_timeouted :
600- return self .create_smbv3_conn ()
601- elif not no_smbv1 and self .smbv1 :
602- return self .create_smbv1_conn ()
603- else :
606+ return self .create_smbv1_conn ()
607+ elif self .smbv3 :
604608 return self .create_smbv3_conn ()
609+ else :
610+ return self .create_smbv1_conn ()
605611
606612 def check_if_admin (self ):
607613 self .logger .debug (f"Checking if user is admin on { self .host } " )
0 commit comments