QT #1 - Keeping a subdomain off the scanners' radar

· PM-mirror


This is the first Quick Tip. The series is for the small stuff from my day to day: things I test, tweaks I end up keeping, attempts and experiments that don't need a whole post. Short on purpose, the kind of thing that reads in a couple of minutes.

The first one came from a private service I keep on a subdomain. I wanted it harder to find, and the first thing I learned was that its name was already public, with no way to take it back.

How a subdomain gets found #

1. A wildcard certificate #

With a certificate for *.example.org, the logs show only the wildcard, and new subdomains stop showing up there. The cover of this post is crt.sh's page for example.com, which does exactly this: every entry is *.example.com.

Wildcards need the DNS-01 challenge, so the ACME client needs API access to the DNS. On Porkbun, with acme.sh:

  1. Create an API key at porkbun.com/account/api. It comes as a key and a secret.
  2. Turn on API Access in the domain's settings. Porkbun makes each domain opt in.
  3. Then:

export PORKBUN_API_KEY="pk1_..."
export PORKBUN_SECRET_API_KEY="sk1_..."
acme.sh --issue --dns dns_porkbun -d example.org -d '*.example.org'

Any other DNS provider works the same way, only the plugin name and the variables change. acme.sh and lego know well over a hundred providers, and Certbot has plugins for the big ones, like certbot-dns-cloudflare. Whatever the provider, a key that can edit the whole zone is a powerful secret, so it's worth limiting it to that one domain when the provider allows.

2. Wildcard DNS #

Point *.example.org at the server. Every invented name now resolves to the same address, and DNS brute force can't tell what exists from what doesn't.

A terminal in a local lab. dig asks for secrets.example.org, admin.example.org and qz81-nothing-here.example.org, and every answer is the same address, 192.0.2.10.

Then nginx needs a catch-all that gives nothing back to names it doesn't know:

server {
listen 80 default_server;
listen 443 ssl default_server;
server_name _;
ssl_reject_handshake on;
return 444;
}

ssl_reject_handshake refuses TLS to anyone who doesn't ask for a known name, so connecting by IP reveals nothing. return 444 closes the connection without an answer.3 Add add_header X-Robots-Tag "noindex" always; to the real site and search engines stay away too.

3. A name nobody guesses #

Wildcard DNS beats DNS brute force, but a scanner that also tries HTTP still gets an answer from the real name, so a name on its wordlist gets found anyway. The real service needs something no list has, like lantern-9f2c instead of secrets.

And if the old name is already in the logs, renaming is the only fix: a wildcard only protects the names that come after it. Anything that points to the old name, like a login callback, has to move along with it.

Keep in mind #

This is a layer of obscurity on top of the real protection. The service still needs a login and updates. What a hidden name buys is fewer bots knocking.

  1. Certificate Transparency came out of Google after the 2011 DigiNotar breach, when a hacked CA issued fake certificates for Google domains. Since 2018, Chrome only trusts new certificates that were logged, so every public CA logs everything.

  2. SecurityTrails is one of the best known sellers of this history. Their records go back years, so a name that ever resolved publicly can show up there even after it's gone.

  3. 444 isn't a real HTTP status. nginx uses it internally to mean "close the connection and send nothing", which the client sees as an empty reply. ssl_reject_handshake arrived in nginx 1.19.4, in 2020.