Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding a DC ip override option #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions bloodhound/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, ad):
self.sessions = []


def connect(self):
def connect(self, dc_ip=None):
if len(self.ad.dcs()) == 0:
logging.error('Could not find a domain controller. Consider specifying a domain and/or DNS server.')
sys.exit(1)
Expand All @@ -60,7 +60,7 @@ def connect(self):
logging.debug('Using kerberos realm: %s', self.ad.realm())

# Create a domain controller object
self.pdc = ADDC(pdc, self.ad)
self.pdc = ADDC(pdc, self.ad, override_ip=dc_ip)
# Create an object resolver
self.ad.create_objectresolver(self.pdc)
# self.pdc.ldap_connect(self.ad.auth.username, self.ad.auth.password, kdc)
Expand Down Expand Up @@ -214,6 +214,11 @@ def main():
metavar='HOST',
action='store',
help='Override which DC to query (hostname)')
parser.add_argument('-dc-ip',
'--domain-controller-ipaddress',
action='store',
default=None,
help='Override which DC IP address to query (if the dc has an interface you cannot hit)')
parser.add_argument('-gc',
'--global-catalog',
metavar='HOST',
Expand Down Expand Up @@ -293,7 +298,7 @@ def main():
# For adding timestamp prefix to the outputfiles
timestamp = datetime.datetime.fromtimestamp(time.time()).strftime('%Y%m%d%H%M%S') + "_"
bloodhound = BloodHound(ad)
bloodhound.connect()
bloodhound.connect(args.domain_controller_ipaddress)
bloodhound.run(collect=collect,
num_workers=args.workers,
disable_pooling=args.disable_pooling,
Expand Down
27 changes: 24 additions & 3 deletions bloodhound/ad/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
Active Directory Domain Controller
"""
class ADDC(ADComputer):
def __init__(self, hostname=None, ad=None):
def __init__(self, hostname=None, ad=None, override_ip=None):
ADComputer.__init__(self, hostname)
self.ad = ad
# Primary LDAP connection
Expand All @@ -52,6 +52,8 @@ def __init__(self, hostname=None, ad=None):
self.gcldap = None
# Initialize GUID map
self.objecttype_guid_map = dict()
# override which IP gets chosen
self.dc_ipaddress = override_ip

def ldap_connect(self, protocol='ldap', resolver=False):
"""
Expand All @@ -62,8 +64,27 @@ def ldap_connect(self, protocol='ldap', resolver=False):
# 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:
ip = r.address

# if an overrided DC IP address was provided
if self.dc_ipaddress:

# checking if in results from dns resolution
in_results = False
results = []
for r in q:
results.append(r.address)
if r.address == self.dc_ipaddress:
in_results = True
if not in_results:
logging.warning('Your Domain Controllers override IP address appears to not be resolved for the primary DC. results are:')
logging.warning(' '.join(results))

# still let user assign, since it was an override
ip = self.dc_ipaddress
else:
# normal logic without an overriding DC IP address
for r in q:
ip = r.address

ldap = self.ad.auth.getLDAPConnection(hostname=ip,
baseDN=self.ad.baseDN, protocol=protocol)
Expand Down