SECURITY ENGINEERING · PART 5 · ETHICAL HACKING, STEP BY STEP · RECON · 61 OF 229

Subdomain Enumeration: Amass, Subfinder, crt.sh

You cannot protect a host you do not know exists, and attackers look for exactly those. This episode covers subdomain and asset discovery: certificate logs with crt.sh, passive sources through Subfinder and Amass, DNS brute forcing, probing which hosts are alive with httpx, cloud assets such as open buckets, the subdomain takeover risk from dangling DNS records, and building a continuous asset inventory.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 9
  9. 10
  10. 11
  11. 12
  12. 13
  13. 14
  14. 15
  15. 16
  16. 17
  17. 18
  18. 19
  19. 20
  20. 21
  21. 22
  22. 23
  23. 24
  24. 25
  25. 26
  26. 27
  27. 28
  28. 29
  29. 30
  30. 31
  31. 32
  32. 33
  33. 34
  34. 35
  35. 36
  36. 37
  37. 38
  38. 39
  39. 40
  40. 41
  41. 42
  42. 43
  43. 44
  44. 45
  45. 46
  46. 47
  47. 48
  48. 49
  49. 50
  50. 51
  51. 52
  52. 53
  53. 54
  54. 55
  55. 56
  56. 57
  57. 58
  58. 59
  59. 60
  60. 61
  61. 62
  62. 63
  63. 64
  64. 106
  65. 107
  66. 108
  67. 109
  68. 110
  69. 111
  70. 112
  71. 113
  72. 114
  73. 115
  74. 116
  75. 117
  76. 118
  77. 119
  78. 120
  79. 121
  80. 122
  81. 123
  82. 124
  83. 125
  84. 126
  85. 127
  86. 128
  87. 129
  88. 130
  89. 131
  90. 132
  91. 133
  92. 134
  93. 135
  94. 136
  95. 137
  96. 138
  97. 139
  98. 140
  99. 141
  100. 142
  101. 143
  102. 144
1 / 14

Press play to hear the narration, or step through at your own pace.

Key takeaways

  • Certificate logs and passive sources
  • brute force in scope
  • probe what is alive
  • remove dangling DNS
  • inventory daily

Notes

Why subdomains

Why subdomains? Because each name is a separate system. Development, staging and test environments, often with weaker settings and real data. Old and legacy versions. Remote access points such as VPN and single sign-on. Internal tools exposed by accident: build servers, dashboards, ticket systems. APIs. Names left over from acquisitions and old campaigns. Each has different software, a different owner and a different patch level. The weakest one sets your security.

What hides in names
  • dev., staging., test., uat.
  • old., legacy., v1., beta.
  • vpn., remote., mail., sso.
  • jenkins., gitlab., grafana., jira., admin.
  • api., internal-api.
  • names from acquisitions and old campaigns
  • each: different software, owner and patch level

Certificate logs

The fastest source is certificate transparency. Every public certificate is logged with the hostnames it covers, and the site c r t dot s h lets you search those logs. One request returns every name under a domain that ever received a certificate. You will see the obvious ones, and then names like staging API and Grafana internal. It is completely passive. Note the lesson for defenders too: a certificate for an internal name publishes that name to the world.

query crt.sh
curl -s "https://crt.sh/?q=%25.example.com\
&output=json" | jq -r ".[].name_value" \
  | sort -u

# www.example.com
# api.example.com
# staging-api.example.com
# vpn.example.com
# grafana.internal.example.com
# passive: the target sees nothing

Passive tools

Tools combine many sources. Subfinder and Amass query certificate logs, passive DNS databases, which record what names resolved to over time, search engines, web archives and security datasets, then merge the results. Both have a passive mode that never contacts the target. Adding free API keys for the data providers increases coverage considerably. Run two tools and merge the output, because each finds names the other misses.

passive enumeration
subfinder -d example.com -silent \
  -o subs.txt

