예제 #1
0
    def putin_post_python_module_queue(self, post_module_intent=None):
        try:
            # 存储uuid
            tmp_self_uuid = str(uuid.uuid1())

            # 清空历史记录
            post_module_intent.clean_log()

            logger.warning("模块放入列表:{} job_id: {} uuid: {}".format(post_module_intent.NAME, None, tmp_self_uuid))
            post_module_intent.module_self_uuid = tmp_self_uuid
            self.ModuleJobsScheduler.add_job(func=post_module_intent._thread_run, max_instances=1, id=tmp_self_uuid)

            # 放入缓存队列,用于后续删除任务,存储结果等
            req = {
                'broker': post_module_intent.MODULE_BROKER,
                'uuid': tmp_self_uuid,
                'module': post_module_intent,
                'time': int(time.time()),
                'job_id': None,
            }
            Xcache.create_module_task(req)
            Notice.send_info(
                "模块: {} {} 开始执行".format(post_module_intent.NAME, post_module_intent.target_str))
            return True
        except Exception as E:
            logger.error(E)
            return False
예제 #2
0
    def putin_post_msf_module_queue(msf_module=None):
        """调用msgrpc生成job,放入列表"""

        params = [
            msf_module.type,
            msf_module.mname,
            msf_module.opts,
            True,  # 强制设置后台运行
            0  # 超时时间
        ]

        result = RpcClient.call(Method.ModuleExecute, params)
        if result is None:
            Notice.send_warning(f"渗透服务连接失败,无法执行模块 :{msf_module.NAME}")
            return False
        elif result == "license expire":
            Notice.send_warning(f"License 过期,无法执行模块 :{msf_module.NAME}")
            return False

        # result 数据格式
        # {'job_id': 3, 'uuid': 'dbcb2530-95b1-0137-5100-000c2966078a', 'module': b'\x80\ub.'}

        if result.get("job_id") is None:
            logger.warning("模块实例:{} uuid: {} 创建后台任务失败".format(
                msf_module.NAME, result.get("uuid")))
            Notice.send_warning("模块: {} {} 创建后台任务失败,请检查输入参数".format(
                msf_module.NAME, msf_module.target_str))
            return False
        else:
            logger.warning("模块实例放入列表:{} job_id: {} uuid: {}".format(
                msf_module.NAME, result.get("job_id"), result.get("uuid")))
            # 放入请求队列
            req = {
                'broker': msf_module.MODULE_BROKER,
                'uuid': result.get("uuid"),
                'module': msf_module,
                'time': int(time.time()),
                'job_id': result.get("job_id"),
            }
            Xcache.create_module_task(req)
            Notice.send_info("模块: {} {} 开始执行".format(msf_module.NAME,
                                                     msf_module.target_str))
            return True