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.
66 lines
2.2 KiB
66 lines
2.2 KiB
from client.subdomain.oneforall.common import utils
|
|
from client.subdomain.oneforall.common.query import Query
|
|
|
|
|
|
class Google(Query):
|
|
def __init__(self, domain):
|
|
"""
|
|
初始化 Google 查询类
|
|
|
|
:param domain: 待查询的域名
|
|
"""
|
|
Query.__init__(self) # 调用父类 Query 的初始化方法
|
|
self.domain = self.register(domain) # 注册目标域名
|
|
self.module = 'Certificate' # 模块名称
|
|
self.source = 'GoogleQuery' # 数据源标识
|
|
self.addr = 'https://transparencyreport.google.com/' \
|
|
'transparencyreport/api/v3/httpsreport/ct/certsearch' # Google Transparency Report API 地址
|
|
|
|
def query(self):
|
|
"""
|
|
向 Google Transparency Report 接口查询子域,并进行子域匹配
|
|
"""
|
|
# 获取请求头和代理
|
|
self.header = self.get_header()
|
|
self.proxy = self.get_proxy(self.source)
|
|
|
|
# 构建查询参数,查询所有与目标域名相关的证书记录,包含过期证书和子域名
|
|
params = {'include_expired': 'true',
|
|
'include_subdomains': 'true',
|
|
'domain': self.domain}
|
|
resp = self.get(self.addr, params) # 发送 GET 请求
|
|
|
|
# 如果响应为空,则返回
|
|
if not resp:
|
|
return
|
|
|
|
# 使用 utils.match_subdomain 方法匹配并提取子域名
|
|
subdomains = utils.match_subdomain(self.domain, resp.text)
|
|
# 将发现的子域名添加到当前已知子域名集合中
|
|
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 = Google(domain) # 创建 Google 实例
|
|
query.run() # 执行查询操作
|
|
|
|
|
|
if __name__ == '__main__':
|
|
do('example.com') # 执行对 example.com 的查询
|