amass enum -passive -d example.com

# sources: CT logs, passive DNS,
# search engines, web archives,
# threat-intel and DNS datasets
# API keys add more sources

Active discovery

Some names have never appeared in any public source, so you ask DNS directly. Brute forcing resolves a wordlist of likely names. Permutation tools take known names and try variations, such as API dev and API two. A zone transfer, which hands over the whole zone, is rarely permitted but takes one command to check. First test for wildcard DNS, where every name resolves and results are meaningless. This is active: the target's DNS servers see the queries.

Going active
  • brute force: resolve a wordlist of likely names (dnsx, puredns, massdns)
  • permutations: api-dev, api-stg, api2 from known names
  • zone transfer (AXFR): rarely open, always worth one try
  • check for wildcard DNS first
  • this is visible to the target

Which are alive

A list of names is not yet useful. Next you check which are alive and what they run. A tool called httpx requests each one and reports the status, the page title and the detected technology. Now the interesting items stand out: an old site on a PHP version that stopped receiving fixes years ago, and a build server that answers on the internet. Screenshot tools give a visual overview of hundreds of hosts in minutes. This step is active and must be in scope.

probe with httpx
httpx -l subs.txt -title \
  -status-code -tech-detect

# https://api.example.com [200]
#   [API docs] [nginx]
# https://old.example.com [200]
#   [Welcome] [Apache 2.4.29, PHP 5.6]
# https://jenkins.example.com [403]
#   [Jenkins]

Subdomain takeover

Discovery also reveals one of the most common cloud-era weaknesses: subdomain takeover. A subdomain points, with a CNAME record, to an application on a cloud or hosting platform. Later the application is deleted, but the DNS record stays. An attacker registers that same application name on the platform, and now controls what your subdomain serves. They can obtain a valid certificate, host phishing pages on your real domain, and sometimes read cookies scoped to the parent domain.

How it happens
  • shop.example.com is a CNAME to an app on a cloud or SaaS platform
  • the app is deleted; the DNS record is forgotten
  • an attacker registers that same app name on the platform
  • now they serve content on YOUR subdomain, with a valid certificate

Prevent takeover

Prevention is mostly discipline. Delete the DNS record before deleting the resource it points to, never after. Manage DNS and cloud resources in the same infrastructure code, so they are removed together. Scan your own zones regularly for records pointing at resources that no longer exist. The same issue affects name server and mail records, and addresses released back to a cloud provider. Cloud providers publish guidance and tools for auditing your own zones.

Defenses
  • delete the DNS record BEFORE deleting the resource
  • manage DNS and cloud resources in the same code (Terraform)
  • scan for dangling CNAMEs regularly
  • also: dangling NS, MX, and released cloud IP addresses
  • tools exist for defenders to audit their own zones

Beyond subdomains

Assets are more than subdomains. Address ranges you own, and addresses in cloud accounts. Cloud storage buckets, often named after the company or product, and sometimes publicly readable. Other root domains for brands and acquisitions. Mobile applications, which contain the hostnames of the APIs they call. Public code repositories and container images. And software service tenants, such as a helpdesk or wiki, that may allow public sign-up. A full inventory covers all of these.

Other asset types
  • IP ranges: your ASN, cloud elastic IPs
  • cloud storage: buckets and blobs named after you
  • other root domains: brands, acquisitions, typos
  • mobile apps and their API hosts
  • code repos, container images
  • SaaS tenants: helpdesk, wiki, status pages

Make it continuous

A one-time list is out of date within a week, so make discovery continuous. Start from your sources of truth: DNS zones, cloud provider APIs and the registrar. Add outside-in discovery every day. Compare with yesterday and alert on anything new. Give every asset a named owner. And scan a new host before anyone else does. Commercial attack surface management products do this, and so does the open-source chain from this episode, on a schedule.

