mirror of
https://github.com/shmilylty/OneForAll.git
synced 2026-08-26 21:07:50 +08:00
解决爆破进程不为1出错的问题
This commit is contained in:
+63
-50
@@ -308,59 +308,63 @@ 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()
|
||||||
with open(result_path) as fd:
|
for result_path in result_paths:
|
||||||
for line in fd:
|
logger.log('DEBUG', f'正在读取{result_path}')
|
||||||
line = line.strip()
|
with open(result_path) as fd:
|
||||||
try:
|
for line in fd:
|
||||||
items = json.loads(line)
|
line = line.strip()
|
||||||
except Exception as e:
|
try:
|
||||||
logger.log('ERROR', e.args)
|
items = json.loads(line)
|
||||||
logger.log('ERROR', f'解析行{line}出错跳过解析该行')
|
except Exception as e:
|
||||||
continue
|
logger.log('ERROR', e.args)
|
||||||
status = items.get('status')
|
logger.log('ERROR', f'解析{result_path}行{line}出错跳过解析该行')
|
||||||
if status != 'NOERROR':
|
continue
|
||||||
continue
|
status = items.get('status')
|
||||||
data = items.get('data')
|
if status != 'NOERROR':
|
||||||
if 'answers' not in data:
|
continue
|
||||||
continue
|
data = items.get('data')
|
||||||
answers = data.get('answers')
|
if 'answers' not in data:
|
||||||
for answer in answers:
|
continue
|
||||||
if answer.get('type') == 'A':
|
answers = data.get('answers')
|
||||||
ip = answer.get('data')
|
for answer in answers:
|
||||||
# 取值 如果是首次出现的IP集合 出现次数先赋值0
|
if answer.get('type') == 'A':
|
||||||
value = times.setdefault(ip, 0)
|
ip = answer.get('data')
|
||||||
times[ip] = value + 1
|
# 取值 如果是首次出现的IP集合 出现次数先赋值0
|
||||||
|
value = times.setdefault(ip, 0)
|
||||||
|
times[ip] = value + 1
|
||||||
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() # 用来保存所有通过有效性检查的子域
|
||||||
with open(output_path) as fd:
|
for output_path in output_paths:
|
||||||
for line in fd:
|
logger.log('DEBUG', f'正在处理{output_path}')
|
||||||
line = line.strip()
|
with open(output_path) as fd:
|
||||||
try:
|
for line in fd:
|
||||||
items = json.loads(line)
|
line = line.strip()
|
||||||
except Exception as e:
|
try:
|
||||||
logger.log('ERROR', e.args)
|
items = json.loads(line)
|
||||||
logger.log('ERROR', f'解析行{line}出错跳过解析该行')
|
except Exception as e:
|
||||||
continue
|
logger.log('ERROR', e.args)
|
||||||
qname = items.get('name')[:-1] # 去出最右边的`.`点号
|
logger.log('ERROR', f'解析行{line}出错跳过解析该行')
|
||||||
status = items.get('status')
|
continue
|
||||||
if status != 'NOERROR':
|
qname = items.get('name')[:-1] # 去出最右边的`.`点号
|
||||||
logger.log('TRACE', f'处理{line}时发现{qname}查询结果状态{status}')
|
status = items.get('status')
|
||||||
continue
|
if status != 'NOERROR':
|
||||||
data = items.get('data')
|
logger.log('TRACE', f'处理{line}时发现{qname}查询结果状态{status}')
|
||||||
if 'answers' not in data:
|
continue
|
||||||
logger.log('TRACE', f'处理{line}时发现{qname}返回的结果无应答')
|
data = items.get('data')
|
||||||
continue
|
if 'answers' not in data:
|
||||||
records, subdomains = gen_records(items, records, subdomains,
|
logger.log('TRACE', f'处理{line}时发现{qname}返回的结果无应答')
|
||||||
ip_times, wildcard_ips,
|
continue
|
||||||
wildcard_ttl)
|
records, subdomains = gen_records(items, records, subdomains,
|
||||||
|
ip_times, wildcard_ips,
|
||||||
|
wildcard_ttl)
|
||||||
return records, subdomains
|
return records, subdomains
|
||||||
|
|
||||||
|
|
||||||
@@ -413,11 +417,12 @@ 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:
|
||||||
output_path.unlink()
|
for output_path in output_paths:
|
||||||
|
output_path.unlink()
|
||||||
|
|
||||||
|
|
||||||
class Brute(Module):
|
class Brute(Module):
|
||||||
@@ -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}秒'
|
||||||
|
|||||||
Reference in New Issue
Block a user