Skip to content

Commit

Permalink
add command line parameter to force ldaps usage
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkjanm committed Dec 13, 2023
1 parent 5d57ca0 commit 8370131
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 4 additions & 2 deletions bloodhound/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def connect(self):
self.pdc = ADDC(pdc, self.ad)
# Create an object resolver
self.ad.create_objectresolver(self.pdc)
# self.pdc.ldap_connect(self.ad.auth.username, self.ad.auth.password, kdc)


def run(self, collect, num_workers=10, disable_pooling=False, timestamp="", computerfile="", cachefile=None, exclude_dcs=False, fileNamePrefix=""):
Expand Down Expand Up @@ -258,6 +257,9 @@ def main():
coopts.add_argument('--cachefile',
action='store',
help='Cache file (experimental)')
coopts.add_argument('--use-ldaps',
action='store_true',
help='Use LDAP over TLS on port 636 by default')
coopts.add_argument('-op',
'--outputprefix',
metavar='PREFIX_NAME',
Expand Down Expand Up @@ -294,7 +296,7 @@ def main():
else:
auth = ADAuthentication(username=args.username, password=args.password, domain=args.domain, auth_method=args.auth_method)

ad = AD(auth=auth, domain=args.domain, nameserver=args.nameserver, dns_tcp=args.dns_tcp, dns_timeout=args.dns_timeout)
ad = AD(auth=auth, domain=args.domain, nameserver=args.nameserver, dns_tcp=args.dns_tcp, dns_timeout=args.dns_timeout, use_ldaps=args.use_ldaps)

# Resolve collection methods
collect = resolve_collection_methods(args.collectionmethod)
Expand Down
12 changes: 10 additions & 2 deletions bloodhound/ad/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,15 @@ def __init__(self, hostname=None, ad=None):
# Initialize GUID map
self.objecttype_guid_map = dict()

def ldap_connect(self, protocol='ldap', resolver=False):
def ldap_connect(self, protocol=None, resolver=False):
"""
Connect to the LDAP service
"""
if not protocol:
protocol = self.ad.ldap_default_protocol

logging.info('Connecting to LDAP server: %s' % self.hostname)
logging.debug('Using protocol %s' % protocol)

# Convert the hostname to an IP, this prevents ldap3 from doing it
# which doesn't use our custom nameservers
Expand Down Expand Up @@ -580,7 +584,7 @@ def get_root_domain(self):
"""
class AD(object):

def __init__(self, domain=None, auth=None, nameserver=None, dns_tcp=False, dns_timeout=3.0):
def __init__(self, domain=None, auth=None, nameserver=None, dns_tcp=False, dns_timeout=3.0, use_ldaps=False):
self.domain = domain
# Object of type ADDomain, added later
self.domain_object = None
Expand Down Expand Up @@ -637,6 +641,10 @@ def __init__(self, domain=None, auth=None, nameserver=None, dns_tcp=False, dns_t
self.baseDN = ADUtils.domain2ldap(domain)
else:
self.baseDN = None
if use_ldaps:
self.ldap_default_protocol = 'ldaps'
else:
self.ldap_default_protocol = 'ldap'

def realm(self):
if self.domain is not None:
Expand Down

0 comments on commit 8370131

Please sign in to comment.