Asset inventory pipeline
  • sources of truth: DNS zones, cloud APIs, registrar
  • plus outside-in discovery, daily
  • diff against yesterday: alert on anything new each asset has an owner
  • new host: scanned before it is announced
  • tools: commercial ASM, or the open-source chain here

What to look at first

With hundreds of hosts, where do you look first? Testers have a consistent order. Anything old: outdated versions, expired certificates. Non-production names that appear to hold production data. Administration and developer tools reachable from the internet. Login pages without multi-factor authentication. Default installation pages, which signal an unfinished setup. Dangling records. And anything for which nobody in the company can name an owner.

Triage
  • anything old: outdated versions, expired certs
  • non-production names with production-looking data
  • admin and developer tools reachable from the internet
  • login pages without MFA
  • default pages: "It works!"
  • dangling records
  • things nobody can name an owner for

Common mistakes

Mistakes. Trusting the official asset list. Using one tool and one source. Actively probing a discovered host without confirming it belongs to the client and is in scope. Ignoring wildcard DNS and drowning in false results. Deleting a cloud resource while leaving its DNS record. Putting internal names into public certificates, which publishes them. And running discovery once a year, when the environment changes every day.

Avoid these
  • trusting the official asset list
  • one tool, one source
  • brute forcing or probing hosts outside the scope
  • ignoring wildcard DNS
  • deleting a cloud resource and leaving its DNS record
  • internal names in public certificates
  • discovery once a year

Say it like this

In the interview: I start passively with certificate transparency and passive DNS, using tools such as Subfinder and Amass. Then, within scope, DNS brute forcing and permutations, and probing for live hosts and technologies. I add address ranges, cloud storage and other root domains. I check for dangling records that allow subdomain takeover. As a defender, I combine that with our DNS and cloud APIs in a daily job that alerts on anything new and assigns an owner.

In the interview
  • "Passive first: certificate
  • transparency, passive DNS and tools like Subfinder and Amass. Then DNS brute force
  • and permutations, probe live
  • hosts with httpx, and add IP
  • ranges and cloud assets. I
  • check dangling records and run it daily with diffs."

Interview questions

Q1What is subdomain enumeration?

The process of discovering the subdomains that exist under a domain, using passive sources such as certificate transparency logs and passive DNS, and active methods such as DNS brute forcing. It reveals systems that may be forgotten or less well protected.

Q2How does crt.sh find subdomains?

crt.sh is a search interface for certificate transparency logs. Because every publicly trusted certificate and the hostnames it covers are logged, searching for a domain returns the names that have had certificates issued, without contacting the target.

Q3What is the difference between Amass and Subfinder?

Both enumerate subdomains from many passive sources. Subfinder is fast and focused on passive enumeration. Amass is broader, adding active techniques, DNS brute forcing and network mapping. Testers often run both and merge the results.

Q4What is a subdomain takeover?

A vulnerability in which a DNS record, usually a CNAME, points to an external resource that no longer exists. An attacker who claims that resource name on the provider can serve content on the victim's subdomain.

Q5How do you prevent subdomain takeover?

Remove DNS records before decommissioning the resources they reference, manage DNS and resources together in infrastructure as code, and regularly audit zones for records pointing to unclaimed or deleted cloud and SaaS resources.

Q6What is a DNS zone transfer and why is it a risk?

A zone transfer (AXFR) copies all records of a DNS zone to another server. If it is allowed to arbitrary clients, anyone can download the full list of hostnames. It should be restricted to authorised secondary name servers.

Q7What is passive DNS?

Databases built by recording DNS responses observed over time at resolvers and sensors. They show which names resolved to which addresses historically, revealing subdomains and infrastructure without querying the target's own name servers.

Q8Why do companies have unknown internet-facing assets?

Because of test environments left running, acquisitions, cloud resources created outside central processes, marketing sites built by agencies, and services decommissioned incompletely. Without continuous discovery and ownership, these accumulate.