mirror of
https://github.com/shmilylty/OneForAll.git
synced 2026-08-25 20:37:48 +08:00
61 lines
1.3 KiB
Python
61 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
|
|
"""
|
|
检查域名证书收集子域名
|
|
"""
|
|
import socket
|
|
import ssl
|
|
|
|
from common.module import Module
|
|
from config.log import logger
|
|
|
|
|
|
class CheckCert(Module):
|
|
def __init__(self, domain):
|
|
Module.__init__(self)
|
|
self.domain = 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 = self.match_subdomains(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 run(domain):
|
|
"""
|
|
类统一调用入口
|
|
|
|
:param str domain: 域名
|
|
"""
|
|
check = CheckCert(domain)
|
|
check.run()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
run('example.com')
|