From 8408d538de41412834f6b54aa4d85ef5600855c2 Mon Sep 17 00:00:00 2001 From: Jing Ling Date: Thu, 2 Jan 2020 23:12:58 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oneforall/aiobrute.py | 2 +- oneforall/common/request.py | 3 ++- oneforall/common/resolve.py | 40 +++++++++++++++++++------------------ oneforall/config.py | 2 +- oneforall/oneforall.py | 4 +++- oneforall/takeover.py | 1 + 6 files changed, 29 insertions(+), 23 deletions(-) diff --git a/oneforall/aiobrute.py b/oneforall/aiobrute.py index 28d9321..d095767 100644 --- a/oneforall/aiobrute.py +++ b/oneforall/aiobrute.py @@ -261,7 +261,7 @@ class AIOBrute(Module): logger.log('INFOR', f'发现{self.domain}的子域: {hostname} ' f'解析到: {name} IP: {ips}') self.subdomains.add(hostname) - self.records[hostname] = str(ips) + self.records[hostname] = str(ips)[1:-1] async def main(self, domain, rx_queue): if not self.fuzz: # fuzz模式不探测域名是否使用泛解析 diff --git a/oneforall/common/request.py b/oneforall/common/request.py index 1030c7f..27dcb88 100644 --- a/oneforall/common/request.py +++ b/oneforall/common/request.py @@ -198,7 +198,8 @@ async def bulk_get_request(datas, port): futures = asyncio.as_completed(tasks) for future in tqdm.tqdm(futures, total=len(tasks), - desc='Progress'): + desc='Progress', + ncols=60): await future logger.log('INFOR', f'完成异步进行子域的GET请求') diff --git a/oneforall/common/resolve.py b/oneforall/common/resolve.py index b4fbcb2..556ccb6 100644 --- a/oneforall/common/resolve.py +++ b/oneforall/common/resolve.py @@ -1,5 +1,6 @@ import asyncio import functools +import socket import tqdm from dns.resolver import Resolver @@ -32,7 +33,7 @@ async def dns_query_a(hostname): except Exception as e: logger.log('TRACE', e.args) answer = e - return answer + return hostname, answer async def aiodns_query_a(hostname): @@ -44,11 +45,15 @@ async def aiodns_query_a(hostname): """ try: loop = asyncio.get_event_loop() - answer = await loop.getaddrinfo(hostname, 'http') - except Exception as e: + socket.setdefaulttimeout(20) + # answer = await loop.getaddrinfo(hostname, 80) + answer = await loop.run_in_executor(None, + socket.gethostbyname_ex, + hostname) + except BaseException as e: logger.log('TRACE', e.args) answer = e - return answer + return hostname, answer def resolve_callback(future, index, datas): @@ -59,18 +64,13 @@ def resolve_callback(future, index, datas): :param index: 下标 :param datas: 结果集 """ - try: - answer = future.result() - except Exception as e: - datas[index]['ips'] = str(e.args) + hostname, answer = future.result() + if isinstance(answer, Exception): + datas[index]['reason'] = str(answer.args) datas[index]['valid'] = 0 - else: - if isinstance(answer, list): - ips = {item[4][0] for item in answer} - datas[index]['ips'] = str(ips)[1:-1] - else: - datas[index]['ips'] = 'Something error' - datas[index]['valid'] = 0 + if isinstance(answer, tuple): + ips = answer[2] + datas[index]['ips'] = str(ips)[1:-1] async def bulk_query_a(datas): @@ -87,15 +87,17 @@ async def bulk_query_a(datas): if not data.get('ips'): subdomain = data.get('subdomain') task = asyncio.ensure_future(aiodns_query_a(subdomain)) - task.add_done_callback(functools.partial(resolve_callback, - index=i, - datas=datas)) # 回调 + wrapped_callback = functools.partial(resolve_callback, + index=i, + datas=datas) + task.add_done_callback(wrapped_callback) # 回调 tasks.append(task) if tasks: # 任务列表里有任务不空时才进行解析 futures = asyncio.as_completed(tasks) for future in tqdm.tqdm(futures, total=len(tasks), - desc='Progress'): + desc='Progress', + ncols=60): await future # await asyncio.wait(tasks) # 等待所有task完成 logger.log('INFOR', '完成异步查询子域的A记录') diff --git a/oneforall/config.py b/oneforall/config.py index 185e492..ac8bc29 100644 --- a/oneforall/config.py +++ b/oneforall/config.py @@ -32,7 +32,7 @@ enable_http_request = True # HTTP请求子域(默认True) enable_wildcard_check = True # 开启泛解析检测 会去掉泛解析的子域 # 爆破时使用的进程数(根据系统中CPU数量情况设置 不宜大于CPU数量 默认为系统中的CPU数量) brute_process_num = os.cpu_count() -brute_coroutine_num = 128 # 爆破时每个进程下的协程数(不宜大于500) +brute_coroutine_num = 2048 # 爆破时每个进程下的协程数(不宜大于500) # 爆破所使用的字典路径 默认data/subdomains.txt brute_wordlist_path = data_storage_path.joinpath('subnames.txt') brute_task_segment = 500 diff --git a/oneforall/oneforall.py b/oneforall/oneforall.py index 4c7fc52..762b845 100644 --- a/oneforall/oneforall.py +++ b/oneforall/oneforall.py @@ -34,7 +34,9 @@ banner = f"""{yellow} ___ _ _ ___ ___ ___| _|___ ___ ___| | | {version}{green} | . | | -_| _| . | _| .'| | | {blue} -|___|_|_|___|_| |___|_| |__,|_|_| {white}git.io/fjHT1{end} +|___|_|_|___|_| |___|_| |__,|_|_| {white}git.io/fjHT1 + +{red}OneForAll处于开发中,会进行版本快速迭代,请每次在使用前进行更新!{end} """ diff --git a/oneforall/takeover.py b/oneforall/takeover.py index 743bc5f..8140332 100644 --- a/oneforall/takeover.py +++ b/oneforall/takeover.py @@ -122,6 +122,7 @@ class Takeover(Module): bar = tqdm() bar.total = len(self.subdomains) bar.desc = 'Progress' + bar.ncols = 60 while True: done = bar.total - self.subdomainq.qsize() bar.n = done