2023-10-28 21:55:58 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# Mass DNS AXFR - developed by acidvegas in python (https://git.acid.vegas/mdaxfr)
|
|
|
|
|
2023-10-29 04:45:10 +00:00
|
|
|
import logging
|
2023-10-29 01:40:06 +00:00
|
|
|
import os
|
2024-03-11 04:45:28 +00:00
|
|
|
import re
|
2023-10-28 21:55:58 +00:00
|
|
|
import urllib.request
|
|
|
|
|
|
|
|
try:
|
2023-11-01 21:02:39 +00:00
|
|
|
import dns.rdatatype
|
|
|
|
import dns.query
|
|
|
|
import dns.zone
|
|
|
|
import dns.resolver
|
2023-10-28 21:55:58 +00:00
|
|
|
except ImportError:
|
2023-11-01 21:02:39 +00:00
|
|
|
raise SystemExit('missing required \'dnspython\' module (pip install dnspython)')
|
2023-10-28 21:55:58 +00:00
|
|
|
|
2023-10-29 16:02:48 +00:00
|
|
|
|
2024-03-11 04:45:28 +00:00
|
|
|
# Colours
|
|
|
|
BLUE = '\033[1;34m'
|
|
|
|
CYAN = '\033[1;36m'
|
|
|
|
GREEN = '\033[1;32m'
|
|
|
|
GREY = '\033[1;90m'
|
|
|
|
PINK = '\033[1;95m'
|
|
|
|
PURPLE = '\033[0;35m'
|
|
|
|
RED = '\033[1;31m'
|
|
|
|
YELLOW = '\033[1;33m'
|
|
|
|
RESET = '\033[0m'
|
|
|
|
|
|
|
|
|
|
|
|
def attempt_axfr(domain: str, nameserver: str, nameserver_ip: str):
|
2023-11-01 21:02:39 +00:00
|
|
|
'''
|
2024-03-11 04:45:28 +00:00
|
|
|
Request a zone transfer from a nameserver on a domain.
|
2023-11-01 21:02:39 +00:00
|
|
|
|
2024-03-11 04:45:28 +00:00
|
|
|
:param domain: The domain to perform the zone transfer on.
|
2023-11-01 21:02:39 +00:00
|
|
|
:param nameserver: The nameserver to perform the zone transfer on.
|
2024-03-11 04:45:28 +00:00
|
|
|
:param nameserver_ip: The IP address of the nameserver.
|
2023-11-01 21:02:39 +00:00
|
|
|
'''
|
2024-03-11 04:45:28 +00:00
|
|
|
|
|
|
|
print(f' {YELLOW}Attempting AXFR for {CYAN}{domain}{RESET} on {PURPLE}{nameserver} {GREY}({nameserver_ip}){RESET}')
|
|
|
|
|
|
|
|
zone = dns.zone.from_xfr(dns.query.xfr(nameserver_ip, domain))
|
|
|
|
|
|
|
|
record_count = sum(len(node.rdatasets) for node in zone.nodes.values())
|
|
|
|
|
|
|
|
print(f' {GREEN}AXFR successful for {CYAN}{domain}{RESET} on {PURPLE}{nameserver} {GREY}({nameserver_ip}){RESET} - {record_count:,} records')
|
|
|
|
|
|
|
|
with open(os.path.join('axfrout', f'{domain}_{nameserver}_{nameserver_ip}.log'), 'w') as file:
|
|
|
|
file.write(zone.to_text())
|
|
|
|
|
|
|
|
|
|
|
|
def get_nameservers(domain: str) -> list:
|
2023-11-04 05:54:58 +00:00
|
|
|
'''
|
|
|
|
Generate a list of the root nameservers.
|
2023-11-26 01:38:07 +00:00
|
|
|
|
2023-11-04 05:54:58 +00:00
|
|
|
:param target: The target domain to get the nameservers for.
|
|
|
|
'''
|
2024-03-11 04:45:28 +00:00
|
|
|
|
|
|
|
ns_records = dns.resolver.resolve(domain, 'NS', lifetime=30)
|
|
|
|
nameservers = [str(rr.target)[:-1] for rr in ns_records]
|
|
|
|
|
|
|
|
return nameservers
|
2023-10-28 21:55:58 +00:00
|
|
|
|
2023-10-29 16:02:48 +00:00
|
|
|
|
2023-11-26 01:38:07 +00:00
|
|
|
def get_root_tlds(output_dir: str) -> list:
|
|
|
|
'''
|
|
|
|
Get the root TLDs from a root nameservers.
|
|
|
|
|
|
|
|
:param output_dir: The output directory to use.
|
|
|
|
'''
|
2023-11-26 04:24:04 +00:00
|
|
|
rndroot = [root for root in os.listdir(output_dir) if root.endswith('.root-servers.net.txt')]
|
2023-11-07 02:09:15 +00:00
|
|
|
if rndroot:
|
2023-11-26 01:38:07 +00:00
|
|
|
rndroot_file = rndroot[0] # Take the first file from the list
|
|
|
|
tlds = sorted(set([item.split()[0][:-1] for item in open(os.path.join(root_dir, rndroot_file)).read().split('\n') if item and 'IN' in item and 'NS' in item]))
|
2023-11-07 02:09:15 +00:00
|
|
|
else:
|
2023-11-23 20:31:46 +00:00
|
|
|
logging.warning('Failed to find root nameserver list...fallback to using IANA list')
|
2023-11-07 02:09:15 +00:00
|
|
|
tlds = urllib.request.urlopen('https://data.iana.org/TLD/tlds-alpha-by-domain.txt').read().decode('utf-8').lower().split('\n')[1:]
|
2023-11-01 21:02:39 +00:00
|
|
|
return tlds
|
2023-10-28 21:55:58 +00:00
|
|
|
|
2023-10-29 16:02:48 +00:00
|
|
|
|
2023-10-31 00:30:44 +00:00
|
|
|
def get_psl_tlds() -> list:
|
2023-11-01 21:02:39 +00:00
|
|
|
'''Download the Public Suffix List and return its contents.'''
|
|
|
|
data = urllib.request.urlopen('https://publicsuffix.org/list/public_suffix_list.dat').read().decode()
|
|
|
|
domains = []
|
|
|
|
for line in data.split('\n'):
|
|
|
|
if line.startswith('//') or not line:
|
|
|
|
continue
|
|
|
|
if '*' in line or '!' in line:
|
|
|
|
continue
|
|
|
|
if '.' not in line:
|
|
|
|
continue
|
|
|
|
domains.append(line)
|
|
|
|
return domains
|
2023-10-31 00:30:44 +00:00
|
|
|
|
|
|
|
|
2023-11-04 05:54:58 +00:00
|
|
|
def resolve_nameserver(nameserver: str) -> list:
|
2023-11-01 21:02:39 +00:00
|
|
|
'''
|
|
|
|
Resolve a nameserver to its IP address.
|
|
|
|
|
|
|
|
:param nameserver: The nameserver to resolve.
|
|
|
|
'''
|
2024-03-11 04:45:28 +00:00
|
|
|
|
2023-11-01 21:02:39 +00:00
|
|
|
data = []
|
2024-03-11 04:45:28 +00:00
|
|
|
|
2023-11-01 21:02:39 +00:00
|
|
|
for version in ('A', 'AAAA'):
|
2024-03-11 04:45:28 +00:00
|
|
|
data.extend([ip.address for ip in dns.resolver.resolve(nameserver, version, lifetime=30)])
|
|
|
|
|
2023-11-01 21:02:39 +00:00
|
|
|
return data
|
2023-10-29 16:02:48 +00:00
|
|
|
|
2023-10-28 21:55:58 +00:00
|
|
|
|
2024-03-11 04:45:28 +00:00
|
|
|
def process_domain(domain: str):
|
|
|
|
domain = re.sub(r'^https?://|^(www\.)|(/.*$)', '', domain)
|
|
|
|
|
|
|
|
print(f'{PINK}Looking up nameservers for {CYAN}{domain}{RESET}')
|
|
|
|
|
|
|
|
try:
|
|
|
|
nameservers = get_nameservers(domain)
|
|
|
|
except Exception as ex:
|
|
|
|
print(f' {RED}Error resolving nameservers for {CYAN}{domain} {GREY}({ex}){RESET}')
|
|
|
|
return
|
|
|
|
|
|
|
|
if not nameservers:
|
|
|
|
print(f' {GREY}No nameservers found for {CYAN}{domain}{RESET}')
|
|
|
|
return
|
|
|
|
|
|
|
|
print(f' {BLUE}Found {len(nameservers):,} nameservers for {CYAN}{domain}{RESET}')
|
|
|
|
|
|
|
|
for nameserver in nameservers:
|
|
|
|
print(f' {PINK}Looking up IP addresses for {PURPLE}{nameserver}{RESET}')
|
|
|
|
|
|
|
|
try:
|
|
|
|
nameserver_ips = resolve_nameserver(nameserver)
|
|
|
|
except Exception as ex:
|
|
|
|
print(f' {RED}Error resolving IP addresses for {PURPLE}{nameserver} {GREY}({ex}){RESET}')
|
|
|
|
continue
|
|
|
|
|
|
|
|
if not nameserver_ips:
|
|
|
|
print(f' {GREY}No IP addresses found for {PURPLE}{nameserver}{RESET}')
|
|
|
|
continue
|
|
|
|
|
|
|
|
print(f' {BLUE}Found {len(nameserver_ips):,} IP addresses for {PURPLE}{nameserver}{RESET}')
|
|
|
|
|
|
|
|
for nameserver_ip in nameserver_ips:
|
|
|
|
attempt_axfr(domain, nameserver, nameserver_ip)
|
|
|
|
|
|
|
|
|
2023-10-28 21:55:58 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2023-11-01 21:02:39 +00:00
|
|
|
import argparse
|
|
|
|
import concurrent.futures
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description='Mass DNS AXFR')
|
2024-03-11 04:45:28 +00:00
|
|
|
parser.add_argument('-d', '--domain', type=str,help='domain to perform AXFR on')
|
|
|
|
parser.add_argument('-i', '--input', type=str, help='input directory')
|
|
|
|
parser.add_argument('-t', '--tld', type=str, help='TLD to perform AXFR on')
|
|
|
|
parser.add_argument('-p', '--psl', action='store_true', help='use the Public Suffix List')
|
2023-11-01 21:02:39 +00:00
|
|
|
parser.add_argument('-c', '--concurrency', type=int, default=30, help='maximum concurrent tasks')
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2023-11-23 20:31:46 +00:00
|
|
|
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
|
|
|
|
2023-11-26 04:24:04 +00:00
|
|
|
root_dir = os.path.join(args.output, 'root')
|
|
|
|
os.makedirs(root_dir, exist_ok=True)
|
2023-11-01 21:02:39 +00:00
|
|
|
os.makedirs(args.output, exist_ok=True)
|
|
|
|
dns.resolver._DEFAULT_TIMEOUT = args.timeout
|
|
|
|
|
2023-11-23 20:31:46 +00:00
|
|
|
logging.info('Fetching root nameservers...')
|
2023-11-01 21:02:39 +00:00
|
|
|
with concurrent.futures.ThreadPoolExecutor(max_workers=args.concurrency) as executor:
|
2023-11-26 04:24:04 +00:00
|
|
|
futures = [executor.submit(attempt_axfr, '', root, os.path.join(args.output, f'root/{root}.txt')) for root in get_nameservers('.')]
|
2023-11-01 21:02:39 +00:00
|
|
|
for future in concurrent.futures.as_completed(futures):
|
|
|
|
try:
|
|
|
|
future.result()
|
|
|
|
except Exception as e:
|
2023-11-26 01:38:07 +00:00
|
|
|
logging.error(f'Error in TLD task: {e}')
|
2023-11-01 21:02:39 +00:00
|
|
|
|
2023-11-23 20:31:46 +00:00
|
|
|
logging.info('Fetching root TLDs...')
|
2023-11-01 21:02:39 +00:00
|
|
|
with concurrent.futures.ThreadPoolExecutor(max_workers=args.concurrency) as executor:
|
2023-11-26 04:24:04 +00:00
|
|
|
futures = [executor.submit(attempt_axfr, tld, ns, os.path.join(args.output, tld + '.txt')) for tld in get_root_tlds(root_dir) for ns in get_nameservers(tld) if ns]
|
2023-11-01 21:02:39 +00:00
|
|
|
for future in concurrent.futures.as_completed(futures):
|
|
|
|
try:
|
|
|
|
future.result()
|
|
|
|
except Exception as e:
|
|
|
|
logging.error(f'Error in TLD task: {e}')
|
|
|
|
|
2023-11-23 20:31:46 +00:00
|
|
|
logging.info('Fetching PSL TLDs...')
|
2023-11-04 05:54:58 +00:00
|
|
|
os.makedirs(os.path.join(args.output, 'psl'), exist_ok=True)
|
2023-11-01 21:02:39 +00:00
|
|
|
with concurrent.futures.ThreadPoolExecutor(max_workers=args.concurrency) as executor:
|
2023-11-04 05:54:58 +00:00
|
|
|
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]
|
2023-11-01 21:02:39 +00:00
|
|
|
for future in concurrent.futures.as_completed(futures):
|
|
|
|
try:
|
|
|
|
future.result()
|
|
|
|
except Exception as e:
|
2023-11-26 04:24:04 +00:00
|
|
|
logging.error(f'Error in TLD task: {e}')
|