HackTricks
Search…
Pentesting
Powered By GitBook
53 - Pentesting DNS

Basic Information

The Domain Name Systems (DNS) is the phonebook of the Internet. Humans access information online through domain names, like nytimes.com or espn.com. Web browsers interact through Internet Protocol (IP) addresses. DN S translates domain names to IP addresses so browsers can load Internet resources. From here.
Default port: 53
1
PORT STATE SERVICE REASON
2
53/tcp open domain Microsoft DNS 6.1.7601 (1DB15D39) (Windows Server 2008 R2 SP1)
3
5353/udp open zeroconf udp-response
4
53/udp open domain Microsoft DNS 6.1.7601 (1DB15D39) (Windows Server 2008 R2 SP1)
Copied!

Enumeration

DNS does not have a "banner" to grab. The closest equivalent is a magic query for version.bind. CHAOS TXT which will work on most BIND nameservers. You can perform this query using dig:
1
dig version.bind CHAOS TXT @DNS
Copied!
If that does not work you can use fingerprinting techniques to determine the remote server's version -- the fpdns tool is one option for that, but there are others.
You can grab the banner also with a nmap script:
1
--script dns-nsid
Copied!

Zone Transfer

1
dig axfr @<DNS_IP> #Try zone transfer without domain
2
dig axfr @<DNS_IP> <DOMAIN> #Try zone transfer guessing the domain
3
fierce --domain <DOMAIN> --dns-servers <DNS_IP> #Will try toperform a zone transfer against every authoritative name server and if this doesn'twork, will launch a dictionary attack
Copied!

More info

1
dig ANY @<DNS_IP> <DOMAIN> #Any information
2
dig A @<DNS_IP> <DOMAIN> #Regular DNS request
3
dig AAAA @<DNS_IP> <DOMAIN> #IPv6 DNS request
4
dig TXT @<DNS_IP> <DOMAIN> #Information
5
dig MX @<DNS_IP> <DOMAIN> #Emails related
6
dig NS @<DNS_IP> <DOMAIN> #DNS that resolves that name
7
dig -x 192.168.0.2 @<DNS_IP> #Reverse lookup
8
dig -x 2a00:1450:400c:c06::93 @<DNS_IP> #reverse IPv6 lookup
9
10
#Use [-p PORT] or -6 (to use ivp6 address of dns)
Copied!

Using nslookup

1
nslookup
2
> SERVER <IP_DNS> #Select dns server
3
> 127.0.0.1 #Reverse lookup of 127.0.0.1, maybe...
4
> <IP_MACHINE> #Reverse lookup of a machine, maybe...
Copied!

Useful metasploit modules

1
auxiliary/gather/enum_dns #Perform enumeration actions
Copied!

Useful nmap scripts

1
#Perform enumeration actions
2
nmap -n --script "(default and *dns*) or fcrdns or dns-srv-enum or dns-random-txid or dns-random-srcport" <IP>
Copied!

DNS - Reverse BF

1
dnsrecon -r 127.0.0.0/24 -n <IP_DNS> #DNS reverse of all of the addresses
2
dnsrecon -r 127.0.1.0/24 -n <IP_DNS> #DNS reverse of all of the addresses
3
dnsrecon -r <IP_DNS>/24 -n <IP_DNS> #DNS reverse of all of the addresses
4
dnsrecon -d active.htb -a -n <IP_DNS> #Zone transfer
Copied!
If you are able to find subdomains resolving to internal IP-addresses, you should try to perform a reverse dns BF to the NSs of the domain asking for that IP range.
You can query reverse IP ranges to https://bgp.he.net/net/205.166.76.0/24#_dns (this tool is also helpful with BGP).

DNS - Subdomains BF

1
dnsrecon -D subdomains-1000.txt -d <DOMAIN> -n <IP_DNS>
2
dnscan -d <domain> -r -w subdomains-1000.txt #Bruteforce subdomains in recursive way, https://github.com/rbsec/dnscan
Copied!

Active Directory servers

1
dig -t _gc._tcp.lab.domain.com
2
dig -t _ldap._tcp.lab.domain.com
3
dig -t _kerberos._tcp.lab.domain.com
4
dig -t _kpasswd._tcp.lab.domain.com
5
nmap --script dns-srv-enum --script-args "dns-srv-enum.domain='domain.com'"
Copied!

DNSSec

1
#Query paypal subdomains to ns3.isc-sns.info
2
nmap -sSU -p53 --script dns-nsec-enum --script-args dns-nsec-enum.domains=paypal.com ns3.isc-sns.info
Copied!

IPv6

