Test LDAP connection
(self, verbose=True)
| 149 | return False |
| 150 | |
| 151 | def test_ldap_connection(self, verbose=True): |
| 152 | """Test LDAP connection""" |
| 153 | try: |
| 154 | if verbose: |
| 155 | logger.debug(f"Trying LDAP connection to {self.target}") |
| 156 | |
| 157 | # For Kerberos, skip detailed LDAP test to avoid delays |
| 158 | if self.use_kerberos and self.kerberos_ticket: |
| 159 | if verbose: |
| 160 | logger.debug("Skipping detailed LDAP test for Kerberos (speed optimization)") |
| 161 | return True # Assume it works if we got here |
| 162 | |
| 163 | # Create LDAP connection |
| 164 | if self.use_kerberos and self.kerberos_ticket: |
| 165 | if verbose: |
| 166 | logger.debug("Using Kerberos ticket") |
| 167 | if not self._load_kerberos_ticket(): |
| 168 | return False |
| 169 | ldapConnection = LDAPConnection(f'ldap://{self.target}') |
| 170 | ldapConnection.kerberosLogin(self.username, self.password, self.domain, |
| 171 | self.lm_hash, self.nt_hash, useCache=True) |
| 172 | |
| 173 | elif self.ntlm_hash: |
| 174 | if verbose: |
| 175 | logger.debug("Using NTLM hash") |
| 176 | ldapConnection = LDAPConnection(f'ldap://{self.target}') |
| 177 | ldapConnection.login(self.username, self.password, self.domain, |
| 178 | self.lm_hash, self.nt_hash) |
| 179 | |
| 180 | else: |
| 181 | if verbose: |
| 182 | logger.debug("Using plain password") |
| 183 | ldapConnection = LDAPConnection(f'ldap://{self.target}') |
| 184 | ldapConnection.login(self.username, self.password, self.domain) |
| 185 | |
| 186 | if verbose: |
| 187 | logger.debug("LDAP connection successful!") |
| 188 | |
| 189 | # Test domain info |
| 190 | base_dn = f"DC={self.domain.replace('.', ',DC=')}" |
| 191 | search_filter = "(objectClass=domain)" |
| 192 | attributes = ['name', 'objectSid', 'whenCreated'] |
| 193 | |
| 194 | resp = ldapConnection.search( |
| 195 | searchBase=base_dn, |
| 196 | scope=2, # SCOPE_SUBTREE |
| 197 | searchFilter=search_filter, |
| 198 | attributes=attributes, |
| 199 | sizeLimit=1 |
| 200 | ) |
| 201 | |
| 202 | if verbose: |
| 203 | for item in resp: |
| 204 | if isinstance(item, ldapasn1.SearchResultEntry): |
| 205 | logger.debug(f"Domain information:") |
| 206 | for attr in item['attributes']: |
| 207 | attr_name = str(attr['type']) |
| 208 | attr_values = [str(val) for val in attr['vals']] |
no test coverage detected