Code optimization
This commit is contained in:
parent
b441bf9e96
commit
665d28d181
@ -1,6 +1,6 @@
|
|||||||
# Mass DNS AXFR (Zone Transfer)
|
# Mass DNS AXFR (Zone Transfer)
|
||||||
|
|
||||||
###### This script will attempt a [Zone Transfer](https://en.wikipedia.org/wiki/DNS_zone_transfer) on all of the [Root Nameservers](https://en.wikipedia.org/wiki/Root_name_server) and [Top-level Domains](https://en.wikipedia.org/wiki/Top-level_domain) *(TLDs)*.
|
###### [Zone Transfer](https://en.wikipedia.org/wiki/DNS_zone_transfer) on all of the [Root Nameservers](https://en.wikipedia.org/wiki/Root_name_server) and [Top-level Domains](https://en.wikipedia.org/wiki/Top-level_domain) *(TLDs)*.
|
||||||
|
|
||||||
## Expectations & Legalities
|
## Expectations & Legalities
|
||||||
It is expected to set *realistic* expectations when using this tool. In contemporary network configurations, AXFR requests are typically restricted, reflecting best practices in DNS security. While many nameservers now disallow AXFR requests, there may still be occasional instances where configurations permit them. Always exercise due diligence and ensure ethical use.
|
It is expected to set *realistic* expectations when using this tool. In contemporary network configurations, AXFR requests are typically restricted, reflecting best practices in DNS security. While many nameservers now disallow AXFR requests, there may still be occasional instances where configurations permit them. Always exercise due diligence and ensure ethical use.
|
||||||
|
2
mdaxfr
2
mdaxfr
@ -31,7 +31,7 @@ attempt_axfr() {
|
|||||||
|
|
||||||
# For root nameservers
|
# For root nameservers
|
||||||
for root in $(dig +short . NS); do
|
for root in $(dig +short . NS); do
|
||||||
attempt_axfr "." "$root" "$OUTPUT_DIR/$root-root.txt"
|
attempt_axfr "." "$root" "$OUTPUT_DIR/$root.txt"
|
||||||
done
|
done
|
||||||
|
|
||||||
# For TLD nameservers
|
# For TLD nameservers
|
||||||
|
44
mdaxfr.py
44
mdaxfr.py
@ -42,11 +42,21 @@ def attempt_axfr(tld: str, nameserver: str, filename: str):
|
|||||||
logging.error(f'Failed to perform zone transfer from {nameserver.address} for {tld}: {ex}')
|
logging.error(f'Failed to perform zone transfer from {nameserver.address} for {tld}: {ex}')
|
||||||
|
|
||||||
|
|
||||||
def get_root_nameservers() -> list:
|
def get_nameservers(target: str) -> list:
|
||||||
'''Generate a list of the root nameservers.'''
|
'''
|
||||||
root_ns_records = dns.resolver.resolve('.', 'NS', lifetime=15)
|
Generate a list of the root nameservers.
|
||||||
root_servers = [str(rr.target)[:-1] for rr in root_ns_records]
|
|
||||||
return root_servers
|
:param target: The target domain to get the nameservers for.
|
||||||
|
'''
|
||||||
|
try:
|
||||||
|
ns_records = dns.resolver.resolve(target+'.', 'NS', lifetime=60)
|
||||||
|
nameservers = [str(rr.target)[:-1] for rr in ns_records]
|
||||||
|
return nameservers
|
||||||
|
except dns.exception.Timeout:
|
||||||
|
logging.warning(f'Timeout fetching nameservers for {target}')
|
||||||
|
except dns.resolver.NoNameservers:
|
||||||
|
logging.warning(f'No nameservers found for {target}')
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
def get_root_tlds() -> list:
|
def get_root_tlds() -> list:
|
||||||
@ -56,17 +66,6 @@ def get_root_tlds() -> list:
|
|||||||
return tlds
|
return tlds
|
||||||
|
|
||||||
|
|
||||||
def get_tld_nameservers(tld: str) -> list:
|
|
||||||
'''Get the nameservers for a TLD.'''
|
|
||||||
try:
|
|
||||||
return [str(nameserver) for nameserver in dns.resolver.resolve(tld+'.', 'NS', lifetime=60)]
|
|
||||||
except dns.exception.Timeout:
|
|
||||||
logging.warning(f'Timeout fetching nameservers for TLD: {tld}')
|
|
||||||
except dns.resolver.NoNameservers:
|
|
||||||
logging.warning(f'No nameservers found for TLD: {tld}')
|
|
||||||
return []
|
|
||||||
|
|
||||||
|
|
||||||
def get_psl_tlds() -> list:
|
def get_psl_tlds() -> list:
|
||||||
'''Download the Public Suffix List and return its contents.'''
|
'''Download the Public Suffix List and return its contents.'''
|
||||||
data = urllib.request.urlopen('https://publicsuffix.org/list/public_suffix_list.dat').read().decode()
|
data = urllib.request.urlopen('https://publicsuffix.org/list/public_suffix_list.dat').read().decode()
|
||||||
@ -82,7 +81,7 @@ def get_psl_tlds() -> list:
|
|||||||
return domains
|
return domains
|
||||||
|
|
||||||
|
|
||||||
def resolve_nameserver(nameserver: str) -> str:
|
def resolve_nameserver(nameserver: str) -> list:
|
||||||
'''
|
'''
|
||||||
Resolve a nameserver to its IP address.
|
Resolve a nameserver to its IP address.
|
||||||
|
|
||||||
@ -111,24 +110,29 @@ if __name__ == '__main__':
|
|||||||
os.makedirs(args.output, exist_ok=True)
|
os.makedirs(args.output, exist_ok=True)
|
||||||
dns.resolver._DEFAULT_TIMEOUT = args.timeout
|
dns.resolver._DEFAULT_TIMEOUT = args.timeout
|
||||||
|
|
||||||
|
# Grab the root nameservers
|
||||||
|
os.makedirs(os.path.join(args.output, 'root'), exist_ok=True)
|
||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=args.concurrency) as executor:
|
with concurrent.futures.ThreadPoolExecutor(max_workers=args.concurrency) as executor:
|
||||||
futures = [executor.submit(attempt_axfr, '', root, os.path.join(args.output, root + '.txt')) for root in get_root_nameservers()]
|
futures = [executor.submit(attempt_axfr, '', root, os.path.join(args.output, f'root/{root}.txt')) for root in get_nameservers('')]
|
||||||
for future in concurrent.futures.as_completed(futures):
|
for future in concurrent.futures.as_completed(futures):
|
||||||
try:
|
try:
|
||||||
future.result()
|
future.result()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f'Error in root server task: {e}')
|
logging.error(f'Error in root server task: {e}')
|
||||||
|
|
||||||
|
# Get the root TLDs
|
||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=args.concurrency) as executor:
|
with concurrent.futures.ThreadPoolExecutor(max_workers=args.concurrency) as executor:
|
||||||
futures = [executor.submit(attempt_axfr, tld, ns, os.path.join(args.output, tld + '.txt')) for tld in get_root_tlds() for ns in get_tld_nameservers(tld) if ns]
|
futures = [executor.submit(attempt_axfr, tld, ns, os.path.join(args.output, tld + '.txt')) for tld in get_root_tlds() for ns in get_nameservers(tld) if ns]
|
||||||
for future in concurrent.futures.as_completed(futures):
|
for future in concurrent.futures.as_completed(futures):
|
||||||
try:
|
try:
|
||||||
future.result()
|
future.result()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f'Error in TLD task: {e}')
|
logging.error(f'Error in TLD task: {e}')
|
||||||
|
|
||||||
|
# Get the Public Suffix List
|
||||||
|
os.makedirs(os.path.join(args.output, 'psl'), exist_ok=True)
|
||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=args.concurrency) as executor:
|
with concurrent.futures.ThreadPoolExecutor(max_workers=args.concurrency) as executor:
|
||||||
futures = [executor.submit(attempt_axfr, tld, ns, os.path.join(args.output, tld + '.txt')) for tld in get_psl_tlds() for ns in get_tld_nameservers(tld) if ns]
|
futures = [executor.submit(attempt_axfr, tld, ns, os.path.join(args.output, f'psl/{tld}.txt')) for tld in get_psl_tlds() for ns in get_nameservers(tld) if ns]
|
||||||
for future in concurrent.futures.as_completed(futures):
|
for future in concurrent.futures.as_completed(futures):
|
||||||
try:
|
try:
|
||||||
future.result()
|
future.result()
|
||||||
|
1
opennic
1
opennic
@ -1,5 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# OpenNIC AXFR - devloped by acidvegas (https://git.acid.vegas/mdaxfr)
|
# OpenNIC AXFR - devloped by acidvegas (https://git.acid.vegas/mdaxfr)
|
||||||
|
# Todo: Find a better way to retrieve the TLDs so we don't have to hardcode them
|
||||||
|
|
||||||
servers=$(curl -s 'https://api.opennicproject.org/geoip/?list&ipv=all&res=100' | grep -oE '([0-9]{1,3}(\.[0-9]{1,3}){3}|[0-9a-fA-F:]+:[0-9a-fA-F:]+)')
|
servers=$(curl -s 'https://api.opennicproject.org/geoip/?list&ipv=all&res=100' | grep -oE '([0-9]{1,3}(\.[0-9]{1,3}){3}|[0-9a-fA-F:]+:[0-9a-fA-F:]+)')
|
||||||
tlds=("bbs" "chan" "cyb" "dyn" "epic" "geek" "gopher" "indy" "libre" "neo" "null" "o" "oss" "oz" "parody" "pirate" "opennic.glue" "dns.opennic.glue")
|
tlds=("bbs" "chan" "cyb" "dyn" "epic" "geek" "gopher" "indy" "libre" "neo" "null" "o" "oss" "oz" "parody" "pirate" "opennic.glue" "dns.opennic.glue")
|
||||||
|
Loading…
Reference in New Issue
Block a user