-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubenum.py
More file actions
56 lines (47 loc) · 1.81 KB
/
subenum.py
File metadata and controls
56 lines (47 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import requests
import time
from urllib.parse import urlparse
import logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
def find_subdomains(domain):
subdomains = set()
try:
logger.info(f"Querying crt.sh for subdomains of {domain}")
url = f"https://crt.sh/?q=%25.{domain}&output=json"
res = requests.get(url, timeout=10)
res.raise_for_status()
data = res.json()
for entry in data:
name = entry.get('name_value', '').lower()
if name and domain in name:
subdomains.add(name)
logger.info(f"Found {len(subdomains)} subdomains from crt.sh")
except Exception as e:
logger.error(f"Error querying crt.sh: {e}")
common_subdomains = [
'www', 'mail', 'ftp', 'admin', 'blog', 'dev', 'test', 'staging',
'api', 'cdn', 'ns1', 'ns2', 'smtp', 'pop', 'imap', 'webmail',
'support', 'help', 'docs', 'wiki', 'forum', 'shop', 'store',
'app', 'mobile', 'secure', 'vpn', 'remote', 'portal'
]
try:
logger.info("Performing DNS bruteforce for common subdomains")
for sub in common_subdomains:
test_domain = f"{sub}.{domain}"
try:
import socket
socket.gethostbyname(test_domain)
subdomains.add(test_domain)
logger.debug(f"Found subdomain: {test_domain}")
except socket.gaierror:
continue
except Exception as e:
logger.error(f"Error during DNS bruteforce: {e}")
return sorted(list(subdomains))
def validate_domain(domain):
try:
parsed = urlparse(f"http://{domain}")
return bool(parsed.netloc)
except:
return False