def load_module(name): # if os.path.isdir(name): # exp = parse_exp(name) # for i in exp: # path = (name + i).replace('/', '.') # try: # module_obj = importlib.import_module(name=path) # if hasattr(module_obj, 'Zerooosploit'): # pass # except ModuleNotFoundError as e: # LOGGER.error(e) # else: exp = name.replace('/', '.') try: global mod mod = importlib.import_module('modules.' + exp) if hasattr(mod, 'Zerooosploit'): module_self = getattr(mod, 'Zerooosploit') # print(getattr(module_self, 'show_info')) # print('class', module_self()) return module_self() else: msg = f'Module {exp} doesn\'t define any object named Zerooosploit' LOGGER.error(ModuleNotDefineException(msg)) except ModuleNotFoundError as e: LOGGER.error(e) except Exception as e: LOGGER.exception(e)
def command_handle(self, command, args): # print('1:',command, '2:',args) if self.current_module: if command == 'run' or command == 'exploit': self.command_run() elif command == 'back' or command == 'exit': self.command_back() elif command == 'set' and args: self.command_set(args) elif command == 'show' and args == 'options': self.command_show_options() elif command == 'show' and args == 'info': self.command_show_info() elif command == 'reload': self.command_reload() else: LOGGER.error('Unknow command: {0}.'.format(command, args)) else: if command == 'use': self.module_use(args) elif command == 'help' or command == '?': self.command_help() elif command == 'setg' and args: self.command_setg(args) elif command == 'unsetg' and args: self.command_unsetg(args) elif command == 'exit' or command == 'quit': sys.exit() elif command == 'exec' and args: self.command_exec(args) elif command == 'search' and args: self.command_search(args) elif command == 'list': self.command_modules_list() else: LOGGER.error('Unknow command: {0}.'.format(command + args))
async def send_request_cgi(self, method, url, **kwargs): kwargs.setdefault('timeout', self.http_timeout) kwargs.setdefault('headers', self.http_headers) kwargs.setdefault('verify_ssl', self.verify_ssl) kwargs.setdefault('allow_redirects', self.http_allow_redirects) kwargs.setdefault('proxy', self.proxy) # 连接数限制 禁止dns缓存 conn = aiohttp.TCPConnector(use_dns_cache=False) try: # async with asyncio.Semaphore(rate): async with aiohttp.ClientSession(connector=conn) as session: # async with aiohttp.ClientSession(connector=conn) as session: resp = await session.request(method, url, **kwargs) LOGGER.debug(f'Requests: {method} {url}', self.debug) text = await resp.text() content = await resp.read() stream_content = await resp.content.read() resp = { 'code': resp.status, 'text': text, 'content': content, 'url': resp.url, 'stream_content': stream_content, 'headers': resp.headers, 'cookie': resp.cookies } LOGGER.debug(http_response_style(resp['code'], resp['headers'], resp['text'], resp['content'], resp['stream_content']), self.debug) return resp except aiohttp.ClientConnectorError: LOGGER.error(f'{url} Error: ConnectionError') except aiohttp.ServerDisconnectedError: LOGGER.error(f'{url} Error: ServerDisconnectedError') except aiohttp.InvalidURL: LOGGER.error(f'Invalid URL format: {url}') except socket.error as e: LOGGER.warning(e) except KeyboardInterrupt: LOGGER.warning('Module has been stopped') except asyncio.TimeoutError as e: pass except Exception as e: LOGGER.exception(e) return None