解决爆破进程不为1出错的问题

This commit is contained in:
Jing Ling
2020-05-04 16:50:41 +08:00
parent ba09528944
commit 9fd678e1bd
+20 -7
View File
@@ -308,9 +308,11 @@ def gen_records(items, records, subdomains, ip_times, wc_ips, wc_ttl):
return records, subdomains return records, subdomains
def stat_ip_times(result_path): def stat_ip_times(result_paths):
logger.log('INFOR', f'正在统计IP次数') logger.log('INFOR', f'正在统计IP次数')
times = dict() times = dict()
for result_path in result_paths:
logger.log('DEBUG', f'正在读取{result_path}')
with open(result_path) as fd: with open(result_path) as fd:
for line in fd: for line in fd:
line = line.strip() line = line.strip()
@@ -318,7 +320,7 @@ def stat_ip_times(result_path):
items = json.loads(line) items = json.loads(line)
except Exception as e: except Exception as e:
logger.log('ERROR', e.args) logger.log('ERROR', e.args)
logger.log('ERROR', f'解析行{line}出错跳过解析该行') logger.log('ERROR', f'解析{result_path}{line}出错跳过解析该行')
continue continue
status = items.get('status') status = items.get('status')
if status != 'NOERROR': if status != 'NOERROR':
@@ -336,10 +338,12 @@ def stat_ip_times(result_path):
return times return times
def deal_output(output_path, ip_times, wildcard_ips, wildcard_ttl): def deal_output(output_paths, ip_times, wildcard_ips, wildcard_ttl):
logger.log('INFOR', f'正在处理解析结果') logger.log('INFOR', f'正在处理解析结果')
records = dict() # 用来记录所有域名解析数据 records = dict() # 用来记录所有域名解析数据
subdomains = list() # 用来保存所有通过有效性检查的子域 subdomains = list() # 用来保存所有通过有效性检查的子域
for output_path in output_paths:
logger.log('DEBUG', f'正在处理{output_path}')
with open(output_path) as fd: with open(output_path) as fd:
for line in fd: for line in fd:
line = line.strip() line = line.strip()
@@ -413,10 +417,11 @@ def save_brute_dict(dict_path, dict_set):
exit(1) exit(1)
def delete_file(dict_path, output_path): def delete_file(dict_path, output_paths):
if config.delete_generated_dict: if config.delete_generated_dict:
dict_path.unlink() dict_path.unlink()
if config.delete_massdns_result: if config.delete_massdns_result:
for output_path in output_paths:
output_path.unlink() output_path.unlink()
@@ -577,10 +582,18 @@ class Brute(Module):
log_path, process_num=self.process_num, log_path, process_num=self.process_num,
concurrent_num=self.concurrent_num) concurrent_num=self.concurrent_num)
ip_times = stat_ip_times(output_path) output_paths = []
self.records, self.subdomains = deal_output(output_path, ip_times, if self.process_num == 1:
output_paths.append(output_path)
else:
for i in range(self.process_num):
output_name = f'resolved_result_{domain}_{timestring}.json{i}'
output_path = temp_dir.joinpath(output_name)
output_paths.append(output_path)
ip_times = stat_ip_times(output_paths)
self.records, self.subdomains = deal_output(output_paths, ip_times,
wildcard_ips, wildcard_ttl) wildcard_ips, wildcard_ttl)
delete_file(dict_path, output_path) delete_file(dict_path, output_paths)
end = time.time() end = time.time()
self.elapse = round(end - start, 1) self.elapse = round(end - start, 1)
logger.log('INFOR', f'{self.source}模块耗时{self.elapse}' logger.log('INFOR', f'{self.source}模块耗时{self.elapse}'