修复check模块下在解析出多个IP不通的情况下超时严重的问题

This commit is contained in:
JrD
2020-09-08 18:56:20 +08:00
parent c8603728e3
commit 476364d2ca
3 changed files with 51 additions and 18 deletions
+18 -5
View File
@@ -11,6 +11,7 @@ class CSP(Check):
"""
Collect subdomains from ContentSecurityPolicy
"""
def __init__(self, domain, header):
Check.__init__(self)
self.domain = domain
@@ -18,6 +19,7 @@ class CSP(Check):
self.source = 'CSPCheck'
self.csp_header = header
@property
def grab_header(self):
"""
Get header
@@ -26,13 +28,24 @@ class CSP(Check):
"""
csp_header = dict()
urls = [f'http://{self.domain}',
f'https://{self.domain}',
f'http://www.{self.domain}',
f'https://www.{self.domain}']
f'https://{self.domain}']
urls_www = [f'http://www.{self.domain}',
f'https://www.{self.domain}']
header = self.grab_loop(csp_header, urls)
if header:
return header
header = self.grab_loop(csp_header, urls_www)
return header
def grab_loop(self, csp_header, urls):
for url in urls:
self.header = self.get_header()
self.proxy = self.get_proxy(self.source)
response = self.get(url, check=False)
try:
response = self.get(url, check=False, ignore=True, raise_error=True)
except requests.exceptions.ConnectTimeout:
logger.log('DEBUG', f'Connection to {url} timed out, so break check')
break
if response:
return response.headers
return csp_header
@@ -42,7 +55,7 @@ class CSP(Check):
正则匹配响应头中的内容安全策略字段以发现子域名
"""
if not self.csp_header:
self.csp_header = self.grab_header()
self.csp_header = self.grab_header
csp = self.csp_header.get('Content-Security-Policy')
if not self.csp_header:
logger.log('DEBUG', f'Failed to get header of {self.domain} domain')