Skip to content

Commit

Permalink
Fixed bug with wildcards not being detected when their answers contai…
Browse files Browse the repository at this point in the history
…ned CNAME records
  • Loading branch information
d3mondev committed Jul 30, 2020
1 parent 31d5941 commit 293018e
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions wildcarder
Original file line number Diff line number Diff line change
Expand Up @@ -102,26 +102,33 @@ def load_massdns_cache(filename):
def get_parent(domain):
return '.'.join(domain.split('.')[1:])

def run_dig(record, domain):
cmd = 'dig +short ' + record + ' ' + domain
process = subprocess.Popen(['bash', '-c', cmd], stdout = subprocess.PIPE, universal_newlines = True)
stdout, stderr = process.communicate()

if process.returncode != 0:
print("Unable to run {0}".format(cmd))
exit(1)

answers = []
for line in stdout.splitlines():
answers.append(line.strip().rstrip('.'))

return answers

def dns_resolve(domain):
answers = []
if domain in dns_cache:
answers = dns_cache[domain]
else:
cmd = 'dig +short ' + domain
process = subprocess.Popen(['bash', '-c', cmd], stdout = subprocess.PIPE, universal_newlines = True)
stdout, stderr = process.communicate()

if process.returncode != 0:
print("Unable to run {0}".format(cmd))
exit(1)

for line in stdout.splitlines():
answers.append(line.strip().rstrip('.'))
answers = run_dig('A', domain)
answers += run_dig('CNAME', domain)

dns_cache[domain] = answers

global dns_queries_count
dns_queries_count = dns_queries_count + 1
dns_queries_count = dns_queries_count + 2

return answers

Expand All @@ -146,7 +153,7 @@ def get_wildcard_root(domain):
for i in range(numparts - 1, 0, -1):
parent = '.'.join(parts[i - 1:numparts])
if is_wildcard_root(parent, domain):
return topmost
break
topmost = parent

return topmost
Expand Down

0 comments on commit 293018e

Please sign in to comment.