POSIX version now attempts IPv4 & IPv6, Python & POSIX version now correctly attempts every IP beloging to the nameserver

This commit is contained in:
Dionysus 2023-11-23 14:16:35 -05:00
parent 03c09942fe
commit b73cc90d52
Signed by: acidvegas
GPG Key ID: EF4B922DB85DC9DE
3 changed files with 25 additions and 20 deletions

View File

@ -16,7 +16,7 @@ It is expected to set *realistic* expectations when using this tool. In contempo
| `-t`, `--timeout` | DNS timeout *(default: 30)* | | `-t`, `--timeout` | DNS timeout *(default: 30)* |
## Information ## Information
I only wrote this to shit on **[this bozo](https://github.com/flotwig/TLDR-2/tree/main)** who took a dead project & brought it back to life by making it even worse. Rather than making a pull request to give this bloke more credit in his "tenure" as a developer, I decided to just rewrite it all from scratch so people can fork off of *clean* code instead. I only wrote this to shit on **[this bozo](https://github.com/flotwig/TLDR-2/)** who took a dead project & brought it back to life by making it even worse. Rather than making a pull request to give this bloke more credit in his "tenure" as a developer, I decided to just rewrite it all from scratch so people can fork off of *clean* code instead.
This repostiory also contains a [pure POSIX version](./mdaxfr) for portability, aswell as a [script](./opennic) to do zone transfers on [OpenNIC TLDs](https://wiki.opennic.org/opennic/dot). This repostiory also contains a [pure POSIX version](./mdaxfr) for portability, aswell as a [script](./opennic) to do zone transfers on [OpenNIC TLDs](https://wiki.opennic.org/opennic/dot).

9
mdaxfr
View File

@ -7,7 +7,7 @@ mkdir -p "$OUTPUT_DIR/root"
mkdir -p "$OUTPUT_DIR/psl" mkdir -p "$OUTPUT_DIR/psl"
resolve_nameserver() { resolve_nameserver() {
dig +short "$1" A || dig +short "$1" AAAA dig +short AAAA $1 +short -t A $1 2>/dev/null
} }
attempt_axfr() { attempt_axfr() {
@ -16,19 +16,22 @@ attempt_axfr() {
filename="$3" filename="$3"
temp_file="${filename}.temp" temp_file="${filename}.temp"
nameserver_ip=$(resolve_nameserver "$nameserver") nameserver_ips=$(resolve_nameserver "$nameserver")
if [ -z "$nameserver_ip" ]; then if [ -z "$nameserver_ips" ]; then
echo "Failed to resolve nameserver $nameserver" echo "Failed to resolve nameserver $nameserver"
return return
fi fi
for nameserver_ip in $nameserver_ips; do
dig AXFR "$tld" "@$nameserver_ip" > "$temp_file" dig AXFR "$tld" "@$nameserver_ip" > "$temp_file"
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
mv "$temp_file" "$filename" mv "$temp_file" "$filename"
return
else else
echo "Failed to perform zone transfer from $nameserver for $tld" echo "Failed to perform zone transfer from $nameserver for $tld"
rm -f "$temp_file" rm -f "$temp_file"
fi fi
done
} }
# For root nameservers # For root nameservers

View File

@ -29,17 +29,19 @@ def attempt_axfr(tld: str, nameserver: str, filename: str):
else: else:
for ns in nameserver: # Let's try all the IP addresses for the nameserver for ns in nameserver: # Let's try all the IP addresses for the nameserver
try: try:
xfr = dns.query.xfr(ns, tld+'.', lifetime=300)
if xfr:
with open(temp_file, 'w') as file: with open(temp_file, 'w') as file:
xfr = dns.query.xfr(nameserver.address, tld+'.', lifetime=300)
for msg in xfr: for msg in xfr:
for rrset in msg.answer: for rrset in msg.answer:
for rdata in rrset: for rdata in rrset:
file.write(f'{rrset.name}.{tld} {rrset.ttl} {rdata}\n') file.write(f'{rrset.name}.{tld} {rrset.ttl} {rdata}\n')
os.rename(temp_file, filename) os.rename(temp_file, filename)
break
except Exception as ex: except Exception as ex:
if os.path.exists(temp_file): if os.path.exists(temp_file):
os.remove(temp_file) os.remove(temp_file)
logging.error(f'Failed to perform zone transfer from {nameserver.address} for {tld}: {ex}') logging.error(f'Failed to perform zone transfer from {nameserver} ({ns}) for {tld}: {ex}')
def get_nameservers(target: str) -> list: def get_nameservers(target: str) -> list:
@ -109,7 +111,7 @@ if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Mass DNS AXFR') parser = argparse.ArgumentParser(description='Mass DNS AXFR')
parser.add_argument('-c', '--concurrency', type=int, default=30, help='maximum concurrent tasks') parser.add_argument('-c', '--concurrency', type=int, default=30, help='maximum concurrent tasks')
parser.add_argument('-o', '--output', default='axfrout', help='output directory') parser.add_argument('-o', '--output', default='axfrout', help='output directory')
parser.add_argument('-t', '--timeout', type=int, default=30, help='DNS timeout (default: 30)') parser.add_argument('-t', '--timeout', type=int, default=15, help='DNS timeout (default: 15)')
args = parser.parse_args() args = parser.parse_args()
os.makedirs(args.output, exist_ok=True) os.makedirs(args.output, exist_ok=True)