Back to cheatsheets
Privacy
Subdomain Enumeration
Discover subdomains via Certificate Transparency logs for passive enumeration and takeover detection.
What you'll learn
- CT log search (crt.sh)
- Subdomain takeover check
How to use these snippets
- Click the Copy button next to any snippet to copy it to your clipboard.
- Paste the code into your project, IDE, or terminal.
- Replace placeholder values (like
example.comoryour-secret) with your actual data. - Review the code comments for important security notes and caveats.
- Try the interactive related tool to see the concept in action.
Code Snippets
Copy-paste code snippets
2 ready-to-use snippets for subdomain enumeration. Click copy and paste into your project.
CT log search (crt.sh)
async function findSubdomains(domain) {
const url = `https://crt.sh/?q=%25.${domain}&output=json`;
const res = await fetch(url);
const data = await res.json();
// Extract unique subdomain names
const subdomains = new Set();
for (const entry of data) {
for (const name of entry.name_value.split('\n')) {
const clean = name.replace(/^*\./, '').trim();
if (clean.endsWith(domain)) {
subdomains.add(clean);
}
}
}
return [...subdomains].sort();
}
Subdomain takeover check
const TAKEOVER_FINGERPRINTS = {
'github.io': 'There isn\'t a GitHub Pages site here',
'herokuapp.com': 'No such app',
's3.amazonaws.com': 'The specified bucket does not exist',
'azurewebsites.net': '404 Web Site not found',
'shopify.com': 'Sorry, this shop is currently unavailable',
};
async function checkTakeover(subdomain) {
try {
const res = await fetch(`https://${subdomain}`, {
method: 'GET', redirect: 'manual'
});
const text = await res.text();
for (const [service, fingerprint] of
Object.entries(TAKEOVER_FINGERPRINTS)) {
if (subdomain.includes(service) &&
text.includes(fingerprint)) {
return { vulnerable: true, service };
}
}
return { vulnerable: false };
} catch (e) {
return { vulnerable: false, error: e.message };
}
}
Tool
Related ShieldX tool
Try this concept hands-on with the interactive tool.
100% Free · No signup · No cost
Generate something unguessable right now
148 bits of entropy, a crack-time estimate you can trust, and a clipboard that clears itself after 30 seconds.
Part of the Toolly ecosystem · secure.toolly.site