Skip to content

Commit

Permalink
fixed detection when using gethostbyaddr
Browse files Browse the repository at this point in the history
  • Loading branch information
blark committed Jun 4, 2019
1 parent 1c2aaa0 commit e606e12
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions aiodnsbrute/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ def _dns_result_callback(self, name, future):
# parse and output and store results.
else:
if self.lookup_type == "query":
ip = ", ".join([ip.host for ip in future.result()])
ips = [ip.host for ip in future.result()]
cname = False
row = f"{name:<30}\t{ip}"
row = f"{name:<30}\t{ips}"
elif self.lookup_type == "gethostbyname":
r = future.result()
ip = ", ".join([ip for ip in r.addresses])
ips = [ip for ip in r.addresses]
if name == r.name:
cname = False
n = f"""{name:<30}\t{f"{'':<35}" if self.verbosity >= 2 else ""}"""
Expand All @@ -104,12 +104,12 @@ def _dns_result_callback(self, name, future):
# format the name based on verbosity - this is kluge
short_cname = f"{r.name[:28]}.." if len(r.name) > 30 else r.name
n = f'{name}{"**" if self.verbosity <= 1 else ""}'
n = f'{n:<30}\t{f"CNAME {short_cname:<30}" if self.verbosity >= 2 else ""}'
row = f"{n:<30}\t{ip}"
n = f'''{n:<30}\t{f"CNAME {short_cname:<30}" if self.verbosity >= 2 else ""}'''
row = f"{n:<30}\t{ips}"
# store the result
if ip not in self.ignore_hosts:
if set(ips) != set(self.ignore_hosts):
self.logger.success(row)
dns_lookup_result = {"domain": name, "ip": [ip]}
dns_lookup_result = {"domain": name, "ip": ips}
if self.lookup_type == "gethostbyname" and cname:
dns_lookup_result["cname"] = r.name
dns_lookup_result["aliases"] = r.aliases
Expand Down Expand Up @@ -177,23 +177,13 @@ def run(
f"Using recursive DNS with the following servers: {self.resolver.nameservers}"
)

if query:
self.logger.info(
"Using pycares `query` function to perform lookups, CNAMEs cannot be identified"
)
self.lookup_type = "query"
else:
self.logger.info(
"Using pycares `gethostbyname` function to perform lookups, CNAME data will be appended to results (** denotes CNAME, show actual name with -vv)"
)
self.lookup_type = "gethostbyname"

if wildcard:
# 63 chars is the max allowed segment length, there is practically no chance that it will be a legit record
random_sld = (
lambda: f'{"".join(random.choice(string.ascii_lowercase + string.digits) for i in range(63))}'
)
try:
self.lookup_type = "query"
wc_check = self.loop.run_until_complete(
self._dns_lookup(f"{random_sld()}.{domain}")
)
Expand All @@ -212,6 +202,17 @@ def run(
else:
self.logger.warn("Wildcard detection is disabled")

if query:
self.logger.info(
"Using pycares `query` function to perform lookups, CNAMEs cannot be identified"
)
self.lookup_type = "query"
else:
self.logger.info(
"Using pycares `gethostbyname` function to perform lookups, CNAME data will be appended to results (** denotes CNAME, show actual name with -vv)"
)
self.lookup_type = "gethostbyname"

with open(wordlist, encoding="utf-8", errors="ignore") as words:
w = words.read().splitlines()
self.logger.info(f"Wordlist loaded, proceeding with {len(w)} DNS requests")
Expand Down

0 comments on commit e606e12

Please sign in to comment.