DNS Enumeration
Table of Contents
- Introduction to DNS
- DNS Record Types
- dig Command Deep Dive
- nslookup Usage
- DNS Zone Transfer (AXFR)
- DNSSEC Overview
- DNS Caching and Recon Impact
- DNS-Based Subdomain Discovery
- Common DNS Misconfigurations
- Attack Chain Position
- OSCP Exam Tips
Introduction to DNS
What is DNS?
DNS (Domain Name System) is the distributed database that translates human-readable domain names into machine-readable IP addresses. It is one of the most critical infrastructure components on the internet and a rich source of information for penetration testers.
Why DNS Matters for Penetration Testing
DNS enumeration is valuable because it reveals:
| Information Type | Description | Attack Value |
|---|---|---|
| Infrastructure | Servers, services, and their locations | Identifies attack targets |
| Internal Structure | Subdomains and internal naming conventions | Reveals organizational structure |
| Service Relationships | How services relate to each other | Maps attack paths |
| Email Infrastructure | Mail servers and email configuration | Enables email-based attacks |
| Hosting Information | Where services are hosted | Identifies hosting providers |
| Administrative Contacts | DNS admin information | Enables social engineering |
| Network Ranges | IP ranges used by the organization | Expands attack surface |
DNS Architecture
flowchart TD
A[Client Query] --> B[Local DNS Resolver]
B --> C{Cache Hit?}
C -->|Yes| D[Return Cached Result]
C -->|No| E[Root Name Server]
E --> F[TLD Name Server]
F --> G[Authoritative Name Server]
G --> H[Response to Resolver]
H --> B
B --> D
D --> A
style A fill:#ff6b6b,stroke:#333,stroke-width:2px
style G fill:#4ecdc4,stroke:#333,stroke-width:2px
DNS Query Types
| Query Type | Description | Use Case |
|---|---|---|
| Recursive | Resolver does all the work | Client queries |
| Iterative | Resolver asks each server in turn | Resolver queries |
| Non-recursive | Single server response | Authoritative queries |
| Reverse | IP to domain name | Reverse DNS lookups |
DNS Record Types
Understanding DNS record types is fundamental to effective DNS enumeration. Each record type serves a specific purpose and can reveal different types of information.
A Record (Address Record)
Purpose: Maps a domain name to an IPv4 address.
Format: name IN A ipv4_address
Example:
target.com. 300 IN A 10.10.10.1
Attack Relevance:
- Identifies the IP addresses of target servers
- Reveals hosting infrastructure
- Helps map the target’s network topology
- Multiple A records indicate load balancing or redundancy
Enumeration:
# Query A records
dig target.com A
# Query A records (short output)
dig target.com A +short
# Query A records for subdomain
dig www.target.com A
AAAA Record (IPv6 Address Record)
Purpose: Maps a domain name to an IPv6 address.
Format: name IN AAAA ipv6_address
Example:
target.com. 300 IN AAAA 2001:db8::1
Attack Relevance:
- Reveals IPv6 infrastructure
- May expose services not available on IPv4
- IPv6 often has different security configurations
- Can bypass IPv4-only firewalls
Enumeration:
# Query AAAA records
dig target.com AAAA
# Query AAAA records (short output)
dig target.com AAAA +short
CNAME Record (Canonical Name Record)
Purpose: Creates an alias from one domain name to another.
Format: alias IN CNAME canonical_name
Example:
www.target.com. 300 IN CNAME target.com.
mail.target.com. 300 IN CNAME mailserver.target.com.
Attack Relevance:
- Reveals service relationships and aliases
- May expose internal service names
- Can reveal CDN usage and hosting providers
- Helps map the target’s service architecture
Enumeration:
# Query CNAME records
dig target.com CNAME
# Query CNAME for subdomain
dig www.target.com CNAME
# Follow CNAME chain
dig www.target.com CNAME +trace
MX Record (Mail Exchange Record)
Purpose: Specifies the mail servers responsible for receiving email for a domain.
Format: name IN MX preference mail_server
Example:
target.com. 3600 IN MX 10 mail.target.com.
target.com. 3600 IN MX 20 mail2.target.com.
Attack Relevance:
- Identifies email infrastructure
- Reveals mail server versions and configurations
- Enables email-based attacks (phishing, spam)
- May expose internal mail server names
- Preference values reveal backup mail servers
Enumeration:
# Query MX records
dig target.com MX
# Query MX records (short output)
dig target.com MX +short
# Follow MX to A records
dig target.com MX +short | while read pref mx; do dig $mx A +short; done
NS Record (Name Server Record)
Purpose: Specifies the authoritative name servers for a domain.
Format: name IN NS name_server
Example:
target.com. 86400 IN NS ns1.target.com.
target.com. 86400 IN NS ns2.target.com.
Attack Relevance:
- Identifies DNS infrastructure
- Reveals DNS hosting provider
- Name servers are targets for zone transfer attempts
- May expose internal name server names
- Helps identify DNS misconfigurations
Enumeration:
# Query NS records
dig target.com NS
# Query NS records (short output)
dig target.com NS +short
# Query NS records for each name server
dig target.com NS +short | while read ns; do dig @ns target.com AXFR; done
TXT Record (Text Record)
Purpose: Stores arbitrary text data associated with a domain.
Format: name IN TXT "text data"
Example:
target.com. 3600 IN TXT "v=spf1 include:_spf.google.com ~all"
target.com. 3600 IN TXT "google-site-verification=abc123def456"
_target.com. 3600 IN TXT "v=DKIM1; k=rsa; p=MIGfMA0GCS..."
Attack Relevance:
- SPF records reveal email infrastructure and trusted senders
- DKIM records reveal email signing keys
- Verification tokens reveal third-party service integrations
- May contain internal information or comments
- Can reveal cloud provider usage (AWS, Azure, GCP verification)
Common TXT Record Types:
| Record Type | Format | Purpose |
|---|---|---|
| SPF | v=spf1 ... |
Email sender policy |
| DKIM | v=DKIM1; ... |
Email signing key |
| DMARC | v=DMARC1; ... |
Email authentication policy |
| Google Verification | google-site-verification=... |
Google service verification |
| Microsoft Verification | ms=... |
Microsoft service verification |
| AWS Verification | aws:verification=... |
AWS service verification |
Enumeration:
# Query TXT records
dig target.com TXT
# Query SPF record
dig target.com TXT +short | grep spf
# Query DKIM record
dig _domainkey.target.com TXT
# Query DMARC record
dig _dmarc.target.com TXT
SOA Record (Start of Authority Record)
Purpose: Contains administrative information about the zone.
Format: name IN SOA mname rname serial refresh retry expire minimum
Example:
target.com. 86400 IN SOA ns1.target.com. admin.target.com. (
2026090101 ; Serial
3600 ; Refresh
900 ; Retry
604800 ; Expire
86400 ) ; Minimum TTL
Fields Explained:
| Field | Description | Attack Relevance |
|---|---|---|
| mname | Primary name server | Identifies primary DNS server |
| rname | Responsible person’s email | Social engineering target |
| serial | Zone serial number | Zone transfer indicator |
| refresh | How often secondaries check | DNS update frequency |
| retry | Retry interval on failure | DNS resilience |
| expire | When secondary data expires | DNS availability |
| minimum | Negative caching TTL | DNS caching behavior |
Attack Relevance:
- Admin email address is a social engineering target
- Serial number format may reveal zone transfer possibilities
- Name server information helps target DNS infrastructure
- Timing values reveal DNS update patterns
Enumeration:
# Query SOA record
dig target.com SOA
# Query SOA record (short output)
dig target.com SOA +short
SRV Record (Service Record)
Purpose: Specifies the location of services (port and priority).
Format: priority weight port target IN SRV service
Example:
_sip._tcp.target.com. 3600 IN SRV 10 60 5060 sipserver.target.com.
_xmpp._tcp.target.com. 3600 IN SRV 10 60 5222 xmpp.target.com.
Fields Explained:
| Field | Description |
|---|---|
| priority | Lower values have higher priority |
| weight | Load balancing weight |
| port | Service port number |
| target | Server hostname |
Attack Relevance:
- Reveals internal services and their locations
- May expose internal service names
- Helps map internal infrastructure
- Common in Active Directory environments
Common SRV Records:
| Service | Record | Default Port |
|---|---|---|
| LDAP | _ldap._tcp.dc._msdcs. |
389 |
| Kerberos | _kerberos._tcp. |
88 |
| SIP | _sip._tcp. |
5060 |
| XMPP | _xmpp._tcp. |
5222 |
| MySQL | _mysql._tcp. |
3306 |
Enumeration:
# Query SRV records
dig target.com SRV
# Query specific SRV record
dig _sip._tcp.target.com SRV
# Query LDAP SRV records (Active Directory)
dig _ldap._tcp.dc._msdcs.target.com SRV
PTR Record (Pointer Record)
Purpose: Maps an IP address to a domain name (reverse DNS).
Format: ip_address IN PTR domain_name
Example:
1.10.10.10.in-addr.arpa. 3600 IN PTR target.com.
Attack Relevance:
- Reveals server naming conventions
- May expose internal hostnames
- Helps identify server roles
- Can reveal infrastructure relationships
Enumeration:
# Reverse DNS lookup
dig -x 10.10.10.1
# Reverse DNS lookup (short output)
dig -x 10.10.10.1 +short
# Reverse lookup for IP range
for i in {1..254}; do dig -x 10.10.10.$i +short; done
CAA Record (Certification Authority Authorization)
Purpose: Specifies which Certificate Authorities can issue certificates for a domain.
Format: name IN CAA flags tag value
Example:
target.com. 3600 IN CAA 0 issue "letsencrypt.org"
target.com. 3600 IN CAA 0 issuewild ";"
Attack Relevance:
- Reveals certificate management practices
- May indicate which CAs the organization trusts
- Can reveal certificate automation tools
- Helps understand certificate infrastructure
Enumeration:
# Query CAA records
dig target.com CAA
# Query CAA records (short output)
dig target.com CAA +short
DNS Record Types Summary Table
| Record Type | Purpose | Attack Value | Common in OSCP |
|---|---|---|---|
| A | IPv4 address | Identifies servers | Yes |
| AAAA | IPv6 address | IPv6 infrastructure | Rare |
| CNAME | Alias | Service relationships | Yes |
| MX | Mail server | Email infrastructure | Yes |
| NS | Name server | DNS infrastructure | Yes |
| TXT | Text data | SPF, DKIM, verification | Yes |
| SOA | Zone info | Admin contact, timing | Yes |
| SRV | Service location | Internal services | Sometimes |
| PTR | Reverse DNS | Server naming | Yes |
| CAA | CA authorization | Certificate practices | Rare |
dig Command Deep Dive
dig (domain information groper) is the most powerful and flexible DNS query tool available on Linux systems.
Basic Syntax
dig [@server] [domain] [record_type] [options]
Common Options
| Option | Description | Example |
|---|---|---|
+short |
Short output format | dig target.com A +short |
+noall +answer |
Show only answer section | dig target.com +noall +answer |
+trace |
Trace resolution path | dig target.com +trace |
+tries=N |
Number of retry attempts | dig target.com +tries=3 |
+time=N |
Timeout in seconds | dig target.com +time=5 |
+retry=N |
Number of retries | dig target.com +retry=2 |
+search |
Use search list | dig target.com +search |
+nocmd |
Don’t print command | dig target.com +nocmd |
+noquestion |
Don’t print question | dig target.com +noquestion |
+nostats |
Don’t print stats | dig target.com +nostats |
+comments |
Include comments | dig target.com +comments |
+bufsize=N |
Set buffer size | dig target.com +bufsize=4096 |
+tcp |
Use TCP instead of UDP | dig target.com +tcp |
+port=N |
Set port number | dig target.com +port=53 |
-x |
Reverse lookup | dig -x 10.10.10.1 |
-f |
Batch mode (file input) | dig -f domains.txt |
-t |
Specify record type | dig -t MX target.com |
Output Interpretation
A typical dig output has several sections:
$ dig target.com A
; <<>> DiG 9.16.1-Ubuntu <<>> target.com A
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12345
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 3
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;target.com. IN A
;; ANSWER SECTION:
target.com. 300 IN A 10.10.10.1
;; AUTHORITY SECTION:
target.com. 86400 IN NS ns1.target.com.
target.com. 86400 IN NS ns2.target.com.
;; ADDITIONAL SECTION:
ns1.target.com. 300 IN A 10.10.10.2
ns2.target.com. 300 IN A 10.10.10.3
;; Query time: 15 msec
;; SERVER: 10.10.10.1#53(10.10.10.1)
;; WHEN: Mon Sep 01 10:00:00 UTC 2026
;; MSG SIZE rcvd: 128
Output Sections Explained
| Section | Description |
|---|---|
| HEADER | Query status, flags, and counts |
| OPT PSEUDOSECTION | EDNS information |
| QUESTION SECTION | The query that was made |
| ANSWER SECTION | The response to the query |
| AUTHORITY SECTION | Authoritative name servers |
| ADDITIONAL SECTION | Additional useful information |
Header Flags
| Flag | Description |
|---|---|
| qr | Query/Response (1 = response) |
| rd | Recursion Desired |
| ra | Recursion Available |
| aa | Authoritative Answer |
| tc | Truncation |
| ad | Authentic Data (DNSSEC) |
| cd | Checking Disabled (DNSSEC) |
Response Codes
| Code | Description |
|---|---|
| NOERROR | Query successful |
| FORMERR | Format error |
| SERVFAIL | Server failure |
| NXDOMAIN | Non-existent domain |
| NOTIMP | Not implemented |
| REFUSED | Query refused |
| YXDOMAIN | Domain exists when it shouldn’t |
| YXRRSET | RRSet exists when it shouldn’t |
| NXRRSET | RRSet doesn’t exist |
| NOTAUTH | Server not authoritative |
Practical dig Examples
1. Basic Queries
# Query A record
dig target.com A
# Query all record types
dig target.com ANY
# Query MX records
dig target.com MX
# Query NS records
dig target.com NS
# Query TXT records
dig target.com TXT
# Query SOA record
dig target.com SOA
2. Short Output
# Short output for A record
dig target.com A +short
# Short output for MX records
dig target.com MX +short
# Short output for NS records
dig target.com NS +short
# Short output for TXT records
dig target.com TXT +short
3. Reverse Lookups
# Reverse DNS lookup
dig -x 10.10.10.1
# Reverse lookup (short output)
dig -x 10.10.10.1 +short
# Reverse lookup for IP range
for i in {1..254}; do
result=$(dig -x 10.10.10.$i +short)
if [ -n "$result" ]; then
echo "10.10.10.$i -> $result"
fi
done
4. Querying Specific Servers
# Query specific name server
dig @ns1.target.com target.com A
# Query specific name server for zone transfer
dig @ns1.target.com target.com AXFR
# Query root name server
dig @a.root-servers.net target.com NS
# Query TLD name server
dig @a.gtld-servers.net target.com NS
5. Trace Resolution
# Trace the full resolution path
dig target.com +trace
# Trace with verbose output
dig target.com +trace +comments
6. Batch Mode
# Create a file with domains to query
echo -e "target.com\nwww.target.com\nmail.target.com" > domains.txt
# Query all domains in file
dig -f domains.txt
# Query all domains for specific record type
dig -f domains.txt -t MX
# Query all domains with short output
dig -f domains.txt +short
7. Advanced Queries
# Query with TCP (for large responses)
dig target.com ANY +tcp
# Query with custom timeout
dig target.com +time=5 +tries=3
# Query with custom port
dig target.com +port=5353
# Query with increased buffer size
dig target.com ANY +bufsize=4096
# Query with EDNS disabled
dig target.com +noedns
8. Filtering Output
# Show only answer section
dig target.com +noall +answer
# Show only authority section
dig target.com +noall +authority
# Show only additional section
dig target.com +noall +additional
# Show answer and authority sections
dig target.com +noall +answer +authority
# Show only the IP address
dig target.com A +short
nslookup Usage
nslookup is a simpler DNS query tool that is available on most systems, including Windows.
Basic Syntax
nslookup [options] [domain] [server]
Interactive Mode
# Enter interactive mode
nslookup
# Set query type
> set type=MX
# Query domain
> target.com
# Set server
> server ns1.target.com
# Query with new server
> target.com
# Exit
> exit
Non-Interactive Mode
# Basic query
nslookup target.com
# Query specific server
nslookup target.com ns1.target.com
# Query specific record type
nslookup -type=MX target.com
# Query specific record type from specific server
nslookup -type=MX target.com ns1.target.com
Common nslookup Commands
# Query A record
nslookup -type=A target.com
# Query MX records
nslookup -type=MX target.com
# Query NS records
nslookup -type=NS target.com
# Query TXT records
nslookup -type=TXT target.com
# Query SOA record
nslookup -type=SOA target.com
# Reverse lookup
nslookup 10.10.10.1
# Query specific name server
nslookup target.com ns1.target.com
dig vs nslookup
| Feature | dig | nslookup |
|---|---|---|
| Output Detail | Very detailed | Simple |
| Flexibility | High | Limited |
| Batch Mode | Yes (-f) |
No |
| Short Output | Yes (+short) |
No |
| Trace | Yes (+trace) |
No |
| TCP Support | Yes (+tcp) |
Limited |
| Custom Port | Yes (+port) |
No |
| Availability | Linux/macOS | Windows/Linux/macOS |
| Recommended | Yes | Legacy |
Recommendation: Use
digfor penetration testing. It is more powerful, flexible, and provides better output.nslookupis kept for compatibility and is considered legacy.
DNS Zone Transfer (AXFR)
What is a Zone Transfer?
A zone transfer (AXFR) is a protocol used to replicate DNS data across name servers. It allows secondary name servers to obtain a complete copy of the DNS zone from the primary name server.
Why it matters for penetration testing:
- A successful zone transfer reveals the entire DNS zone for a domain
- This includes all subdomains, internal hosts, and service names
- It is one of the most valuable reconnaissance techniques
- Misconfigured zone transfers are common in real-world environments
How Zone Transfers Work
sequenceDiagram
participant Attacker
participant Primary_NS as Primary Name Server
participant Secondary_NS as Secondary Name Server
Note over Secondary_NS,Primary_NS: Legitimate zone transfer
Secondary_NS->>Primary_NS: AXFR Request
Primary_NS->>Secondary_NS: Full Zone Data
Note over Attacker,Primary_NS: Attack attempt
Attacker->>Primary_NS: AXFR Request
alt Misconfigured
Primary_NS->>Attacker: Full Zone Data
Attacker->>Attacker: Complete DNS map
else Properly Configured
Primary_NS->>Attacker: REFUSED
end
Attempting a Zone Transfer
Using dig
# Attempt zone transfer from default server
dig axfr target.com
# Attempt zone transfer from specific name server
dig axfr target.com @ns1.target.com
# Attempt zone transfer from all name servers
dig target.com NS +short | while read ns; do
echo "Trying $ns..."
dig axfr target.com @$ns
done
Using nslookup
# Enter interactive mode
nslookup
# Set type to AXFR
> set type=axfr
# Attempt zone transfer
> target.com ns1.target.com
Using host
# Attempt zone transfer
host -l target.com ns1.target.com
Success Indicators
A successful zone transfer returns the complete zone data:
$ dig axfr target.com @ns1.target.com
; <<>> DiG 9.16.1-Ubuntu <<>> axfr target.com @ns1.target.com
;; global options: +cmd
;target.com. IN SOA ns1.target.com. admin.target.com. 2026090101 3600 900 604800 86400
target.com. 86400 IN NS ns1.target.com.
target.com. 86400 IN NS ns2.target.com.
target.com. 300 IN A 10.10.10.1
www.target.com. 300 IN A 10.10.10.1
mail.target.com. 300 IN A 10.10.10.2
ftp.target.com. 300 IN A 10.10.10.3
internal.target.com. 300 IN A 10.10.10.4
dev.target.com. 300 IN A 10.10.10.5
staging.target.com. 300 IN A 10.10.10.6
target.com. 3600 IN MX 10 mail.target.com.
target.com. 300 IN SOA ns1.target.com. admin.target.com. 2026090101 3600 900 604800 86400
;; Query time: 15 msec
;; SERVER: 10.10.10.2#53(10.10.10.2)
;; WHEN: Mon Sep 01 10:00:00 UTC 2026
;; XFR size: 11 records (messages 1, bytes 512)
Attack Value of Zone Transfers
| Information Revealed | Attack Value |
|---|---|
| All subdomains | Expands attack surface |
| Internal hostnames | Reveals internal infrastructure |
| Service names | Identifies services to target |
| IP addresses | Provides targets for scanning |
| Mail servers | Enables email-based attacks |
| Development servers | Often less secure than production |
| Staging environments | May contain test credentials |
Zone Transfer Prevention
| Method | Description |
|---|---|
| Access Control | Restrict AXFR to authorized secondary servers only |
| Firewall Rules | Block AXFR requests from unauthorized sources |
| DNS Server Config | Configure allow-transfer directive |
| Monitoring | Monitor for AXFR attempts |
| Regular Audits | Periodically test zone transfer access |
Incremental Zone Transfer (IXFR)
IXFR is an incremental version of AXFR that transfers only the changes since the last transfer:
# Attempt incremental zone transfer
dig ixfr target.com @ns1.target.com
# IXFR with serial number
dig ixfr=2026090100 target.com @ns1.target.com
DNSSEC Overview
What is DNSSEC?
DNSSEC (Domain Name System Security Extensions) is a set of extensions to DNS that add security by signing DNS data with cryptographic keys.
How DNSSEC Works
flowchart TD
A[DNS Zone] --> B[Sign with Private Key]
B --> C[DNSSEC Signed Records]
C --> D[Resolver Queries]
D --> E[Verify with Public Key]
E --> F{Valid?}
F -->|Yes| G[Return Response]
F -->|No| H[Return Error]
style A fill:#4ecdc4,stroke:#333,stroke-width:2px
style G fill:#95e1d3,stroke:#333,stroke-width:2px
style H fill:#ff6b6b,stroke:#333,stroke-width:2px
DNSSEC Record Types
| Record Type | Purpose |
|---|---|
| RRSIG | Digital signature for a record set |
| DNSKEY | Contains the public key for the zone |
| DS | Delegation signer (links child to parent zone) |
| NSEC | Proves non-existence of a record |
| NSEC3 | Proves non-existence (hashed, prevents zone walking) |
DNSSEC and Reconnaissance
| Aspect | Impact on Recon |
|---|---|
| Zone Walking | NSEC allows zone walking; NSEC3 prevents it |
| Data Integrity | Signed data cannot be spoofed |
| Authentication | Responses can be verified |
| Enumeration | NSEC records can reveal valid names |
Checking DNSSEC Status
# Check DNSSEC signing
dig target.com DNSKEY
# Check DS record
dig target.com DS
# Check RRSIG records
dig target.com RRSIG
# Check DNSSEC validation
dig target.com +dnssec
# Check DNSSEC with validation
dig target.com +dnssec +multi
NSEC Zone Walking
NSEC records can be used to enumerate all names in a zone:
# Attempt NSEC zone walking
dig target.com NSEC
# Walk through the zone
dig first.target.com NSEC
# Use the next name from the response and repeat
Note: NSEC3 was introduced to prevent zone walking by hashing the names. Most DNSSEC-enabled zones use NSEC3.
DNS Caching and Its Impact on Recon
What is DNS Caching?
DNS caching stores DNS query results to improve performance and reduce query load. Cached results have a TTL (Time to Live) that determines how long they are valid.
How Caching Affects Reconnaissance
| Aspect | Impact |
|---|---|
| Stale Data | Cached results may be outdated |
| Incomplete Data | Cache may not have all records |
| Timing | TTL affects when new data appears |
| Accuracy | Cached data may not reflect current state |
TTL Values
TTL values are specified in DNS records and determine cache duration:
# Check TTL values
dig target.com A
# Output shows TTL in the answer section:
# target.com. 300 IN A 10.10.10.1
# ^^^
# TTL = 300 seconds (5 minutes)
Common TTL Values
| TTL Value | Duration | Typical Use |
|---|---|---|
| 60 | 1 minute | Dynamic services, testing |
| 300 | 5 minutes | Web services, APIs |
| 3600 | 1 hour | Standard services |
| 86400 | 24 hours | Stable infrastructure |
| 604800 | 7 days | NS records, stable data |
Bypassing DNS Cache
# Query authoritative server directly (bypasses cache)
dig @ns1.target.com target.com A
# Use +noall to avoid cached results
dig target.com A +noall +answer
# Query with fresh flag
dig target.com A +noflush
Cache Poisoning Concerns
While not directly a recon technique, understanding DNS caching is important for:
- Cache poisoning attacks: Injecting false data into DNS cache
- DNS spoofing: Redirecting traffic to attacker-controlled servers
- Recon accuracy: Understanding when cached data may be stale
DNS-Based Subdomain Discovery
Subdomain discovery is one of the most valuable DNS enumeration techniques.
Why Subdomains Matter
| Reason | Description |
|---|---|
| Expanded Attack Surface | Each subdomain is a potential target |
| Different Services | Subdomains often host different services |
| Different Security | Subdomains may have different security configurations |
| Internal Services | Subdomains may expose internal services |
| Development Environments | Dev/staging subdomains are often less secure |
DNS-Based Subdomain Discovery Methods
1. Brute Force with dig
# Create a wordlist of common subdomains
cat > subdomains.txt << 'EOF'
www
mail
ftp
ssh
admin
portal
api
dev
staging
test
vpn
wiki
git
jenkins
grafana
prometheus
elastic
kibana
swagger
docs
blog
shop
store
cdn
static
assets
images
media
files
backup
db
database
mysql
postgres
redis
mongodb
ldap
kerberos
active-directory
dc
domain-controller
exchange
outlook
teams
slack
zoom
webex
meet
EOF
# Brute force subdomains
cat subdomains.txt | while read sub; do
result=$(dig +short $sub.target.com A)
if [ -n "$result" ]; then
echo "$sub.target.com -> $result"
fi
done
2. Using nslookup
cat subdomains.txt | while read sub; do
result=$(nslookup $sub.target.com 2>/dev/null | grep "Address" | tail -1)
if [ -n "$result" ]; then
echo "$sub.target.com -> $result"
fi
done
3. Using host
cat subdomains.txt | while read sub; do
result=$(host $sub.target.com 2>/dev/null | grep "has address")
if [ -n "$result" ]; then
echo "$sub.target.com -> $result"
fi
done
4. Zone Transfer (Best Method)
# Attempt zone transfer
dig axfr target.com @ns1.target.com
# If successful, all subdomains are revealed
Common Subdomain Patterns
| Pattern | Examples | Purpose |
|---|---|---|
| Service-based | mail, ftp, ssh, vpn | Specific services |
| Environment-based | dev, staging, test, prod | Development environments |
| Role-based | admin, portal, dashboard | Administrative interfaces |
| Technology-based | api, git, jenkins, grafana | Technology-specific services |
| Content-based | blog, docs, wiki, news | Content management |
| Infrastructure | cdn, static, assets, images | Content delivery |
Subdomain Discovery Tools
| Tool | Description | Notes |
|---|---|---|
| Sublist3r | Subdomain enumeration tool | Uses multiple sources |
| Amass | Attack surface mapping | Comprehensive DNS enumeration |
| Subfinder | Fast subdomain finder | Passive and active methods |
| massdns | High-performance DNS resolver | Fast brute forcing |
| dnsenum | DNS enumeration script | All-in-one tool |
Common DNS Misconfigurations
DNS misconfigurations can reveal sensitive information and create attack opportunities.
1. Open Zone Transfer
Misconfiguration: Zone transfers allowed from any source.
Detection:
dig axfr target.com @ns1.target.com
Impact: Complete DNS zone disclosure.
Remediation: Restrict zone transfers to authorized secondary servers only.
2. Exposed Internal Hostnames
Misconfiguration: Internal hostnames resolvable from external DNS.
Detection:
# Check for internal hostnames
dig internal.target.com A
dig dc01.target.com A
dig fileserver.target.com A
Impact: Reveals internal infrastructure and naming conventions.
Remediation: Use split-horizon DNS (separate internal and external zones).
3. Incorrect PTR Records
Misconfiguration: PTR records pointing to incorrect or internal domains.
Detection:
dig -x 10.10.10.1
Impact: May reveal internal domain names.
Remediation: Ensure PTR records match public domain names.
4. Missing SPF Records
Misconfiguration: No SPF record for email authentication.
Detection:
dig target.com TXT +short | grep spf
# If no output, SPF is missing
Impact: Enables email spoofing.
Remediation: Add proper SPF record.
5. Wildcard DNS Records
Misconfiguration: Wildcard A record resolves any subdomain.
Detection:
# Query random subdomain
dig randomstring123.target.com A
# If it resolves, wildcard is configured
Impact: Makes subdomain enumeration difficult; may expose unintended services.
Remediation: Remove wildcard records or restrict their scope.
6. DNS Rebinding Vulnerability
Misconfiguration: Low TTL combined with permissive DNS configuration.
Detection:
# Check TTL values
dig target.com A
# Low TTL (e.g., 0 or 60) may indicate rebinding risk
Impact: Allows bypassing same-origin policy in browsers.
Remediation: Use proper TTL values and validate Host headers.
7. Exposed DNS Admin Information
Misconfiguration: SOA record contains real email address.
Detection:
dig target.com SOA
# Look for admin email in rname field
Impact: Enables social engineering attacks.
Remediation: Use generic email addresses in SOA records.
8. DNS Cache Poisoning Vulnerability
Misconfiguration: Lack of DNSSEC or weak DNS configuration.
Detection:
dig target.com +dnssec
# If no DNSSEC records, may be vulnerable
Impact: Allows DNS spoofing and traffic redirection.
Remediation: Enable DNSSEC and use modern DNS software.
Attack Chain Position
DNS enumeration is part of the Reconnaissance and Scanning phases.
flowchart LR
A[Passive Recon] --> B[DNS Enumeration]
B --> C[Subdomain Discovery]
C --> D[Zone Transfer]
D --> E[Service Identification]
E --> F[Port Scanning]
F --> G[Service Enumeration]
G --> H[Vulnerability Analysis]
H --> I[Exploitation]
style B fill:#4ecdc4,stroke:#333,stroke-width:2px
style D fill:#4ecdc4,stroke:#333,stroke-width:2px
DNS in the Kill Chain
| Kill Chain Phase | DNS Activities |
|---|---|
| Reconnaissance | DNS record enumeration, zone transfers, subdomain discovery |
| Weaponization | N/A |
| Delivery | N/A |
| Exploitation | DNS-based exploits, DNS rebinding |
| Installation | N/A |
| Command & Control | DNS tunneling, DGA (Domain Generation Algorithms) |
| Actions on Objectives | N/A |
OSCP Exam Tips
Critical DNS Advice for OSCP
1. Always Check DNS Records
# Query all record types
dig target.local ANY
# Check for subdomains
dig ns target.local
dig mx target.local
# Zone transfer attempt (very common in OSCP)
dig axfr target.local @ns1.target.local
2. Zone Transfers are Common in OSCP
Zone transfers are one of the most common ways to discover additional targets in OSCP exams:
# Get name servers
dig target.local NS +short
# Attempt zone transfer from each name server
dig target.local NS +short | while read ns; do
echo "Trying zone transfer from $ns..."
dig axfr target.local @$ns
done
3. Look for Internal Hostnames
DNS records often reveal internal infrastructure:
# Check for common internal hostnames
for sub in dc fileserver webserver mailserver db server admin internal dev staging test; do
result=$(dig +short $sub.target.local A)
if [ -n "$result" ]; then
echo "$sub.target.local -> $result"
fi
done
4. Reverse DNS Lookups
# Reverse lookup for target IP
dig -x 10.10.10.1
# Reverse lookup for IP range
for i in {1..254}; do
result=$(dig -x 10.10.10.$i +short)
if [ -n "$result" ]; then
echo "10.10.10.$i -> $result"
fi
done
5. DNS-Based Service Discovery
# Check for SRV records (Active Directory)
dig _ldap._tcp.dc._msdcs.target.local SRV
dig _kerberos._tcp.target.local SRV
# Check for mail servers
dig target.local MX
Common DNS Mistakes in OSCP
- Not attempting zone transfers: This is one of the easiest ways to discover targets
- Ignoring NS records: Name servers are the targets for zone transfers
- Not checking MX records: Mail servers are often separate targets
- Missing internal hostnames: DNS records often reveal internal infrastructure
- Not using reverse DNS: Reverse lookups can reveal additional hosts
Quick DNS Commands for OSCP
# 1. Query all records
dig target.local ANY
# 2. Get name servers
dig target.local NS +short
# 3. Attempt zone transfer
dig target.local NS +short | while read ns; do dig axfr target.local @$ns; done
# 4. Check MX records
dig target.local MX +short
# 5. Reverse DNS lookup
dig -x 10.10.10.1 +short
# 6. Check for subdomains
for sub in www mail ftp admin dev staging test internal dc fileserver; do
result=$(dig +short $sub.target.local A)
if [ -n "$result" ]; then echo "$sub.target.local -> $result"; fi
done
Summary
DNS enumeration is a powerful reconnaissance technique that reveals infrastructure details, internal hostnames, and service relationships. Key takeaways:
- Know all DNS record types: Each type reveals different information
- Master the dig command: It is the most powerful DNS query tool
- Always attempt zone transfers: They reveal the entire DNS zone
- Look for internal hostnames: DNS records often expose internal infrastructure
- Check for misconfigurations: Common DNS misconfigurations reveal sensitive information
- Use subdomain discovery: Subdomains expand the attack surface
- Understand DNSSEC: It affects enumeration techniques and security
Mastering DNS enumeration will significantly improve your ability to discover and map target infrastructure during the OSCP exam and real-world penetration tests.
References and Further Reading
- BIND Documentation
- RFC 1034: DNS Concepts
- RFC 1035: DNS Operations
- DNSSEC Overview
- NSEC Zone Walking
Last Updated: 2026-09-01 Chapter 03: Information Gathering - Topic 03: DNS Enumeration