示例#1
0
    def _store_result_in_history(self):
        """存储模块运行结果到历史记录"""
        if self.MODULETYPE in [TAG2CH.internal]:
            return None
        opts = {}
        for key in self._custom_param:
            for option in self.OPTIONS:
                if option.get("name") == key:
                    if self._custom_param.get(key) is None:
                        continue
                    opts[option.get("name_tag")] = self._custom_param.get(key)

                    # 处理凭证,监听,文件等参数
                    try:
                        if key == HANDLER_OPTION.get("name"):
                            handler_dict = json.loads(
                                self._custom_param.get(key))
                            # 清理无效的参数
                            new_params = {
                                "PAYLOAD": handler_dict.get("PAYLOAD"),
                                "LPORT": handler_dict.get("LPORT")
                            }
                            if handler_dict.get("LHOST") is not None:
                                new_params["LHOST"] = handler_dict.get("LHOST")
                            if handler_dict.get("RHOST") is not None:
                                new_params["RHOST"] = handler_dict.get("RHOST")

                            opts[option.get("name_tag")] = json.dumps(
                                new_params)
                        elif key == FILE_OPTION.get("name"):
                            file_dict = json.loads(self._custom_param.get(key))
                            opts[option.get("name_tag")] = json.dumps({
                                "name":
                                file_dict.get("name"),
                            })
                        elif key == CREDENTIAL_OPTION.get("name"):
                            credential_dict = json.loads(
                                self._custom_param.get(key))
                            opts[option.get("name_tag")] = json.dumps({
                                "username":
                                credential_dict.get("username"),
                                "password":
                                credential_dict.get("password"),
                                "password_type":
                                credential_dict.get("password_type"),
                            })
                    except Exception as E:
                        logger.exception(E)
        module_result = Xcache.get_module_result(ipaddress=self.host_ipaddress,
                                                 loadpath=self.__module__)

        flag = Xcache.add_module_result_history(
            ipaddress=self.host_ipaddress,
            loadpath=self.__module__,
            opts=opts,
            update_time=module_result.get("update_time"),
            result=module_result.get("result"))
        return flag
示例#2
0
    def list(ipaddress=None, loadpath=None):
        result = Xcache.get_module_result(ipaddress=ipaddress,
                                          loadpath=loadpath)
        result_dict = {
            "ipaddress": ipaddress,
            "loadpath": loadpath,
            "update_time": result.get("update_time"),
            "result": result.get("result")
        }

        context = data_return(200, CODE_MSG.get(200), result_dict)
        return context
示例#3
0
    def list(hid=None, loadpath=None):
        host = Host.get_by_hid(hid)
        result = Xcache.get_module_result(ipaddress=host.get("ipaddress"),
                                          loadpath=loadpath)
        result_dict = {
            "hid": hid,
            "loadpath": loadpath,
            "update_time": result.get("update_time"),
            "result": result.get("result")
        }

        context = data_return(200, CODE_MSG.get(200), result_dict)
        return context