Skip to content

Subdomain Takeover Vulnerability

Critical DNS hijacking vulnerability detected

Critical Security Issue
DNS Hijacking
Domain Security

Critical Security Risk

Subdomain takeover allows attackers to hijack your subdomains and host malicious content under your trusted domain name. This can be used for phishing attacks, malware distribution, and stealing user credentials.

Understanding Subdomain Takeover

Subdomain takeover occurs when an attacker gains control of a subdomain that points to an external service you no longer use. This typically happens when you remove a service (like a hosted website, CDN, or cloud application) but forget to remove the DNS record pointing to it.

When the external service account is deleted or expires, the subdomain becomes available for registration by anyone. An attacker can then register the same service endpoint and immediately gain control of your subdomain, hosting whatever content they choose under your domain name.

Common Attack Scenarios

The real danger lies in how attackers weaponize hijacked subdomains for maximum impact. Attackers exploit hijacked subdomains to conduct sophisticated social engineering attacks, leveraging the trust and authority associated with your legitimate domain name. Users are more likely to trust content hosted on legitimate subdomains, making these attacks particularly effective for credential harvesting and malware distribution.

With the attack mechanisms clearly understood, implementing comprehensive protection becomes essential for preventing subdomain hijacking. The following systematic approach ensures thorough subdomain security.

Identify Vulnerable Subdomains

Protection starts with understanding your current exposure. A systematic audit reveals which subdomains could potentially be hijacked by attackers.

DNS Record Audit

Conduct a comprehensive DNS audit to identify potential subdomain takeover vulnerabilities by examining all external service integrations and their current status.

Subdomain takeover vulnerabilities typically occur when DNS records point to external services that are no longer active or configured. The audit process involves systematically discovering all subdomains, verifying their DNS records, and checking whether the target services are still operational. This methodical approach helps identify vulnerable endpoints before attackers can exploit them.

Basic DNS Discovery Commands

Start with basic DNS queries to identify CNAME records pointing to external services:

# Basic CNAME record discovery for takeover vulnerability assessment
dig yourdomain.com ANY | grep CNAME                    # Query all record types, filter CNAMEs
# This command reveals direct CNAME mappings in your zone
# Look for records pointing to third-party services

dig @8.8.8.8 yourdomain.com AXFR | grep CNAME         # Attempt zone transfer for complete view
# Zone transfer provides comprehensive DNS record listing
# Only works if your DNS server allows AXFR queries (usually restricted)
# Use your authoritative nameservers if zone transfer is blocked

The ANY query retrieves all available record types for your domain, making it easy to spot CNAME records that could be vulnerable. Zone transfer (AXFR) provides the most complete view but requires proper permissions.

Individual Subdomain Verification

Test specific subdomains to understand their configuration and vulnerability status:

# Detailed subdomain analysis for takeover vulnerability assessment
dig subdomain.yourdomain.com CNAME +short             # Extract CNAME target only
# +short flag returns minimal output (just the target hostname)
# Reveals which external service the subdomain points to

dig subdomain.yourdomain.com A +short                 # Verify IP address resolution
# Checks if CNAME ultimately resolves to valid IP addresses
# Missing resolution may indicate defunct service

nslookup subdomain.yourdomain.com                     # Cross-verification with different tool
# Provides additional DNS information including reverse lookup
# Helps confirm DNS configuration accuracy and detect inconsistencies

These commands verify both the DNS configuration and actual resolution. A CNAME that doesn't resolve to valid IP addresses often indicates a potential takeover vulnerability.

Advanced Subdomain Discovery

Use specialized tools for comprehensive subdomain enumeration across multiple data sources:

# Professional subdomain enumeration using specialized security tools
subfinder -d yourdomain.com -silent                   # Passive subdomain discovery
# Queries multiple data sources: certificate logs, search engines, APIs
# -silent flag suppresses verbose output for clean results
# Discovers subdomains that may not be in your DNS zone file

