在網絡安全領域中,發現和管理攻擊面絕對是一項必須的任務,而對域名的尋找和分析是發現攻擊面的重要步驟。今天我們將與您分享關于域名發現的四種方法,并附帶Python示例代碼來幫助您更好的理解和掌握這些方法。
1. 主域名鏈式證書提取域名信息(Chain of Trust from Root Domain)
import ssl
import OpenSSLdef get_cert_chain(domain):cert = ssl.get_server_certificate((domain, 443))x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, cert)return [value for value in x509.get_subject().get_components()]print(get_cert_chain('example.com'))
2. 證書透明度日志(Certificate Transparency Logs)
import requestsdef query_crt_sh(domain):url = f"https://crt.sh/?q={domain}&output=json"response = requests.get(url)try:return [result['name_value'] for result in response.json()]except:return []print(query_crt_sh('example.com'))
3. 站長工具(Webmaster Tools)
import requests
from bs4 import BeautifulSoupdef query_webmaster_tools(domain):base_url = f"https://whois.chinaz.com/{domain}"page = requests.get(base_url)bs_obj = BeautifulSoup(page.text, "html.parser")return [pre.text for pre in bs_obj.find_all('pre')]print(query_webmaster_tools('example.com'))
4. 子域名爆破(Subdomain Enumeration)
對實際環境中常見的子域名前綴進行枚舉。
import socketdef enum_subdomains(domain):common_subdomains = ['www', 'ftp', 'mail', 'webmail', 'admin']for subdomain in common_subdomains:full_domain = f"{subdomain}.{domain}"try:# if the subdomain resolves, it existssocket.gethostbyname(full_domain)print(f"Discovered subdomain: {full_domain}")except socket.gaierror:passenum_subdomains('example.com')
根據目標和環境選擇適合的工具進行深入挖掘總能幫助我們更好的發現攻擊面。希望以上的信息會對你有所幫助。
寫在最后
云圖極速版支持包含上述幾種在內的 20 余種域名發現方式,通過智能編排的方式動態調用以實現域名發現覆蓋度的最大化。除此之外,云圖極速版還支持 IP 發現、端口、服務、網站、組件、漏洞、安全風險等多種企業資產信息的全自動發現與監控。實現攻擊面發現與攻擊面管理的自動化。