Before testing an application, you map its attack surface — every subdomain and hidden page that exists. This recon is mostly guessing from a wordlist and checking what responds, and it's a perfect job for Python's requests library. Only ever run it against targets you own or are authorised to test.
Enumeration is just wordlist + check
You take a list of likely names, build a URL for each, and see which ones answer. No magic — just speed and a good wordlist.
Finding subdomains
import requests
domain = 'example.com'
for sub in ['www', 'mail', 'dev', 'admin', 'api']:
url = f'https://{sub}.{domain}'
try:
r = requests.get(url, timeout=3)
print(f'[+] {url} -> {r.status_code}')
except requests.RequestException:
pass # didn't resolve or connect
Each name that answers is another way in — and forgotten dev or staging subdomains are often the unpatched ones.
Finding hidden directories
Same idea, one level down — guess paths on a site you're allowed to test.
base = 'http://localhost:8000'
for path in ['admin', 'login', 'backup', 'config', 'uploads']:
r = requests.get(f'{base}/{path}')
if r.status_code != 404:
print(f'[+] /{path} -> {r.status_code}')
| Status code | Rough meaning |
|---|---|
| 200 | Page exists and loads |
| 301 / 302 | Redirect — something's there |
| 403 | Exists but forbidden (interesting!) |
| 404 | Not found — skip it |
A 403 is often more exciting than a 200: the page exists but someone tried to hide it.
Tip: Real wordlists (like SecLists) have tens of thousands of entries. Always set a
timeoutand go gently against a target you own — hammering a server with thousands of fast requests is noisy and can look like a denial-of-service attack.
The ethics line, again
Subdomain and directory enumeration touches real infrastructure. Run it only against domains you own or are explicitly authorised to test — a written scope agreement exists for exactly this reason.