Cyber Services / All lessons / CEH — Ethical Hacking / Subdomain Enumeration Using Metasploit

Subdomain Enumeration Using Metasploit

Module 21 of 130 · 9 min read · Free to read

MODULES ↓ Command blocks have a COPY button
Comprehensive DNS Reconnaissance and Attack Surface Discovery
DNS Reconnaissance Attack Surface Discovery Metasploit Framework Practical Activities

Subdomain Enumeration: The Foundation of Reconnaissance

Subdomain enumeration is a critical reconnaissance technique in penetration testing and security assessment. It involves discovering subdomains associated with a target domain to expand the attack surface and identify potentially vulnerable entry points. Organizations often deploy development sites, administrative panels, and third-party services on subdomains that may have weaker security controls than the main domain.

Why Subdomain Enumeration Matters

Subdomain discovery provides multiple strategic advantages in security assessments:

  • Attack Surface Expansion: Each discovered subdomain represents additional potential attack vectors
  • Vulnerability Discovery: Development and staging subdomains often contain unpatched vulnerabilities
  • Asset Inventory: Creates comprehensive maps of organizational digital assets
  • Third-Party Risk: Identifies externally hosted services that may introduce security risks
  • Network Mapping: Reveals infrastructure patterns and relationships between services
Ethical Mandate: Authorization is Essential

WARNING: Subdomain enumeration involves active reconnaissance against target infrastructure. You MUST have explicit, written permission from the domain owner before conducting any enumeration activities. Unauthorized scanning may violate laws, terms of service, and ethical standards. Confine all testing to authorized engagements or personal lab environments.

DNS Enumeration

Comprehensive DNS reconnaissance including zone transfers, brute forcing, and reverse lookups

Brute Force Discovery

Systematic testing of common subdomain names using extensive wordlists

Advanced Techniques

DNS cache snooping, reverse lookups, and certificate transparency analysis

Integration Capabilities

Seamless integration with other Metasploit modules and external tools

DNS Fundamentals & Enumeration Principles

DNS Architecture Overview

Understanding DNS architecture is crucial for effective subdomain enumeration. The Domain Name System translates human-readable domain names into IP addresses and contains various record types that reveal infrastructure details.

Key DNS Record Types

Record Type Purpose Enumeration Value Example
A Record Maps domain to IPv4 address Identifies live hosts and services sub.example.com → 192.168.1.10
AAAA Record Maps domain to IPv6 address Identifies IPv6-enabled services sub.example.com → 2001:db8::1
CNAME Record Canonical name (alias) Reveals service relationships and CDN usage www.example.com → lb.example.com
MX Record Mail exchange servers Identifies email infrastructure example.com → mail.example.com
NS Record Name servers Reveals DNS infrastructure and potential zone transfer targets example.com → ns1.example.com
TXT Record Text information May contain API keys, verification codes, or configuration data example.com → "v=spf1 include:_spf.google.com"
Enumeration Methodology

Effective subdomain enumeration follows a systematic approach:

  1. Passive Enumeration: Gather information without direct interaction (certificate transparency, search engines)
  2. Active Enumeration: Direct DNS queries and brute force attempts
  3. Zone Transfer Attempts: Try to extract entire DNS zones from name servers
  4. Reverse Lookups: Discover domains hosted on identified IP addresses
  5. Validation & Verification: Confirm discovered subdomains and remove false positives

Metasploit DNS Enumeration Modules

Core DNS Modules

Metasploit provides several auxiliary modules specifically designed for DNS reconnaissance and subdomain enumeration, each with unique capabilities and use cases.

Module Description Primary Use Case Key Parameters
auxiliary/gather/dns_enum Comprehensive DNS enumeration including subdomains, zone transfers, and record analysis General reconnaissance and attack surface mapping DOMAIN, THREADS, MAX_RESOLVERS
auxiliary/gather/dns_bruteforce DNS subdomain brute forcing using wordlists Discovering hidden or non-public subdomains DOMAIN, WORDLIST, THREADS
auxiliary/gather/dns_reverse_lookup Reverse DNS lookup for IP ranges Network mapping and asset discovery RHOSTS, THREADS
auxiliary/gather/dns_cache DNS cache snooping to discover visited domains Internal network reconnaissance DOMAIN, DNS_SERVER
auxiliary/gather/dns_zone_transfer Attempt DNS zone transfers from name servers Comprehensive domain mapping when misconfigured DOMAIN, NS
CEH Domain Relevance

DNS enumeration with Metasploit directly supports multiple CEH domains including Footprinting and Reconnaissance, Scanning Networks, and Enumeration. These skills are fundamental to comprehensive security assessment methodology and align with the practical competencies expected of Certified Ethical Hackers.

DNS Enumeration Module Deep Dive

The dns_enum module is the most comprehensive DNS reconnaissance tool in Metasploit, combining multiple enumeration techniques.

