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/check/sitemap.py

76 lines
2.8 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.

"""
检查 sitemap 文件收集子域名
"""
from client.subdomain.oneforall.common.module import Module
from client.subdomain.oneforall.common import utils
class CheckSitemap(Module):
"""
检查 sitemap 文件收集子域名
"""
def __init__(self, domain):
"""
初始化 CheckSitemap 类
:param domain: 目标域名
"""
Module.__init__(self) # 调用父类 Module 的初始化方法
self.domain = self.register(domain) # 注册域名
self.module = 'Check' # 模块名称
self.source = 'Sitemap' # 数据源标识
def check(self):
"""
访问不同格式的 sitemap 文件并匹配子域名
"""
# 可能的 sitemap 文件 URL 列表,包括 XML, TXT, HTML 格式等
urls = [f'http://{self.domain}/sitemap.xml', f'https://{self.domain}/sitemap.xml',
f'http://www.{self.domain}/sitemap.xml', f'https://www.{self.domain}/sitemap.xml',
f'http://{self.domain}/sitemap.txt', f'https://{self.domain}/sitemap.txt',
f'http://www.{self.domain}/sitemap.txt', f'https://www.{self.domain}/sitemap.txt',
f'http://{self.domain}/sitemap.html', f'https://{self.domain}/sitemap.html',
f'http://www.{self.domain}/sitemap.html', f'https://www.{self.domain}/sitemap.html',
f'http://{self.domain}/sitemap_index.xml', f'https://{self.domain}/sitemap_index.xml',
f'http://www.{self.domain}/sitemap_index.xml', f'https://www.{self.domain}/sitemap_index.xml']
# 循环访问不同的 URL查找 sitemap 文件
for url in urls:
self.header = self.get_header()
self.proxy = self.get_proxy(self.source)
self.timeout = 10 # 设置请求超时时间为 10 秒
response = self.get(url, check=False, allow_redirects=False) # 不跟随重定向
if not response:
return
if response and len(response.content):
# 匹配 sitemap 文件中的子域名
self.subdomains = utils.match_subdomain(self.domain, response.text)
def run(self):
"""
执行入口方法,启动检查过程
"""
self.begin() # 开始执行
self.check() # 执行 sitemap 检查
self.finish() # 完成执行
# 保存结果到文件或数据库
self.save_json()
self.gen_result()
self.save_db()
def do(domain): # 统一入口,方便多线程调用
"""
类统一调用入口
:param domain: 域名
"""
check = CheckSitemap(domain) # 创建 CheckSitemap 实例
check.run() # 执行检查
if __name__ == '__main__':
# 示例:执行针对 'qq.com' 的 sitemap 检查
do('qq.com')