Exemplo n.º 1
0
    def delete_job_by_uuid(self, task_uuid=None):
        req = Xcache.get_module_task_by_uuid(task_uuid=task_uuid)
        Xcache.del_module_task_by_uuid(task_uuid=task_uuid)  # 清理缓存信息

        # 删除后台任务
        try:
            self.ModuleJobsScheduler.remove_job(task_uuid)
        except Exception as E:
            logger.error(E)

        try:
            module_common_instance = req.get("module")
        except Exception as E:
            logger.error(E)
            return False

        # 存储已经生成的结果
        try:
            module_common_instance.log_status("用户手动删除任务")
            module_common_instance._store_result_in_history()
        except Exception as E:
            logger.error("删除多模块实例异常:{} 异常信息: {}".format(module_common_instance.NAME, E))
            Notice.send_exception("模块: {} 执行异常,异常信息: {}".format(module_common_instance.NAME, E))
            logger.error(E)
            return False

        # 发送通知
        Notice.send_info(
            "模块: {} {} 手动删除".format(module_common_instance.NAME, module_common_instance.target_str))
        logger.warning("多模块实例手动删除:{}".format(module_common_instance.NAME))
        return True
Exemplo n.º 2
0
    def store_error_result(task_uuid=None, exception=None):
        req = Xcache.get_module_task_by_uuid(task_uuid=task_uuid)
        Xcache.del_module_task_by_uuid(task_uuid=task_uuid)  # 清理缓存信息
        module_common_instance = req.get("module")

        # 存储运行结果
        try:
            module_common_instance.log_except(exception)
            module_common_instance._store_result_in_history()
            logger.error("多模块实例执行异常:{} 异常信息: {}".format(module_common_instance.NAME, exception))
            Notice.send_exception("模块: {} 执行异常,异常信息: {}".format(module_common_instance.NAME, exception))
            return True
        except Exception as E:
            logger.error("多模块实例执行异常:{} 异常信息: {}".format(module_common_instance.NAME, E))
            Notice.send_exception("模块: {} 执行异常,异常信息: {}".format(module_common_instance.NAME, E))
            logger.error(E)
            return False
Exemplo n.º 3
0
    def store_executed_result(task_uuid=None):
        req = Xcache.get_module_task_by_uuid(task_uuid=task_uuid)
        if req is None:
            logger.warning("缓存中无对应实例,可能已经模块已经中途退出")
            return False
        module_common_instance = req.get("module")

        # 存储运行结果
        try:
            module_common_instance._store_result_in_history()
            Notice.send_success(
                "模块: {} {} 执行完成".format(module_common_instance.NAME, module_common_instance.target_str))
            logger.warning("多模块实例执行完成:{}".format(module_common_instance.NAME))
            Xcache.del_module_task_by_uuid(task_uuid=task_uuid)  # 清理缓存信息
            return True
        except Exception as E:
            Xcache.del_module_task_by_uuid(task_uuid=task_uuid)  # 清理缓存信息
            logger.error("多模块实例执行异常:{} 异常信息: {}".format(module_common_instance.NAME, E))
            Notice.send_exception("模块: {} 执行异常,异常信息: {}".format(module_common_instance.NAME, E))
            logger.error(E)
            return False
Exemplo n.º 4
0
    def call(method=None, params=None, timeout=11):
        _headers = {
            'Connection': 'keep-alive',
            'Content-Type': 'application/json',
            'Authorization': "Bearer {}".format(RPC_TOKEN),
        }

        data = {'jsonrpc': '2.0', 'id': 1, 'method': method}

        if params is not None:
            if isinstance(params, list):
                data['params'] = params
            else:
                logger.warning("params 必须是list类型")
                return None
        json_data = json.dumps(data)
        try:
            r = req_session.post(JSON_RPC_URL,
                                 headers=_headers,
                                 data=json_data,
                                 timeout=(1.05, timeout))
        except Exception as _:
            logger.warning('msf连接失败,检查 {} 是否可用'.format(JSON_RPC_URL))
            return None
        if r.status_code == 200:
            content = json.loads(r.content.decode('utf-8', 'ignore'))
            if content.get('error') is not None:
                logger.warning("错误码:{} 信息:{}".format(
                    content.get('error').get('code'),
                    content.get('error').get('message')))
                Notice.send_exception(
                    f"MSFRPC> {content.get('error').get('message')}")
                return None
            else:
                return content.get('result')

        else:
            logger.warning("返回码:{} 结果:{}".format(r.status_code, r.content))
            return None