amass enum -passive -d yourdomain.com                 # OSINT-based comprehensive discovery
# Uses open source intelligence gathering techniques
# Passive mode avoids active DNS queries to prevent detection
# Excellent for finding forgotten or shadow IT subdomains

assetfinder yourdomain.com                            # Multi-source subdomain aggregation
# Combines results from various subdomain discovery APIs
# Fast and reliable for initial reconnaissance
# Often discovers subdomains missed by manual queries

These tools use passive intelligence gathering to discover subdomains that might not appear in your official DNS records, including forgotten test environments and shadow IT deployments.

Vulnerability Testing

Actively test discovered subdomains for takeover indicators and service status:

# Active vulnerability testing for subdomain takeover detection
curl -I https://subdomain.yourdomain.com              # HTTP headers inspection
# -I flag requests headers only (faster than full page download)
# Check for HTTP status codes indicating service problems
# Look for redirects to error pages or service unavailable messages

curl -sk https://subdomain.yourdomain.com | grep -i "not found\|404\|github"
# -s: silent mode (no progress bar)
# -k: ignore SSL certificate errors (for testing purposes)
# grep searches response content for takeover indicators
# Common indicators: "404 Not Found", "There isn't a GitHub Pages", "No such app"

# Additional service-specific checks
curl -I https://subdomain.yourdomain.com | grep -i "x-github-request-id\|x-served-by"
# Look for service-specific headers that confirm active hosting
# Missing service headers often indicate unclaimed or expired services

Active testing reveals the actual status of services behind your subdomains. Error messages like "404 Not Found" or "No such app" are strong indicators of potential takeover vulnerabilities.

Common Vulnerable Services

  • • GitHub Pages (*.github.io)
  • • Heroku Apps (*.herokuapp.com)
  • • AWS S3 Buckets (*.s3.amazonaws.com)
  • • Azure Websites (*.azurewebsites.net)
  • • Shopify Stores (*.myshopify.com)
  • • Tumblr Blogs (*.tumblr.com)

Automated Testing

Implement automated tools for efficient subdomain takeover detection across large domain portfolios.

Automated testing streamlines the vulnerability assessment process by combining subdomain discovery with HTTP status checking, allowing security teams to process hundreds of subdomains efficiently. These tools integrate multiple data sources and provide consistent, repeatable results that manual testing cannot match at scale.

Subdomain Discovery and HTTP Status Validation

Combine subdomain enumeration with HTTP status validation for comprehensive takeover assessment:

# Complete automated subdomain takeover vulnerability assessment pipeline

# Step 1: Comprehensive subdomain discovery
subfinder -d yourdomain.com -o subdomains.txt
# -o flag saves results to file for processing
# Discovers subdomains from certificate transparency logs, search engines, APIs
# Essential first step for comprehensive coverage

# Step 2: HTTP status code analysis for all discovered subdomains  
httpx -l subdomains.txt -status-code -title -tech-detect -o http_results.txt
# -l: input list of subdomains from file
# -status-code: show HTTP response codes (200, 404, 503, etc.)
# -title: extract page titles (often reveal service status)
# -tech-detect: identify technologies/services running
# -o: save structured output for analysis

# Step 3: Filter potential takeover candidates
grep -E "404|503|502|No such app|Not Found|There isn't a GitHub Pages" http_results.txt
# Search for common takeover indicators in HTTP responses
# 404/503: service not found or unavailable
# Service-specific messages indicate unclaimed accounts

This automated pipeline processes large subdomain lists efficiently, identifying potential vulnerabilities through pattern matching of HTTP responses and service-specific error messages.

Pro Tip: Run automated scans weekly as part of your security monitoring routine. New subdomains and service changes can introduce vulnerabilities between manual audits.

Prevention Strategies

Implement safeguards to prevent subdomain takeover

DNS Hygiene Practices

  • Remove unused records: Delete DNS entries when decommissioning services
  • Regular audits: Monthly review of all external-pointing records
  • Document services: Maintain inventory of all third-party integrations
  • Monitor expirations: Track service subscription and domain renewals