# Launch Metasploit and load the DNS enumeration module
msfconsole
use auxiliary/gather/dns_enum
show options
# Configure and execute comprehensive DNS enumeration
set DOMAIN example.com
set THREADS 20
set MAX_RESOLVERS 10
set DISPLAY_RESULTS true
set ENUM_A true
set ENUM_AAAA true
set ENUM_CNAME true
set ENUM_MX true
set ENUM_NS true
set ENUM_TXT true
set ENUM_SRV true
run
Key Configuration Parameters
Understanding these parameters is crucial for effective enumeration:
  • DOMAIN: Target domain for enumeration (required)
  • THREADS: Number of concurrent threads (performance tuning)
  • MAX_RESOLVERS: Maximum DNS resolvers to use (redundancy)
  • DISPLAY_RESULTS: Show results in real-time (monitoring)
  • ENUM_*: Toggle specific record type enumeration (targeting)
  • WORDLIST: Custom wordlist for brute forcing (customization)

Advanced Enumeration Techniques

DNS Brute Force Attack

For comprehensive discovery beyond standard enumeration, the DNS brute force module systematically tests potential subdomain names using extensive wordlists.

# DNS brute force with custom wordlist
use auxiliary/gather/dns_bruteforce
set DOMAIN example.com
set WORDLIST /usr/share/wordlists/dns/subdomains-top1million-5000.txt
set THREADS 30
set VERBOSE true
run
# Using multiple DNS servers for reliability
set DNS_SERVER 8.8.8.8,1.1.1.1,9.9.9.9
set RETRY 3
set TIMEOUT 10
run
Wordlist Strategy

Effective brute forcing requires quality wordlists. Consider these sources:

  • Seclists: /usr/share/seclists/Discovery/DNS/
  • Built-in Metasploit: /usr/share/metasploit-framework/data/wordlists/
  • Custom Lists: Generate based on target technology and naming conventions
  • Combined Approach: Use multiple wordlists for comprehensive coverage

Reverse DNS Lookup

Reverse DNS lookups can discover additional domains hosted on the same infrastructure, revealing relationships and shared resources.

# Reverse DNS lookup for IP range
use auxiliary/gather/dns_reverse_lookup
set RHOSTS 192.168.1.1-192.168.1.254
set THREADS 20
run
# Export results for further analysis
set OUTPUT_FILE /root/reverse_dns_results.txt
run

DNS Cache Snooping

DNS cache snooping exploits caching behavior to discover domains that have been recently queried, potentially revealing internal infrastructure.

# DNS cache snooping technique
use auxiliary/gather/dns_cache
set DOMAIN example.com
set DNS_SERVER internal-dns-server
run
Cache Snooping Considerations

DNS cache snooping:

  • Works best against internal DNS servers
  • May be detected by security monitoring
  • Relies on specific DNS server configurations
  • Should be used judiciously during authorized assessments

Professional Enumeration Workflow

Comprehensive Enumeration Strategy

A professional subdomain enumeration workflow combines multiple techniques and tools for maximum coverage and accuracy.

# Phase 1: Initial reconnaissance with dns_enum
use auxiliary/gather/dns_enum
set DOMAIN target-company.com
set THREADS 15
set DISPLAY_RESULTS true
run
# Phase 2: Brute force with comprehensive wordlist
use auxiliary/gather/dns_bruteforce
set DOMAIN target-company.com
set WORDLIST /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt
set THREADS 25
run
# Phase 3: Reverse lookup on discovered IPs
use auxiliary/gather/dns_reverse_lookup
# Extract IPs from previous results and set RHOSTS
set THREADS 20
run
# Phase 4: Combine and validate results
# Combine all discovered subdomains
cat dns_enum_results.txt dns_brute_results.txt reverse_lookup_results.txt | sort -u > all_subdomains.txt

# Validate discovered subdomains
for sub in $(cat all_subdomains.txt); do
    host $sub.target-company.com | grep "has address"
done > validated_subdomains.txt

Results Analysis and Prioritization

Effective analysis transforms raw subdomain lists into actionable intelligence for security assessment.

Subdomain Categorization Framework

Category Examples Assessment Priority Testing Focus
Administrative admin, control, dashboard, manage Critical Authentication bypass, default credentials
Development dev, test, staging, qa High Unpatched vulnerabilities, debug features
API Services api, rest, graphql, soap High Input validation, authentication flaws
Infrastructure mail, ftp, vpn, ssh Medium-High Service-specific vulnerabilities
Third-Party cdn, assets, external Medium Configuration issues, subdomain takeover

Complementary Enumeration Tools

Tool Integration Strategy

While Metasploit provides powerful DNS enumeration capabilities, combining it with specialized tools creates a more comprehensive assessment approach.

Sublist3r

Python-based tool using search engines and DNS to enumerate subdomains

