You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
MiaCTFer/client/subdomain/oneforall/modules/certificates/crtsh.py

63 lines
2.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

from client.subdomain.oneforall.common import utils
from client.subdomain.oneforall.common.query import Query
class Crtsh(Query):
def __init__(self, domain):
"""
初始化 Crtsh 查询类
:param domain: 待查询的域名
"""
Query.__init__(self) # 调用父类 Query 的初始化方法
self.domain = self.register(domain) # 注册目标域名
self.module = 'Certificate' # 模块名称
self.source = 'CrtshQuery' # 数据源标识
self.addr = 'https://crt.sh/' # Crt.sh API 地址
def query(self):
"""
向 Crt.sh 接口查询子域,并进行子域匹配
"""
# 获取请求头和代理
self.header = self.get_header()
self.proxy = self.get_proxy(self.source)
# 构建查询参数q 参数匹配所有以目标域名为子域的记录,输出格式为 JSON
params = {'q': f'%.{self.domain}', 'output': 'json'}
resp = self.get(self.addr, params) # 发送 GET 请求
# 如果响应为空,则返回
if not resp:
return
# 使用 utils.match_subdomain 方法匹配并提取子域名
subdomains = utils.match_subdomain(self.domain, str(resp.json()))
# 将发现的子域名添加到当前已知子域名集合中
self.subdomains = self.subdomains.union(subdomains)
def run(self):
"""
类执行入口,执行查询操作并保存结果
"""
self.begin() # 开始执行
self.query() # 执行查询方法
self.finish() # 查询结束
self.save_json() # 保存结果为 JSON 文件
self.gen_result() # 生成最终结果
self.save_db() # 将结果保存到数据库
def do(domain): # 统一入口,方便多线程调用
"""
类统一调用入口
:param str domain: 域名
"""
query = Crtsh(domain) # 创建 Crtsh 实例
query.run() # 执行查询操作
if __name__ == '__main__':
do('example.com') # 执行对 example.com 的查询