@@ -156,7 +156,8 @@ def __init__(self, args, db, host):
156156 self .remote_ops = None
157157 self .bootkey = None
158158 self .output_filename = None
159- self .smbv1 = None
159+ self .smbv1 = None # Check if SMBv1 is supported
160+ self .smbv3 = None # Check if SMBv3 is supported
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,20 @@ 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+ self .smbv1 = True
558+ if not check :
559+ self .conn = conn
552560 except OSError as e :
553561 if "Connection reset by peer" in str (e ):
554562 self .logger .info (f"SMBv1 might be disabled on { self .host } " )
@@ -567,7 +575,7 @@ def create_smbv1_conn(self):
567575 return True
568576
569577 def create_smbv3_conn (self ):
570- self .logger .debug (f"Creating SMBv3 connection to { self .host } " )
578+ self .logger .info (f"Creating SMBv3 connection to { self .host } " )
571579 try :
572580 self .conn = SMBConnection (
573581 self .remoteName ,
@@ -576,32 +584,35 @@ def create_smbv3_conn(self):
576584 self .port ,
577585 timeout = self .args .smb_timeout ,
578586 )
587+ self .smbv3 = True
579588 except (Exception , NetBIOSTimeout , OSError ) as e :
580- self .logger .info (f"Error creating SMBv3 connection to { self .host } : { e } " )
589+ if "timed out" in str (e ):
590+ self .is_timeouted = True
591+ self .logger .debug (f"Timeout creating SMBv3 connection to { self .host } " )
592+ else :
593+ self .logger .info (f"Error creating SMBv3 connection to { self .host } : { e } " )
581594 return False
582595 return True
583596
584- def create_conn_obj (self , no_smbv1 = False ):
597+ def create_conn_obj (self ):
585598 """
586599 Tries to create a connection object to the target host.
587- On first try, it will try to create a SMBv1 connection.
600+ On first try, it will try to create a SMBv3 connection.
588601 On further tries, it will remember which SMB version is supported and create a connection object accordingly.
589602
590603 :param no_smbv1: If True, it will not try to create a SMBv1 connection
591604 """
592- no_smbv1 = self .args .no_smbv1 if self .args .no_smbv1 else no_smbv1
593-
594605 # Initial negotiation
595- if not no_smbv1 and self .smbv1 is None :
596- self .smbv1 = self .create_smbv1_conn ()
597- if self .smbv1 :
606+ if self .smbv3 is None :
607+ self .smbv3 = self .create_smbv3_conn ()
608+ if self .smbv3 :
598609 return True
599610 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 :
611+ return self .create_smbv1_conn ()
612+ elif self .smbv3 :
604613 return self .create_smbv3_conn ()
614+ else :
615+ return self .create_smbv1_conn ()
605616
606617 def check_if_admin (self ):
607618 self .logger .debug (f"Checking if user is admin on { self .host } " )
0 commit comments