Created
February 21, 2025 22:11
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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