53 - Pentesting DNS

Basic Information

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

Different DNS Servers

Server Type
DNS Root Server
The root servers of the DNS are responsible for the top-level domains (TLD). As the last instance, they are only requested if the name server does not respond. Thus, a root server is a central interface between users and content on the Internet, as it links domain and IP address. The Internet Corporation for Assigned Names and Numbers (ICANN) coordinates the work of the root name servers. There are 13 such root servers around the globe.
Authoritative Nameserver
Authoritative name servers hold authority for a particular zone. They only answer queries from their area of responsibility, and their information is binding. If an authoritative name server cannot answer a client's query, the root name server takes over at that point.
Non-authoritative Nameserver
Non-authoritative name servers are not responsible for a particular DNS zone. Instead, they collect information on specific DNS zones themselves, which is done using recursive or iterative DNS querying.
Caching DNS Server
Caching DNS servers cache information from other name servers for a specified period. The authoritative name server determines the duration of this storage.
Forwarding Server
Forwarding servers perform only one function: they forward DNS queries to another DNS server.
Resolvers are not authoritative DNS servers but perform name resolution locally in the computer or router.


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:
dig version.bind CHAOS TXT @DNS
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:
--script dns-nsid

Any record

The record ANY will ask the DNS server to return all the available entries that it is willing to disclose.
dig any @<DNS_IP>

Zone Transfer

This procedure is abbreviated Asynchronous Full Transfer Zone (AXFR).
dig axfr @<DNS_IP> #Try zone transfer without domain
dig axfr @<DNS_IP> <DOMAIN> #Try zone transfer guessing the domain
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

More info

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

Using nslookup

> SERVER <IP_DNS> #Select dns server
> #Reverse lookup of, maybe...
> <IP_MACHINE> #Reverse lookup of a machine, maybe...

Useful metasploit modules

auxiliary/gather/enum_dns #Perform enumeration actions

Useful nmap scripts

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

DNS - Reverse BF

dnsrecon -r -n <IP_DNS> #DNS reverse of all of the addresses
dnsrecon -r -n <IP_DNS> #DNS reverse of all of the addresses
dnsrecon -r <IP_DNS>/24 -n <IP_DNS> #DNS reverse of all of the addresses
dnsrecon -d active.htb -a -n <IP_DNS> #Zone transfer
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 (this tool is also helpful with BGP).

DNS - Subdomains BF

dnsenum --dnsserver <IP_DNS> --enum -p 0 -s 0 -o subdomains.txt -f subdomains-1000.txt <DOMAIN>
dnsrecon -D subdomains-1000.txt -d <DOMAIN> -n <IP_DNS>
dnscan -d <domain> -r -w subdomains-1000.txt #Bruteforce subdomains in recursive way,

Active Directory servers

dig -t
dig -t
dig -t
dig -t
nmap --script dns-srv-enum --script-args "dns-srv-enum.domain=''"


#Query paypal subdomains to
nmap -sSU -p53 --script dns-nsec-enum --script-args


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

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:
dig A @<IP>
Non 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).
Generating server:
#550 5.1.1 RESOLVER.ADR.RecipNotFound; not found ##
Original message headers:
Received: from ( by ( with Microsoft SMTP Server (TLS)
id; Sat, 26 Apr 2014 16:52:22 -0700
Received: from ( by ( with Microsoft SMTP Server (TLS)
id; Sat, 26 Apr 2014 16:51:22 -0700
X-ASG-Debug-ID: 1398556333-0614671716199b0d0001-zOQ9WJ
Received: from ( []) by with ESMTP id xVNPkwaqGgdyH5Ag for <[email protected]>; Sat,
26 Apr 2014 16:52:13 -0700 (PDT)
X-Barracuda-Envelope-From: [email protected]
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

Dangerous settings when configuring a Bind server:
Defines which hosts are allowed to send requests to the DNS server.
Defines which hosts are allowed to send recursive requests to the DNS server.
Defines which hosts are allowed to receive zone transfers from the DNS server.
Collects statistical data of zones.

HackTricks Automatic Commands

Protocol_Name: DNS #Protocol Abbreviation if there is one.
Port_Number: 53 #Comma separated if there is more than one.
Protocol_Description: Domain Name Service #Protocol Abbreviation Spelled out
Name: Notes
Description: Notes for DNS
Note: |
#These are the commands I run every time I see an open DNS port
dnsrecon -r -n {IP} -d {Domain_Name}
dnsrecon -r -n {IP} -d {Domain_Name}
dnsrecon -r {Network}{CIDR} -n {IP} -d {Domain_Name}
dig axfr @{IP}
dig axfr {Domain_Name} @{IP}
Name: Banner Grab
Description: Grab DNS Banner
Command: dig version.bind CHAOS TXT @DNS
Name: Nmap Vuln Scan
Description: Scan for Vulnerabilities with Nmap
Command: nmap -n --script "(default and *dns*) or fcrdns or dns-srv-enum or dns-random-txid or dns-random-srcport" {IP}
Name: Zone Transfer
Description: Three attempts at forcing a zone transfer
Command: dig axfr @{IP} && dix axfr @{IP} {Domain_Name} && fierce -dns {Domain_Name}
Name: Active Directory
Description: Eunuerate a DC via DNS
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}"
Name: consolesless mfs enumeration
Description: DNS enumeration without the need to run msfconsole
Note: sourced from
Command: msfconsole -q -x 'use auxiliary/scanner/dns/dns_amp; set RHOSTS {IP}; set RPORT 53; run; exit' && msfconsole -q -x 'use auxiliary/gather/enum_dns; set RHOSTS {IP}; set RPORT 53; run; exit'