Service-Specific Prevention

  • • Keep GitHub Pages repositories active or remove CNAME
  • • Maintain Heroku app subscriptions or delete DNS records
  • • Configure AWS S3 bucket policies to prevent takeover
  • • Use Azure custom domains with active subscriptions only

Monitoring Implementation

Establish continuous monitoring to detect subdomain takeover attempts and service failures in real-time.

Continuous monitoring is essential because subdomain takeover vulnerabilities can emerge suddenly when services expire, accounts are suspended, or configurations change. Automated monitoring detects these changes immediately, allowing rapid response before attackers can exploit the vulnerability. This proactive approach is far more effective than periodic manual audits.

Basic Monitoring Script

Implement automated HTTP monitoring to detect service status changes:

# Basic subdomain monitoring script for takeover detection
#!/bin/bash

# Monitor critical subdomains for takeover indicators
SUBDOMAINS=("app.yourdomain.com" "blog.yourdomain.com" "cdn.yourdomain.com")

for subdomain in "${SUBDOMAINS[@]}"; do
    echo "Checking $subdomain..."
    
    # Check HTTP status and headers
    STATUS_CODE=$(curl -I -s -o /dev/null -w "%{http_code}" https://$subdomain)
    HEADERS=$(curl -I -s https://$subdomain)
    CONTENT=$(curl -s https://$subdomain | head -n 20)
    
    # Log results with timestamp
    echo "[$(date)] $subdomain - Status: $STATUS_CODE" >> monitoring.log
    
    # Alert on takeover indicators
    if [[ $STATUS_CODE == "404" ]] || [[ $CONTENT == *"Not Found"* ]] || [[ $CONTENT == *"No such app"* ]]; then
        echo "WARNING: Potential takeover detected for $subdomain" | mail -s "Subdomain Takeover Alert" admin@yourdomain.com
    fi
    
    sleep 1  # Rate limiting
done

This script performs regular HTTP checks and alerts administrators when takeover indicators are detected. Run via cron every hour for continuous protection.

Advanced Monitoring with Service Detection

Implement service-specific monitoring to detect when external services become unavailable:

# Advanced monitoring with service-specific takeover detection
#!/bin/bash

monitor_subdomain() {
    local domain=$1
    local service_type=$2
    
    echo "Monitoring $domain (Expected service: $service_type)"
    
    # Get full HTTP response
    response=$(curl -s -I https://$domain)
    content=$(curl -s https://$domain)
    
    case $service_type in
        "github")
            # GitHub Pages specific indicators
            if echo "$content" | grep -qi "there isn't a github pages"; then
                alert_takeover "$domain" "GitHub Pages not claimed"
            fi
            ;;
        "heroku")
            # Heroku specific indicators
            if echo "$content" | grep -qi "no such app"; then
                alert_takeover "$domain" "Heroku app not found"
            fi
            ;;
        "s3")
            # AWS S3 specific indicators
            if echo "$content" | grep -qi "nosuchbucket"; then
                alert_takeover "$domain" "S3 bucket not found"
            fi
            ;;
    esac
}

alert_takeover() {
    local domain=$1
    local reason=$2
    echo "CRITICAL: Subdomain takeover detected - $domain ($reason)"
    # Integrate with your alerting system (Slack, email, etc.)
}

Service-specific monitoring detects takeover vulnerabilities based on platform-specific error messages, providing more accurate alerts than generic HTTP status monitoring.

Remediation Steps

Fix existing vulnerabilities and secure your subdomains

Immediate Actions

  1. 1. Verify service status: Check if the external service is still active
  2. 2. Remove or update DNS: Delete vulnerable records or point to active services
  3. 3. Claim services: Re-register abandoned services if needed
  4. 4. Test accessibility: Verify subdomains resolve correctly

DNS Record Cleanup

Execute systematic DNS record removal to eliminate subdomain takeover vulnerabilities while maintaining service continuity.

DNS record cleanup requires careful verification to prevent service disruption. The process involves confirming the vulnerability, assessing business impact, creating rollback plans, and executing controlled removal. Proper documentation and testing ensure that cleanup doesn't inadvertently break legitimate services or create new security gaps.

Pre-Cleanup Verification

Thoroughly assess the subdomain before making DNS changes to understand dependencies:

# Comprehensive pre-cleanup verification process

# Step 1: Document current DNS configuration
nslookup subdomain.yourdomain.com
# Record exact DNS configuration before changes
# Note all record types: CNAME, A, AAAA, TXT, etc.

# Step 2: Verify service dependencies
dig subdomain.yourdomain.com ANY +short
# Check for additional DNS records that might be in use
# Look for email routing (MX), SPF/DKIM (TXT), or other services

# Step 3: Test current functionality
curl -I https://subdomain.yourdomain.com
curl -s https://subdomain.yourdomain.com | head -n 10
# Document current HTTP behavior and content
# Screenshot pages if needed for rollback reference

# Step 4: Check for legitimate usage
grep -r "subdomain.yourdomain.com" /path/to/application/configs/
# Search application configs, documentation, and code
# Identify any legitimate references that would break

This verification process prevents accidental removal of legitimate services and creates documentation needed for potential rollback scenarios.

Safe DNS Record Removal Process

Execute controlled DNS record removal with proper staging and verification:

# Controlled DNS record removal with safety checks

# Step 1: Set low TTL for quick rollback (if needed)
# Before removing records, temporarily set TTL to 300 seconds (5 minutes)
# This allows rapid rollback if removal causes unexpected issues

# Step 2: Remove DNS records via management interface
# Via DNS management console:
# - Log into your DNS provider (Route53, Cloudflare, etc.)
# - Locate the vulnerable subdomain record
# - Delete or disable the record

# Step 3: CLI removal for automation (example with AWS Route53)
aws route53 change-resource-record-sets --hosted-zone-id Z123456789 --change-batch '{
    "Changes": [{
        "Action": "DELETE",
        "ResourceRecordSet": {
            "Name": "subdomain.yourdomain.com",
            "Type": "CNAME",
            "TTL": 300,
            "ResourceRecords": [{"Value": "vulnerable-service.provider.com"}]
        }
    }]
}'

# Step 4: Verify removal
nslookup subdomain.yourdomain.com
# Should return NXDOMAIN or no records found
# Confirm DNS propagation across multiple resolvers

dig @8.8.8.8 subdomain.yourdomain.com
dig @1.1.1.1 subdomain.yourdomain.com
# Test with different public resolvers to confirm global propagation

The controlled removal process includes staging with low TTL values and multi-resolver verification to ensure complete DNS propagation without creating availability gaps.

Post-Removal Validation

Confirm successful remediation and monitor for any unexpected impacts:

# Post-removal validation and monitoring

# Step 1: Confirm vulnerability elimination
curl -I https://subdomain.yourdomain.com
# Should return connection error or certificate error
# No takeover-vulnerable error pages should be accessible

# Step 2: Monitor for legitimate service disruption
tail -f /var/log/application.log | grep "subdomain.yourdomain.com"
# Watch application logs for any references to removed subdomain
# Alert on any connectivity errors to removed endpoint

# Step 3: Validate no new vulnerabilities introduced
subfinder -d yourdomain.com | grep -v subdomain
# Re-scan for any new subdomains that might have been created
# Ensure removal didn't create alternative vulnerability paths

# Step 4: Document remediation
echo "$(date): Removed vulnerable subdomain subdomain.yourdomain.com" >> security-remediation.log
# Maintain security remediation log for compliance and audit trail
# Include vulnerability details and resolution steps

Post-removal validation ensures the vulnerability is completely eliminated and no legitimate services were inadvertently affected by the DNS changes.

Critical Warning: Never remove DNS records without verifying they don't support legitimate services. Always test removal in staging environments first and have rollback procedures ready.

Long-term Security

  • • Implement DNS CAA records to prevent unauthorized certificates
  • • Use subresource integrity (SRI) for external resources
  • • Regular penetration testing including subdomain enumeration
  • • Employee training on secure DNS management practices

Last updated: January 8, 2026