Brute force using "AAAA" requests to gather IPv6 of the subdomains.
1
dnsdict6 -s -t <domain>
Copied!
Bruteforce reverse DNS in using IPv6 addresses
1
dnsrevenum6 pri.authdns.ripe.net 2001:67c:2e8::/48 #Will use the dns pri.authdns.ripe.net
Copied!

DNS Recursion DDoS

If DNS recursion is enabled, an attacker could spoof the origin on the UDP packet in order to make the DNS send the response to the victim server. An attacker could abuse ANY or DNSSEC record types as they use to have the bigger responses. The way to check if a DNS supports recursion is to query a domain name and check if the flag "ra" (recursion available) is in the response:
1
dig google.com A @<IP>
Copied!
Non available:
Available:

Mail to nonexistent account

From book: Network Security Assessment (3rd edition)
Simply sending an email message to a nonexistent address at a target domain often reveals useful internal network information through a nondelivery notification (NDN).
1
Generating server: noa.nintendo.com
2
4
#550 5.1.1 RESOLVER.ADR.RecipNotFound; not found ##
5
6
Original message headers:
7
8
Received: from ONERDEDGE02.one.nintendo.com (10.13.20.35) by
9
onerdexch08.one.nintendo.com (10.13.30.39) with Microsoft SMTP Server (TLS)
10
id 14.3.174.1; Sat, 26 Apr 2014 16:52:22 -0700
11
Received: from barracuda.noa.nintendo.com (205.166.76.35) by
12
ONERDEDGE02.one.nintendo.com (10.13.20.35) with Microsoft SMTP Server (TLS)
13
id 14.3.174.1; Sat, 26 Apr 2014 16:51:22 -0700
14
X-ASG-Debug-ID: 1398556333-0614671716199b0d0001-zOQ9WJ
15
Received: from gateway05.websitewelcome.com (gateway05.websitewelcome.com [69.93.154.37]) by
16
barracuda.noa.nintendo.com with ESMTP id xVNPkwaqGgdyH5Ag for <[email protected]>; Sat,
17
26 Apr 2014 16:52:13 -0700 (PDT)
18
X-Barracuda-Envelope-From: [email protected]
19
X-Barracuda-Apparent-Source-IP: 69.93.154.37
Copied!
The following data in this transcript is useful:
    Internal hostnames, IP addresses, and subdomain layout
    The mail server is running Microsoft Exchange Server 2010 SP3
    A Barracuda Networks device is used to perform content filtering

Config files

1
host.conf
2
resolv.conf
3
named.conf
Copied!

HackTricks Automatic Commands

1
Protocol_Name: DNS #Protocol Abbreviation if there is one.
2
Port_Number: 53 #Comma separated if there is more than one.
3
Protocol_Description: Domain Name Service #Protocol Abbreviation Spelled out
4
5
Entry_1:
6
Name: Notes
7
Description: Notes for DNS
8
Note: |
9
#These are the commands I run every time I see an open DNS port
10
11
dnsrecon -r 127.0.0.0/24 -n {IP} -d {Domain_Name}
12
dnsrecon -r 127.0.1.0/24 -n {IP} -d {Domain_Name}
13
dnsrecon -r {Network}{CIDR} -n {IP} -d {Domain_Name}
14
dig axfr @{IP}
15
dig axfr {Domain_Name} @{IP}
16
nslookup
17
SERVER {IP}
18
127.0.0.1
19
{IP}
20
Domain_Name
21
exit
22
23
https://book.hacktricks.xyz/pentesting/pentesting-dns
24
25
Entry_2:
26
Name: Banner Grab
27
Description: Grab DNS Banner
28
Command: dig version.bind CHAOS TXT @DNS
29
30
Entry_3:
31
Name: Nmap Vuln Scan
32
Description: Scan for Vulnerabilities with Nmap
33
Command: nmap -n --script "(default and *dns*) or fcrdns or dns-srv-enum or dns-random-txid or dns-random-srcport" {IP}
34
35
Entry_4:
36
Name: Zone Transfer
37
Description: Three attempts at forcing a zone transfer
38
Command: dig axfr @{IP} && dix axfr @{IP} {Domain_Name} && fierce -dns {Domain_Name}
39
40
Entry_5:
41
Name: Active Directory
42
Description: Eunuerate a DC via DNS
43
Command: dig -t _gc._{Domain_Name} && dig -t _ldap._{Domain_Name} && dig -t _kerberos._{Domain_Name} && dig -t _kpasswd._{Domain_Name} && nmap --script dns-srv-enum --script-args "dns-srv-enum.domain={Domain_Name}"
Copied!
Last modified 2mo ago