-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
dns_enumeration.py
63 lines (53 loc) · 2.04 KB
/
dns_enumeration.py
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
import socket
import dns.resolver
R = '\033[31m' # red
G = '\033[32m' # green
C = '\033[36m' # cyan
W = '\033[0m' # white
Y = '\033[33m' # yellow
def get_domain_ip(domain):
try:
ip_address = socket.gethostbyname(domain)
print(f"{G}[+] {C}IP Address:{W} {ip_address}")
return ip_address
except socket.gaierror:
print(f"{R}[-] {C}Could not resolve IP address for the domain.{W}")
return None
def dnsrec(domain):
ip_address = get_domain_ip(domain)
if ip_address:
result = {'dns': [], 'dmarc': []}
print(f'\n{Y}[~] Starting DNS Enumeration...{W}\n')
types = ['A', 'AAAA', 'CAA', 'CNAME', 'MX', 'NS', 'TXT']
# Set a timeout value in seconds
timeout = 10
resolver = dns.resolver.Resolver()
resolver.nameservers = ['8.8.8.8']
resolver.timeout = timeout
resolver.lifetime = timeout
for record_type in types:
try:
response = resolver.query(domain, record_type)
for answer in response:
print(f'{G}[+] {C}{record_type}:{W} {answer}')
result['dns'].append(f'{record_type}: {answer}')
except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer, dns.resolver.Timeout):
pass
dmarc_target = f'_dmarc.{domain}'
try:
dmarc_response = resolver.query(dmarc_target, 'TXT')
for answer in dmarc_response:
print(f'{G}[+] {C}DMARC:{W} {answer}')
result['dmarc'].append(f'DMARC: {answer}')
except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer, dns.resolver.Timeout):
pass
if result['dns'] or result['dmarc']:
result['exported'] = True
else:
print(f'\n{R}[-] {C}No DNS Records or DMARC Record Found!{W}')
result['exported'] = False
return result
if __name__ == "__main__":
target_domain = input("Enter the domain to perform DNS enumeration: ")
result = dnsrec(target_domain)
print(result)