【转载】【安服工具】四种 python 获取子域名的方式

在网络安全领域中,发现和管理攻击面绝对是一项必须的任务,而对域名的寻找和分析是发现攻击面的重要步骤。今天我们将与您分享关于域名发现的五种方法,并附带Python示例代码来帮助您更好的理解和掌握这些方法。

1. 证书透明度日志(Certificate Transparency Logs)

import requests

def 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'))

2. 主域名链式证书提取域名信息(Chain of Trust from Root Domain)

import ssl
import OpenSSL

def 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'))

3. 站长工具(Webmaster Tools)

import requests
from bs4 import BeautifulSoup

def 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 socket

def 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 exists
            socket.gethostbyname(full_domain)
            print(f"Discovered subdomain: {full_domain}")
        except socket.gaierror:
            pass

enum_subdomains('example.com')

根据目标和环境选择适合的工具进行深入挖掘总能帮助我们更好的发现攻击面。希望以上的信息会对你有所帮助。

写在最后

云图极速版支持包含上述几种在内的 20 余种域名发现方式,通过智能编排的方式动态调用以实现域名发现覆盖度的最大化。除此之外,云图极速版还支持 IP 发现、端口、服务、网站、组件、漏洞、安全风险等多种企业资产信息的全自动发现与监控。实现攻击面发现与攻击面管理的自动化。

转载自:https://blog.csdn.net/dhn987/article/details/136207467

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值