@@ -419,11 +419,14 @@ def __init__(self, user='', pw='', domain='', ticket_file='', nthash='', local_a
419419 self .random_user = '' .join (random .choice ("abcdefghijklmnopqrstuvwxyz" ) for i in range (8 ))
420420 self .user = user
421421 self .pw = pw
422- self .domain = domain
423422 self .ticket_file = ticket_file
424423 self .nthash = nthash
425424 self .local_auth = local_auth
426- self .domain_set = False
425+
426+ # Only set the domain here, if it is not empty
427+ self .domain = ''
428+ if domain :
429+ self .set_domain (domain )
427430
428431 if ticket_file :
429432 result = self .valid_ticket (ticket_file )
@@ -455,12 +458,17 @@ def valid_nthash(self, nthash):
455458 def valid_ticket (self , ticket_file ):
456459 return valid_file (ticket_file )
457460
458- def update_domain (self , domain ):
459- if self .domain_set :
460- return
461-
462- self .domain = domain
463- self .domain_set = True
461+ # Allows various modules to set the domain during enumeration. The domain can only be set once.
462+ # Currently, we rely on the information gained via unauth smb session to guess the domain.
463+ # At a later call of lsaquery it might turn out that the domain is different. In this case the
464+ # user will be informed via print_hint()
465+ def set_domain (self , domain ):
466+ if self .domain and self .domain == domain :
467+ return True
468+ if not self .domain :
469+ self .domain = domain
470+ return True
471+ return False
464472
465473 def as_dict (self ):
466474 return {'credentials' :OrderedDict ({'auth_method' :self .auth_method , 'user' :self .user , 'password' :self .pw , 'domain' :self .domain , 'ticket_file' :self .ticket_file , 'nthash' :self .nthash , 'random_user' :self .random_user })}
@@ -847,7 +855,7 @@ def get_domain(self, nmblookup_result):
847855 return Result (None , "Could not find domain/domain" )
848856
849857 if not self .creds .local_auth :
850- self .creds .update_domain (domain )
858+ self .creds .set_domain (domain )
851859 return Result (domain , f"Got domain/workgroup name: { domain } " )
852860
853861 def nmblookup_to_human (self , nmblookup_result ):
@@ -1301,7 +1309,7 @@ def enum_from_smb(self):
13011309 smb_domain_info ["Derived membership" ] = "domain member"
13021310
13031311 if not self .creds .local_auth :
1304- self .creds .update_domain (smb_domain_info ["NetBIOS domain name" ])
1312+ self .creds .set_domain (smb_domain_info ["NetBIOS domain name" ])
13051313 elif (smb_domain_info ["NetBIOS domain name" ] and
13061314 not smb_domain_info ["NetBIOS computer name" ] and
13071315 not smb_domain_info ["FQDN" ] and
@@ -1311,17 +1319,18 @@ def enum_from_smb(self):
13111319 smb_domain_info ["Derived membership" ] = "workgroup member"
13121320
13131321 if not self .creds .local_auth :
1314- self .creds .update_domain (smb_domain_info ["NetBIOS domain name" ])
1322+ self .creds .set_domain (smb_domain_info ["NetBIOS domain name" ])
13151323 elif smb_domain_info ["NetBIOS computer name" ]:
13161324
13171325 smb_domain_info ["Derived domain/workgroup" ] = "unknown"
13181326 smb_domain_info ["Derived membership" ] = "workgroup member"
13191327
13201328 if self .creds .local_auth :
1321- self .creds .update_domain (smb_domain_info ["NetBIOS computer name" ])
1322- else :
1323- # Fallback to local authentication via '.' if nothing else can be found
1324- self .creds .update_domain ('.' )
1329+ self .creds .set_domain (smb_domain_info ["NetBIOS computer name" ])
1330+
1331+ # Fallback to default workgroup 'WORKGROUP' if nothing else can be found
1332+ if not self .creds .domain :
1333+ self .creds .set_domain ('WORKGROUP' )
13251334
13261335 if not any (smb_domain_info .values ()):
13271336 return Result (None , "Could not enumerate domain information via unauthenticated SMB" )
@@ -1353,6 +1362,14 @@ def run(self):
13531362 if result .retval :
13541363 print_success (result .retmsg )
13551364 rpc_domain_info ["Domain" ] = result .retval
1365+
1366+ # In previous enumeration steps the domain was enumerated via unauthenticated
1367+ # SMB session. The domain found there might not be correct. Therefore, we only inform
1368+ # the user that we found a different domain via lsaquery. Jumping back to the session
1369+ # checks does not make sense. If the user was able to call lsaquery, he is already
1370+ # authenticated (likely via null session).
1371+ if not self .creds .local_auth and not self .creds .set_domain (result .retval ):
1372+ print_hint (f"Found domain/workgroup '{ result .retval } ' which is different from the currently used one '{ self .creds .domain } '." )
13561373 else :
13571374 output = process_error (result .retmsg , ["rpc_domain_info" ], module_name , output )
13581375
0 commit comments