sublist3r -d example.com -o subdomains.txt

Amass

Comprehensive attack surface mapping and asset discovery

amass enum -d example.com -o amass_results.txt

Subfinder

Subdomain discovery tool using passive sources

subfinder -d example.com -o subfinder.txt

Assetfinder

Find domains and subdomains passively

assetfinder --subs-only example.com
# Integrating external tools with Metasploit results
# Run multiple tools and combine results
sublist3r -d example.com -o sublist3r.txt
subfinder -d example.com -o subfinder.txt
amass enum -d example.com -o amass.txt

# Combine all results and remove duplicates
cat sublist3r.txt subfinder.txt amass.txt dns_enum_results.txt | sort -u > comprehensive_subdomains.txt

# Import into Metasploit for further analysis
# Use the list for targeted scanning and exploitation

Hands-On Activities

Activity 1: Comprehensive Subdomain Enumeration
Objective: Perform complete subdomain discovery against a test domain using multiple Metasploit modules
  1. Set up a test environment with authorized domains for enumeration
  2. Run initial reconnaissance with the dns_enum module
  3. Perform brute force enumeration with comprehensive wordlists
  4. Execute reverse DNS lookups on discovered IP addresses
  5. Combine and validate all discovered subdomains
  6. Categorize findings by function and priority level
  7. Document methodology and results in professional format
# Complete enumeration workflow
msfconsole
use auxiliary/gather/dns_enum
set DOMAIN test-domain.com
set THREADS 20
run

use auxiliary/gather/dns_bruteforce  
set DOMAIN test-domain.com
set WORDLIST /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt
run

# Combine and analyze results...
Activity 2: Advanced DNS Analysis
Objective: Master advanced DNS enumeration techniques and analysis methods
  1. Perform DNS zone transfer attempts against name servers
  2. Analyze DNS record types for infrastructure intelligence
  3. Implement DNS cache snooping in appropriate scenarios
  4. Use multiple DNS servers for redundancy and verification
  5. Create custom wordlists based on target characteristics
  6. Integrate Metasploit results with external enumeration tools
# Advanced DNS analysis techniques
# Zone transfer attempt
use auxiliary/gather/dns_zone_transfer
set DOMAIN target.com
set NS ns1.target.com
run

# Custom wordlist generation based on target
cewl https://target.com/ -w custom_words.txt
# Process and format for DNS enumeration...
Activity 3: Enterprise-Scale Enumeration
Objective: Scale enumeration techniques for large enterprise environments
  1. Implement automated enumeration workflows
  2. Manage large result sets and eliminate duplicates
  3. Prioritize discovered subdomains for efficient testing
  4. Integrate enumeration results with vulnerability scanning
  5. Create comprehensive attack surface reports
  6. Develop reusable enumeration frameworks
# Enterprise-scale enumeration framework
#!/bin/bash
# Automated enumeration script
DOMAIN=$1
echo "Starting comprehensive enumeration for: $DOMAIN"

# Run multiple tools in parallel
msfconsole -q -x "use auxiliary/gather/dns_enum; set DOMAIN $DOMAIN; run" &
sublist3r -d $DOMAIN -o sublist3r_$DOMAIN.txt &
subfinder -d $DOMAIN -o subfinder_$DOMAIN.txt &

wait
# Combine and process results...
Professional Enumeration Methodology
  • Start Comprehensive: Begin with broad enumeration to maximize coverage
  • Validate Thoroughly: Eliminate false positives through active verification
  • Prioritize Intelligently: Focus testing on high-value subdomains first
  • Document Meticulously: Maintain detailed records of all enumeration activities
  • Respect Scope: Only enumerate domains and subdomains within authorized scope
  • Monitor Performance: Adjust threading and timing to avoid service disruption

Conclusion: Mastering Subdomain Enumeration

Subdomain enumeration with Metasploit represents a critical skill in modern security assessment methodology. By mastering DNS reconnaissance techniques, security professionals can significantly expand their understanding of target attack surfaces and identify potentially vulnerable entry points that might otherwise remain hidden.

Key Takeaways
  • Metasploit provides comprehensive DNS enumeration capabilities through specialized modules
  • Effective enumeration combines multiple techniques for maximum coverage
  • DNS record analysis reveals valuable infrastructure intelligence
  • Integration with external tools enhances enumeration completeness
  • Professional workflow includes validation, categorization, and prioritization
  • Ethical considerations and proper authorization are fundamental requirements
Final Ethical Reminder

DNS enumeration and subdomain discovery are powerful reconnaissance techniques that must be used responsibly and ethically. Always ensure you have explicit, written permission before conducting any enumeration activities. Unauthorized scanning violates legal and ethical standards in most jurisdictions. Use these skills to improve organizational security through authorized testing, responsible disclosure, and comprehensive defense recommendations.

Modules (130) ← CEH — Ethical Hacking