@@ -151,6 +151,7 @@ def __init__(self, args, db, host):
151151 self .admin_privs = False
152152 self .no_ntlm = False
153153 self .sid_domain = ""
154+ self .scope = None
154155
155156 connection .__init__ (self , args , db , host )
156157
@@ -249,6 +250,8 @@ def enum_host_info(self):
249250 if ntlm_challenge :
250251 ntlm_info = parse_challenge (ntlm_challenge )
251252 self .server_os = ntlm_info ["os_version" ]
253+ else :
254+ self .no_ntlm = True
252255
253256 if self .args .domain :
254257 self .domain = self .args .domain
@@ -419,6 +422,7 @@ def kerberos_login(self, domain, username, password="", ntlm_hash="", aesKey="",
419422 return False
420423
421424 def plaintext_login (self , domain , username , password ):
425+
422426 self .username = username
423427 self .password = password
424428 self .domain = domain
@@ -623,7 +627,7 @@ def getUnixTime(self, t):
623627 return t
624628
625629 def search (self , searchFilter , attributes , sizeLimit = 0 , baseDN = None ) -> list :
626- if baseDN is None and self .args .base_dn :
630+ if baseDN is None and self .args .base_dn is not None :
627631 baseDN = self .args .base_dn
628632 elif baseDN is None :
629633 baseDN = self .baseDN
@@ -633,19 +637,24 @@ def search(self, searchFilter, attributes, sizeLimit=0, baseDN=None) -> list:
633637 self .logger .debug (f"Search Filter={ searchFilter } " )
634638
635639 # Microsoft Active Directory set an hard limit of 1000 entries returned by any search
636- paged_search_control = ldapasn1_impacket .SimplePagedResultsControl (criticality = True , size = 1000 )
640+ paged_search_control = [ ldapasn1_impacket .SimplePagedResultsControl (criticality = True , size = 1000 )] if not self . no_ntlm else ""
637641 return self .ldap_connection .search (
642+ scope = self .scope ,
638643 searchBase = baseDN ,
639644 searchFilter = searchFilter ,
640645 attributes = attributes ,
641646 sizeLimit = sizeLimit ,
642- searchControls = [ paged_search_control ] ,
647+ searchControls = paged_search_control ,
643648 )
644649 except ldap_impacket .LDAPSearchError as e :
645- if e . getErrorString (). find ( "sizeLimitExceeded" ) >= 0 :
650+ if "sizeLimitExceeded" in str ( e ) :
646651 # We should never reach this code as we use paged search now
647652 self .logger .fail ("sizeLimitExceeded exception caught, giving up and processing the data received" )
648653 e .getAnswers ()
654+ # if empty username and password is possible that we need to change the scope, we try with a baseObject before returning a fail
655+ elif "operationsError" in str (e ) and self .scope is None and self .username == "" and self .password == "" :
656+ self .scope = ldapasn1_impacket .Scope ("baseObject" )
657+ return self .search (searchFilter , attributes , sizeLimit , baseDN )
649658 else :
650659 self .logger .fail (e )
651660 return []
0 commit comments