# 53 - Pentesting DNS
☁️ HackTricks Cloud ☁️ -🐦 Twitter 🐦 - 🎙️ Twitch 🎙️ - 🎥 Youtube 🎥 * Do you work in a **cybersecurity company**? Do you want to see your **company advertised in HackTricks**? or do you want to have access to the **latest version of the PEASS or download HackTricks in PDF**? Check the [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)! * Discover [**The PEASS Family**](https://opensea.io/collection/the-peass-family), our collection of exclusive [**NFTs**](https://opensea.io/collection/the-peass-family) * Get the [**official PEASS & HackTricks swag**](https://peass.creator-spring.com) * **Join the** [**💬**](https://emojipedia.org/speech-balloon/) [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** me on **Twitter** [**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks\_live)**.** * **Share your hacking tricks by submitting PRs to the** [**hacktricks repo**](https://github.com/carlospolop/hacktricks) **and** [**hacktricks-cloud repo**](https://github.com/carlospolop/hacktricks-cloud).
[**DragonJAR Security Conference es un evento internacional de ciberseguridad**](https://www.dragonjarcon.org/) con más de una década que se celebrará el 7 y 8 de septiembre de 2023 en Bogotá, Colombia. Es un evento de gran contenido técnico donde se presentan las últimas investigaciones en español que atrae a hackers e investigadores de todo el mundo.\ ¡Regístrate ahora en el siguiente enlace y no te pierdas esta gran conferencia!: {% embed url="https://www.dragonjarcon.org/" %} ## **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. DNS translates domain names to [IP addresses](https://www.cloudflare.com/learning/dns/glossary/what-is-my-ip-address/) so browsers can load Internet resources.\ From [here](https://www.cloudflare.com/learning/dns/what-is-dns/). **Default port:** 53 ``` PORT STATE SERVICE REASON 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 Information from [https://academy.hackthebox.com/module/112/section/1069](https://academy.hackthebox.com/module/112/section/1069) | **Server Type** | **Description** | | ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `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](https://www.icann.org/) (`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. | | `Resolver` | Resolvers are not authoritative DNS servers but perform name resolution locally in the computer or router. | ## Enumeration ### **Banner Grabbing** 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`: ```bash 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`](https://github.com/kirei/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**. ```bash dig any victim.com @ ``` ### **Zone Transfer** This procedure is abbreviated `Asynchronous Full Transfer Zone` (`AXFR`). ```bash dig axfr @ #Try zone transfer without domain dig axfr @ #Try zone transfer guessing the domain fierce --domain --dns-servers #Will try toperform a zone transfer against every authoritative name server and if this doesn'twork, will launch a dictionary attack ``` ### More info ```bash dig ANY @ #Any information dig A @ #Regular DNS request dig AAAA @ #IPv6 DNS request dig TXT @ #Information dig MX @ #Emails related dig NS @ #DNS that resolves that name dig -x 192.168.0.2 @ #Reverse lookup dig -x 2a00:1450:400c:c06::93 @ #reverse IPv6 lookup #Use [-p PORT] or -6 (to use ivp6 address of dns) ``` #### Using nslookup ```bash nslookup > SERVER #Select dns server > 127.0.0.1 #Reverse lookup of 127.0.0.1, maybe... > #Reverse lookup of a machine, maybe... ``` ### Useful metasploit modules ```bash auxiliary/gather/enum_dns #Perform enumeration actions ``` ### Useful nmap scripts ```bash #Perform enumeration actions nmap -n --script "(default and *dns*) or fcrdns or dns-srv-enum or dns-random-txid or dns-random-srcport" ``` ### DNS - Reverse BF ```bash dnsrecon -r 127.0.0.0/24 -n #DNS reverse of all of the addresses dnsrecon -r 127.0.1.0/24 -n #DNS reverse of all of the addresses dnsrecon -r /24 -n #DNS reverse of all of the addresses dnsrecon -d active.htb -a -n #Zone transfer ``` {% hint style="info" %} 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. {% endhint %} Another tool to do so: [https://github.com/amine7536/reverse-scan](https://github.com/amine7536/reverse-scan) You can query reverse IP ranges to [https://bgp.he.net/net/205.166.76.0/24#\_dns](https://bgp.he.net/net/205.166.76.0/24#\_dns) (this tool is also helpful with BGP). ### DNS - Subdomains BF ```bash dnsenum --dnsserver --enum -p 0 -s 0 -o subdomains.txt -f subdomains-1000.txt dnsrecon -D subdomains-1000.txt -d -n dnscan -d -r -w subdomains-1000.txt #Bruteforce subdomains in recursive way, https://github.com/rbsec/dnscan ``` ### Active Directory servers ``` dig -t _gc._tcp.lab.domain.com dig -t _ldap._tcp.lab.domain.com dig -t _kerberos._tcp.lab.domain.com dig -t _kpasswd._tcp.lab.domain.com nmap --script dns-srv-enum --script-args "dns-srv-enum.domain='domain.com'" ``` ### DNSSec ```bash #Query paypal subdomains to ns3.isc-sns.info nmap -sSU -p53 --script dns-nsec-enum --script-args dns-nsec-enum.domains=paypal.com ns3.isc-sns.info ``` ### IPv6 Brute force using "AAAA" requests to gather IPv6 of the subdomains. ```bash dnsdict6 -s -t ``` Bruteforce reverse DNS in using IPv6 addresses ```bash dnsrevenum6 pri.authdns.ripe.net 2001:67c:2e8::/48 #Will use the dns pri.authdns.ripe.net ``` ### 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: ```bash dig google.com A @ ``` **Non available**: ![](<../.gitbook/assets/image (275).png>) **Available**: ![](<../.gitbook/assets/image (276).png>)
[**DragonJAR Security Conference es un evento internacional de ciberseguridad**](https://www.dragonjarcon.org/) con más de una década que se celebrará el 7 y 8 de septiembre de 2023 en Bogotá, Colombia. Es un evento de gran contenido técnico donde se presentan las últimas investigaciones en español que atrae a hackers e investigadores de todo el mundo.\ ¡Regístrate ahora en el siguiente enlace y no te pierdas esta gran conferencia!: {% embed url="https://www.dragonjarcon.org/" %} ### 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: noa.nintendo.com blah@nintendo.com #550 5.1.1 RESOLVER.ADR.RecipNotFound; not found ## Original message headers: Received: from ONERDEDGE02.one.nintendo.com (10.13.20.35) by onerdexch08.one.nintendo.com (10.13.30.39) with Microsoft SMTP Server (TLS) id 14.3.174.1; Sat, 26 Apr 2014 16:52:22 -0700 Received: from barracuda.noa.nintendo.com (205.166.76.35) by ONERDEDGE02.one.nintendo.com (10.13.20.35) with Microsoft SMTP Server (TLS) id 14.3.174.1; Sat, 26 Apr 2014 16:51:22 -0700 X-ASG-Debug-ID: 1398556333-0614671716199b0d0001-zOQ9WJ Received: from gateway05.websitewelcome.com (gateway05.websitewelcome.com [69.93.154.37]) by barracuda.noa.nintendo.com with ESMTP id xVNPkwaqGgdyH5Ag for ; Sat, 26 Apr 2014 16:52:13 -0700 (PDT) X-Barracuda-Envelope-From: chris@example.org X-Barracuda-Apparent-Source-IP: 69.93.154.37 ``` 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 ``` host.conf /etc/resolv.conf /etc/bind/named.conf /etc/bind/named.conf.local /etc/bind/named.conf.options /etc/bind/named.conf.log /etc/bind/* ``` Dangerous settings when configuring a Bind server: | **Option** | **Description** | | ----------------- | ------------------------------------------------------------------------------ | | `allow-query` | Defines which hosts are allowed to send requests to the DNS server. | | `allow-recursion` | Defines which hosts are allowed to send recursive requests to the DNS server. | | `allow-transfer` | Defines which hosts are allowed to receive zone transfers from the DNS server. | | `zone-statistics` | 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 Entry_1: Name: Notes Description: Notes for DNS Note: | #These are the commands I run every time I see an open DNS port dnsrecon -r 127.0.0.0/24 -n {IP} -d {Domain_Name} dnsrecon -r 127.0.1.0/24 -n {IP} -d {Domain_Name} dnsrecon -r {Network}{CIDR} -n {IP} -d {Domain_Name} dig axfr @{IP} dig axfr {Domain_Name} @{IP} nslookup SERVER {IP} 127.0.0.1 {IP} Domain_Name exit https://book.hacktricks.xyz/pentesting/pentesting-dns Entry_2: Name: Banner Grab Description: Grab DNS Banner Command: dig version.bind CHAOS TXT @DNS Entry_3: 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} Entry_4: Name: Zone Transfer Description: Three attempts at forcing a zone transfer Command: dig axfr @{IP} && dix axfr @{IP} {Domain_Name} && fierce --dns-servers {IP} --domain {Domain_Name} Entry_5: 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}" Entry_6: Name: consolesless mfs enumeration Description: DNS enumeration without the need to run msfconsole Note: sourced from https://github.com/carlospolop/legion 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' ```
[**DragonJAR Security Conference es un evento internacional de ciberseguridad**](https://www.dragonjarcon.org/) con más de una década que se celebrará el 7 y 8 de septiembre de 2023 en Bogotá, Colombia. Es un evento de gran contenido técnico donde se presentan las últimas investigaciones en español que atrae a hackers e investigadores de todo el mundo.\ ¡Regístrate ahora en el siguiente enlace y no te pierdas esta gran conferencia!: {% embed url="https://www.dragonjarcon.org/" %}
☁️ HackTricks Cloud ☁️ -🐦 Twitter 🐦 - 🎙️ Twitch 🎙️ - 🎥 Youtube 🎥 * Do you work in a **cybersecurity company**? Do you want to see your **company advertised in HackTricks**? or do you want to have access to the **latest version of the PEASS or download HackTricks in PDF**? Check the [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)! * Discover [**The PEASS Family**](https://opensea.io/collection/the-peass-family), our collection of exclusive [**NFTs**](https://opensea.io/collection/the-peass-family) * Get the [**official PEASS & HackTricks swag**](https://peass.creator-spring.com) * **Join the** [**💬**](https://emojipedia.org/speech-balloon/) [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** me on **Twitter** [**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks\_live)**.** * **Share your hacking tricks by submitting PRs to the** [**hacktricks repo**](https://github.com/carlospolop/hacktricks) **and** [**hacktricks-cloud repo**](https://github.com/carlospolop/hacktricks-cloud).