-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
89 lines (67 loc) · 2.6 KB
/
main.py
File metadata and controls
89 lines (67 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python3
# Dependencies:
# python3-dnspython
# Used Modules:
import dns.zone as dz
import dns.query as dq
import dns.resolver as dr
import argparse
# Initialize Resolver-Class from dns.resolver as "NS"
NS = dr.Resolver()
# List of found subdomains
Subdomains = []
# Define the AXFR Function
def AXFR(domain, nameserver):
# Try zone transfer for given domain and nameserver
try:
# Perform the zone transfer
axfr = dz.from_xfr(dq.xfr(nameserver, domain))
# If zone transfer was successful
if axfr:
print('[*] Successful Zone Transfer from {}'.format(nameserver))
# Add found subdomains to global 'Subdomain' list
for record in axfr:
Subdomains.append('{}.{}'.format(record.to_text(), domain))
# If zone transfer fails
except Exception as error:
print(error)
pass
# Main
if __name__ == "__main__":
# ArgParser - Define usage
parser = argparse.ArgumentParser(prog="dns-axfr.py", epilog="DNS Zonetransfer Script", usage="dns-axfr.py [options] -d <DOMAIN>", prefix_chars='-', add_help=True)
# Positional Arguments
parser.add_argument('-d', action='store', metavar='Domain', type=str, help='Target Domain.\tExample: inlanefreight.htb', required=True)
parser.add_argument('-n', action='store', metavar='Nameserver', type=str, help='Nameservers separated by a comma.\tExample: ns1.inlanefreight.htb,ns2.inlanefreight.htb')
parser.add_argument('-v', action='version', version='DNS-AXFR - v1.0', help='Prints the version of DNS-AXFR.py')
# Assign given arguments
args = parser.parse_args()
# Check if URL is given
if not args.d:
print('[!] You must specify target Domain.\n')
print(parser.print_help())
exit()
if not args.n:
print('[!] You must specify target nameservers.\n')
print(parser.print_help())
exit()
# Variables
num_subs = 0
Domain = args.d
NS.nameservers = list(args.n.split(","))
# For each nameserver
for nameserver in NS.nameservers:
# Try AXFR
AXFR(Domain, nameserver)
# Print the results
if Subdomains is not None:
print('-------- Found Subdomains:')
# Print each subdomain
for subdomain in Subdomains:
num_subs =+ 1
print('{}'.format(subdomain))
else:
print('No subdomains found.')
exit()
print(f"Number of Subdomains:{num_subs}")
exit()