diff --git a/kunyu/core/zoomeye.py b/kunyu/core/zoomeye.py index 35e10d0..0486e60 100644 --- a/kunyu/core/zoomeye.py +++ b/kunyu/core/zoomeye.py @@ -1,553 +1,553 @@ -#!/usr/bin/env python -# encoding: utf-8 -''' -@author: 风起 -@contact: onlyzaliks@gmail.com -@File: zoomeye.py -@Time: 2021/6/24 22:18 -''' - -import os -import sys -import json -import random - -import requests -import platform -from rich.table import Table -from rich.console import Console - -try: - import pocsuite3 -except ImportError: - sys.path.append(os.path.abspath(os.path.join(os.path.dirname(os.path.dirname(__file__)), os.path.pardir))) -from pocsuite3.cli import check_environment, module_path -from pocsuite3 import set_paths -from pocsuite3.lib.core.interpreter import PocsuiteInterpreter -from pocsuite3.lib.core.option import init_options - -import kunyu.lib.encode as encode -from kunyu.config.setting import UA, USER_INFO_API, HOST_SEARCH_API, WEB_SEARCH_API, DOMAIN_SEARCH_API, HOST_SCAN_INFO, SEMSITIVE_INFO -from kunyu.lib.export import export_xls -from kunyu.lib.batchfile import get_file -from kunyu.core.crash import HostScan -from kunyu.core.keyword import SearchKeyWord -from kunyu.core import conf -from kunyu.core.seebug import Seebug -from kunyu.utils.log import logger, logger_console -from kunyu.config.__version__ import __help__, init - -console = Console(color_system="auto", record=True) -overflow = "fold" if platform.system() == "Darwin" else "ignore" - -ZOOMEYE_KEY = conf.get("zoomeye", "apikey") -ZOOMEYE_TOKEN = conf.get("login", "token") - -params = {} - -class ZoomeyeSearch(object): - def __init__(self, method): - self.auth = None - self.search = None - self.page = 1 - self.method = method - self.headers = { - "User-Agent": random.choice(UA), - "author": "ZoomEye KunYu" - } - - def __call__(self, func): - def wrapper(*args, **kwargs): - nonlocal func - req_list = [] - login_url = func(self, *args, **kwargs) - try: - for num in range(int(self.page)): - params['query'], params['page'] = self.search, (num + 1) - req_list.append(self.__request(login_url, data=params, headers=self.headers)) - except requests.HTTPError as err: - logger.warning(err) - except requests.exceptions.ConnectionError: - logger.error("Network timeout") - except KeyboardInterrupt: - return - return req_list - - return wrapper - - def __request(self, login_url, data=None, headers=None): - self.__get_login() - """"As the request layer, - the processed data is received and returned to the original data, - which is displayed on the terminal after processing by the presentation layer. - """ - time = int(GlobalVar.get_timeout_resp()) - # The API is not available for tourist users - if self.method == "GET": - resp = requests.get( - login_url, - data=data, - headers=headers, - timeout=time, - verify=False - ) - else: - resp = requests.post( - login_url, - data=data, - headers=headers, - timeout=time, - verify=False - ) - self.check_status(resp) - self.check_error(resp.json()) - # return query data - return json.loads(resp.text) - - # Check return http status code - def check_status(self, resp): - # check http status code 500 or 503 - if resp.status_code in [500, 503]: - raise requests.HTTPError("ZoomEye Server Error, Status: {}".format(resp.status_code)) - elif resp.status_code in [401]: - logger.error("The token has expired, please re-initialize") - print(__help__.format(datil=init)) - sys.exit(0) - - # Check return error info - def check_error(self, resp): - if resp.get("error"): - raise requests.HTTPError(resp.get("message")) - - def __get_login(self): - """"Obtain the user login credentials and use them dynamically. - It is recommended to use the API-KEY method to log in, - because the user name/password requires an additional HTTP request, - so in theory the API-KEY method is more efficient. - """ - if ZOOMEYE_KEY == "None": - self.headers["Authorization"] = "JWT %s" % ZOOMEYE_TOKEN - else: - self.headers["API-KEY"] = ZOOMEYE_KEY - - -# After the SDK public,The interface to get the data. -@ZoomeyeSearch(method="GET") -def _dork_search(self, url, search, page): - """"The logic layer of ZoomEye processes the requested data - and feeds it back to the request layer to obtain the original data - """ - try: - if int(page) <= 0 or page is None: - raise ArithmeticError - self.page = page - self.search = search - return url - - except ArithmeticError: - return logger.warning("Please enter the correct number of queries!") - except Exception: - return logger.warning("Search for parameter exceptions!") - - -@ZoomeyeSearch(method="GET") -# Get ZoomEye User Info -def _user_info(self): - return USER_INFO_API - -# Set Global variate -class GlobalVar: - timeout_resp = 30 - def set_timeout_resp(timeout_resp): - GlobalVar.timeout_resp = timeout_resp - - def get_timeout_resp(*args): - return GlobalVar.timeout_resp - -# The Display class of the tool -class ZoomEye: - from kunyu.config.setting import ZOOMEYE_FIELDS_HOST, ZOOMEYE_FIELDS_WEB, ZOOMEYE_FIELDS_INFO, ZOOMEYE_FIELDS_DOMAIN - from kunyu.utils.convert import convert - raw_data_params = {} - sensitive_params = [] - page = 1 - dtype = 0 - btype = "host" - timeout = 30 - - # Global commands List - help = """Global commands: - info Print User info - SearchHost Basic Host search - SearchWeb Basic Web search - SearchIcon / Icon Image search - SearchBatch Batch search Host - SearchCert SSL certificate Search - SearchDomain Domain name associated/subdomain search - EncodeHash Encryption method interface (base64/hex/md5/mmh3) - HostCrash Host Header Scan hidden assets - Seebug Search Seebug vulnerability information - set