Skip to content

Instantly share code, notes, and snippets.

@scmanjarrez
Created February 21, 2025 22:11
Show Gist options
  • Save scmanjarrez/a96fe918a64d66679143b7f7d29969de to your computer and use it in GitHub Desktop.
Save scmanjarrez/a96fe918a64d66679143b7f7d29969de to your computer and use it in GitHub Desktop.
Small patch for bloodhound-python ce to test resolved IP before choosing blindly
import ldap3
# Convert the hostname to an IP, this prevents ldap3 from doing it
# which doesn't use our custom nameservers
q = self.ad.dnsresolver.query(self.hostname, tcp=self.ad.dns_tcp)
for r in q:
try:
logging.info('Testing resolved hostname connectivity %s' % r.address)
_tmp_serv = ldap3.Server(r.address, connect_timeout=5)
_conn = ldap3.Connection(_tmp_serv)
_bind = _conn.bind()
except ldap3.core.exceptions.LDAPSocketOpenError:
continue
else:
if _conn:
ip = r.address
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment