> For the complete documentation index, see [llms.txt](https://alham-rizvi.gitbook.io/alhamrizvi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://alham-rizvi.gitbook.io/alhamrizvi/ethical-hacking/topic-4-dns-enumeration-and-domain-intelligence.md).

# Topic 4: DNS Enumeration and Domain Intelligence

### Simple Explanation

DNS (Domain Name System) is like the internet's phonebook — it converts human-friendly names (`google.com`) into computer-friendly IP addresses (`142.250....`). DNS Enumeration means digging through this "phonebook" to find every subdomain, mail server, and record related to a target, which reveals a lot about their infrastructure.

***

### 1. What is DNS?

A distributed, hierarchical naming system that translates domain names into IP addresses (and vice versa). Without DNS, you'd have to remember IP addresses for every website.

#### DNS Hierarchy

```
Root (.)
 └── Top-Level Domain (.com, .org, .in)
      └── Second-Level Domain (example.com)
           └── Subdomain (mail.example.com, www.example.com)
```

#### How DNS Resolution Works (step by step)

1. User types `www.example.com` in browser.
2. Browser checks local cache — if not found, asks the **Recursive Resolver** (usually the ISP's DNS server).
3. Resolver asks a **Root Server** → directed to the `.com` **TLD Server**.
4. TLD server directs to the **Authoritative Name Server** for `example.com`.
5. Authoritative server returns the actual IP address.
6. Resolver caches and returns the IP to the browser, which then connects to that IP.

### 2. DNS Record Types (must memorize for exams)

| Record Type | Full Name           | Purpose                                                                                                      |
| ----------- | ------------------- | ------------------------------------------------------------------------------------------------------------ |
| **A**       | Address Record      | Maps a hostname to an IPv4 address                                                                           |
| **AAAA**    | IPv6 Address Record | Maps a hostname to an IPv6 address                                                                           |
| **MX**      | Mail Exchange       | Specifies the mail server(s) for the domain, with priority values                                            |
| **NS**      | Name Server         | Specifies the authoritative DNS servers for the domain                                                       |
| **TXT**     | Text Record         | Holds arbitrary text — often used for SPF/DKIM (email verification), domain ownership verification           |
| **CNAME**   | Canonical Name      | Alias — points one domain name to another domain name                                                        |
| **SOA**     | Start of Authority  | Contains admin info about the domain (primary name server, admin email, refresh/retry timers, serial number) |
| **PTR**     | Pointer Record      | Used for reverse DNS lookup (IP → hostname)                                                                  |
| **SRV**     | Service Record      | Defines location (host+port) of specific services                                                            |

### 3. WHOIS Lookup

WHOIS is a protocol/database that stores registration details of a domain:

* Registrant name, organization, email, phone (may be hidden by privacy protection services)
* Registrar (company where domain was purchased, e.g., GoDaddy)
* Creation date, expiry date, last updated date
* Name servers

**Why attackers use it:** Reveals organizational details, admin contact emails (useful for social engineering/phishing), and infrastructure ownership.

**Regional Internet Registries (RIRs)** — manage IP address allocation regionally:

| RIR      | Region              |
| -------- | ------------------- |
| ARIN     | North America       |
| RIPE NCC | Europe, Middle East |
| APNIC    | Asia-Pacific        |
| LACNIC   | Latin America       |
| AFRINIC  | Africa              |

### 4. DNS Enumeration Techniques

DNS Enumeration = actively querying DNS servers to map out all the hostnames/subdomains/records of a target domain.

#### Methods:

1. **Zone Transfer (AXFR)** — a legitimate mechanism where a secondary DNS server copies the entire DNS zone (all records) from the primary server. If misconfigured to allow transfers to *anyone*, an attacker can dump the entire DNS database in one request. This is a classic, high-value misconfiguration to find.
   * Command example: `dig axfr @nameserver domain.com`
2. **Brute Force Subdomain Enumeration** — trying a wordlist of common subdomain names (`mail`, `ftp`, `dev`, `test`, `admin`) against the domain to see which resolve.
   * Tools: `dnsenum`, `Sublist3r`, `Fierce`, `Amass`
3. **Reverse DNS Lookup** — querying PTR records to find hostnames associated with a range of IP addresses.
4. **DNS Cache Snooping** — checking if a DNS resolver has cached a particular record, which can reveal if certain domains have recently been visited by users of that resolver.
5. **NSEC Walking** — for DNSSEC-signed zones, NSEC records (meant to prove non-existence of a record) can sometimes be "walked" to enumerate all names in a zone.

### 5. Common Tools for DNS Enumeration

| Tool        | Purpose                                                        |
| ----------- | -------------------------------------------------------------- |
| `nslookup`  | Basic DNS query tool (built into Windows/Linux)                |
| `dig`       | More detailed/flexible DNS query tool (Linux)                  |
| `host`      | Simple DNS lookup utility                                      |
| `dnsenum`   | Automated DNS enumeration (zone transfers, brute force, WHOIS) |
| `dnsrecon`  | Similar automated DNS recon tool                               |
| `Sublist3r` | Subdomain enumeration using search engines + brute force       |
| `Fierce`    | Domain scanner focused on finding non-contiguous IP space      |
| `Amass`     | Advanced attack surface mapping, subdomain enumeration         |

### 6. ARIN and Infrastructure Mapping

* **ARIN (American Registry for Internet Numbers)** database lets you search which organization owns a specific IP address block.
* Useful to map an organization's full public IP range once you know even one of their IPs.
* `whois` command can query ARIN directly: `whois <IP address>`

### 7. Example DNS Enumeration Workflow (Practical)

1. `whois example.com` → get registrar, name servers, admin contact.
2. `nslookup -type=NS example.com` → list authoritative name servers.
3. `nslookup -type=MX example.com` → find mail servers.
4. `dig axfr @ns1.example.com example.com` → attempt zone transfer (often blocked on well-configured servers, but worth checking).
5. `dnsenum example.com` or `sublist3r -d example.com` → brute-force/search for subdomains.
6. For each discovered subdomain, resolve its IP and note it for the next phase (scanning).

### 8. Security Implications of DNS Misconfiguration

* **Zone transfer allowed to anyone** → full infrastructure map leaked.
* **Subdomain takeover** — if a subdomain's CNAME points to a service (like a cloud storage bucket or SaaS platform) that's no longer claimed, an attacker can claim it and serve their own malicious content under your domain.
* **DNS Spoofing/Cache Poisoning** — attacker injects fake DNS responses to redirect users to malicious sites (related to MITM topic later).
* **DNS Amplification Attack** — a type of DDoS that abuses open DNS resolvers to flood a victim with traffic (covered more in the DoS topic).

### 9. Countermeasures

* Restrict zone transfers to only trusted secondary servers (`allow-transfer` config).
* Use DNSSEC to cryptographically sign DNS records, preventing spoofing.
* Regularly audit and remove unused subdomain CNAME records (prevents subdomain takeover).
* Rate-limit DNS resolvers to prevent amplification abuse.
* Use WHOIS privacy protection for domain registration info.

***

### Exam Points (Quick Revision)

* DNS record types: A, AAAA, MX, NS, TXT, CNAME, SOA, PTR, SRV — know what each does. **(Very frequently asked as MCQ/short answer)**
* Zone transfer (AXFR) misconfiguration = single biggest DNS enumeration risk.
* WHOIS reveals registrant, registrar, name servers, dates.
* RIRs: ARIN, RIPE NCC, APNIC, LACNIC, AFRINIC.
* Tools: nslookup, dig, dnsenum, Sublist3r, Fierce, Amass.
* Subdomain takeover = dangling CNAME pointing to unclaimed service.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://alham-rizvi.gitbook.io/alhamrizvi/ethical-hacking/topic-4-dns-enumeration-and-domain-intelligence.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
