translate

This commit is contained in:
JrD
2020-05-11 18:36:50 +08:00
parent 8e0daa48a1
commit 038b91b52f
14 changed files with 230 additions and 227 deletions
+59 -60
View File
@@ -1,6 +1,6 @@
# coding=utf-8
"""
模块基类
Module base class
"""
import json
@@ -39,43 +39,43 @@ class Module(object):
def check(self, *apis):
"""
简单检查是否配置了api信息
Simply check whether the api information configure or not
:param apis: api信息元组
:return: 检查结果
:param apis: apis set
:return bool: check result
"""
if not all(apis):
logger.log('ALERT', f'{self.source}模块没有配置API跳过执行')
logger.log('ALERT', f'{self.source} module is not configured, skip')
return False
return True
def begin(self):
"""
输出模块开始信息
begin log
"""
logger.log('DEBUG', f'开始执行{self.source}模块收集{self.domain}的子域')
logger.log('DEBUG', f'Start {self.source} module to collect subdomains of {self.domain}')
def finish(self):
"""
输出模块结束信息
finish log
"""
self.end = time.time()
self.elapse = round(self.end - self.start, 1)
logger.log('DEBUG', f'结束执行{self.source}模块收集{self.domain}的子域')
logger.log('INFOR', f'{self.source}模块耗时{self.elapse}秒发现子域'
f'{len(self.subdomains)}')
logger.log('DEBUG', f'{self.source}模块发现{self.domain}的子域\n'
f'{self.subdomains}')
logger.log('DEBUG', f'Finished {self.source} module to collect {self.domain}\'s subdomains')
logger.log('INFOR', f'The {self.source} module took {self.elapse} seconds, '
f'found {len(self.subdomains)} subdomains')
logger.log('DEBUG', f'{self.source} module found subdomains of {self.domain}\n'
f'{self.subdomains}')
def head(self, url, params=None, check=True, **kwargs):
"""
自定义head请求
Custom head request
:param str url: 请求地址
:param dict params: 请求参数
:param bool check: 检查响应
:param kwargs: 其他参数
:return: requests响应对象
:param str url: request url
:param dict params: request parameters
:param bool check: check response
:param kwargs: other params
:return: requests's response object
"""
try:
resp = requests.head(url,
@@ -97,13 +97,13 @@ class Module(object):
def get(self, url, params=None, check=True, **kwargs):
"""
自定义get请求
Custom get request
:param str url: 请求地址
:param dict params: 请求参数
:param bool check: 检查响应
:param kwargs: 其他参数
:return: requests响应对象
:param str url: request url
:param dict params: request parameters
:param bool check: check response
:param kwargs: other params
:return: requests's response object
"""
try:
resp = requests.get(url,
@@ -125,13 +125,13 @@ class Module(object):
def post(self, url, data=None, check=True, **kwargs):
"""
自定义post请求
Custom post request
:param str url: 请求地址
:param dict data: 请求数据
:param bool check: 检查响应
:param kwargs: 其他参数
:return: requests响应对象
:param str url: request url
:param dict params: request parameters
:param bool check: check response
:param kwargs: other params
:return: requests's response object
"""
try:
resp = requests.post(url,
@@ -153,11 +153,11 @@ class Module(object):
def get_header(self):
"""
获取请求头
Get request header
:return: 请求头
:return: header
"""
# logger.log('DEBUG', f'获取请求头')
# logger.log('DEBUG', f'Get request header')
if setting.enable_fake_header:
return utils.gen_fake_header()
else:
@@ -165,36 +165,35 @@ class Module(object):
def get_proxy(self, module):
"""
获取代理
Get proxy
:param str module: 模块名
:return: 代理字典
:param str module: module name
:return: proxy
"""
if not setting.enable_proxy:
logger.log('TRACE', f'所有模块不使用代理')
logger.log('TRACE', f'All modules do not use proxy')
return self.proxy
if setting.proxy_all_module:
logger.log('TRACE', f'{module}模块使用代理')
logger.log('TRACE', f'{module} module uses proxy')
return utils.get_random_proxy()
if module in setting.proxy_partial_module:
logger.log('TRACE', f'{module}模块使用代理')
logger.log('TRACE', f'{module} module uses proxy')
return utils.get_random_proxy()
else:
logger.log('TRACE', f'{module}模块不使用代理')
logger.log('TRACE', f'{module} module does not use proxy')
return self.proxy
@staticmethod
def match(domain, html, distinct=True):
"""
正则匹配出子域
Use regexp to match subdomains
:param str domain: 域名
:param str html: 要匹配的html响应体
:param bool distinct: 匹配结果去除
:return: 匹配出的子域集合或列表
:rtype: set or list
:param str domain: domain
:param str html: response html text
:param bool distinct: deduplicate results or not (default True)
:return set/list: result set or list
"""
logger.log('TRACE', f'正则匹配响应体中的子域')
logger.log('TRACE', f'Use regexp to match subdomains in the response body')
regexp = r'(?:\>|\"|\'|\=|\,)(?:http\:\/\/|https\:\/\/)?' \
r'(?:[a-z0-9](?:[a-z0-9\-]{0,61}[a-z0-9])?\.){0,}' \
+ domain.replace('.', r'\.')
@@ -211,22 +210,22 @@ class Module(object):
@staticmethod
def register(domain):
"""
获取注册域名
Get registered domain
:param str domain: 域名
:return: 注册域名
:param str domain: domain
:return: registered domain
"""
return Domain(domain).registered()
def save_json(self):
"""
将各模块结果保存为json文件
Save the results of each module as a json file
:return 是否保存成功
:return bool: whether saved successfully
"""
if not setting.save_module_result:
return False
logger.log('TRACE', f'{self.source}模块发现的子域结果保存为json文件')
logger.log('TRACE', f'Save the subdomain results found by {self.source} module as a json file')
path = setting.result_save_dir.joinpath(self.domain, self.module)
path.mkdir(parents=True, exist_ok=True)
name = self.source + '.json'
@@ -244,7 +243,7 @@ class Module(object):
def gen_record(self, subdomains, record):
"""
生成记录字典
Generate record dictionary
"""
item = dict()
item['content'] = record
@@ -253,11 +252,11 @@ class Module(object):
def gen_result(self, find=0, brute=None, valid=0):
"""
生成结果
Generate results
"""
logger.log('DEBUG', f'正在生成最终结果')
logger.log('DEBUG', f'Generating final results...')
if not len(self.subdomains): # 该模块一个子域都没有发现的情况
logger.log('DEBUG', f'{self.source}模块收集结果为空')
logger.log('DEBUG', f'{self.source} module result is empty')
result = {'id': None,
'type': self.type,
'alive': None,
@@ -347,10 +346,10 @@ class Module(object):
def save_db(self):
"""
将模块结果存入数据库中
Save module results into the database
"""
logger.log('DEBUG', f'正在将结果存入到数据库')
logger.log('DEBUG', f'Saving results to database')
lock.acquire()
db = Database()
db.create_table(self.domain)