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.
63 lines
1.5 KiB
63 lines
1.5 KiB
#!/usr/bin/env python3
|
|
|
|
"""
|
|
检查域名证书收集子域名
|
|
"""
|
|
import socket
|
|
import ssl
|
|
|
|
from client.subdomain.oneforall.common import utils
|
|
from client.subdomain.oneforall.common.module import Module
|
|
from client.subdomain.oneforall.config import logger
|
|
|
|
|
|
|
|
class CheckCert(Module):
|
|
def __init__(self, domain):
|
|
Module.__init__(self)
|
|
self.domain = self.register(domain)
|
|
self.port = 443 # ssl port
|
|
self.module = 'Check'
|
|
self.source = 'CertInfo'
|
|
|
|
def check(self):
|
|
"""
|
|
获取域名证书并匹配证书中的子域名
|
|
"""
|
|
try:
|
|
ctx = ssl.create_default_context()
|
|
sock = ctx.wrap_socket(socket.socket(),
|
|
server_hostname=self.domain)
|
|
sock.connect((self.domain, self.port))
|
|
cert_dict = sock.getpeercert()
|
|
except Exception as e:
|
|
logger.log('DEBUG', e.args)
|
|
return
|
|
subdomains = utils.match_subdomain(self.domain, str(cert_dict))
|
|
self.subdomains = self.subdomains.union(subdomains)
|
|
|
|
def run(self):
|
|
"""
|
|
类执行入口
|
|
"""
|
|
self.begin()
|
|
self.check()
|
|
self.finish()
|
|
self.save_json()
|
|
self.gen_result()
|
|
self.save_db()
|
|
|
|
|
|
def do(domain): # 统一入口名字 方便多线程调用
|
|
"""
|
|
类统一调用入口
|
|
|
|
:param str domain: 域名
|
|
"""
|
|
check = CheckCert(domain)
|
|
check.run()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
do('example.com')
|