Ejemplo n.º 1
0
 def list(self, request, **kwargs):
     try:
         context = Credential.list()
     except Exception as E:
         logger.error(E)
         context = data_return(500, CODE_MSG.get(500), [])
     return Response(context)
Ejemplo n.º 2
0
 def destroy(self, request, pk=None, **kwargs):
     try:
         cid = int(request.query_params.get('id', None))
         context = Credential.destory(cid=cid)
     except Exception as E:
         logger.error(E)
         context = data_return(500, CODE_MSG.get(500), {})
     return Response(context)
Ejemplo n.º 3
0
    def update(self, request, pk=None, **kwargs):

        try:
            cid = int(request.data.get('id', None))
            desc = request.data.get('desc', None)
            context = Credential.update(cid, desc)
        except Exception as E:
            logger.error(E)
            context = data_return(500, CODE_MSG.get(500), {})
        return Response(context)
Ejemplo n.º 4
0
    def add_credential(self,
                       username='',
                       password='',
                       password_type='',
                       tag=None,
                       desc=''):
        if tag is None:
            tag = {}
        if isinstance(tag, dict) is not True:
            logger.warning('数据类型检查错误,数据 {}'.format(tag))
            tag = {}
        if password is '' or password.find('n.a.(') > 0 or len(password) > 100:
            return False

        result = Credential.add_or_update(username, password, password_type,
                                          tag, self.NAME, self.host_ipaddress,
                                          desc)
        return result
Ejemplo n.º 5
0
    def create(self, request, **kwargs):
        try:
            username = str(request.data.get('username', ""))
            password = str(request.data.get('password', ""))
            windows_domain = request.data.get('windows-domain', None)
            windows_type = request.data.get('windows-type', None)
            if windows_domain and windows_type:
                # windows类型凭证
                tag = {'domain': windows_domain, 'type': windows_type}
                password_type = "windows"
            else:
                tag = {}
                password_type = "userinput"

            source_module = "用户手工输入"
            context = Credential.create(username, password, password_type,
                                        source_module, tag)
        except Exception as E:
            logger.error(E)
            context = data_return(500, CODE_MSG.get(500), {})
        return Response(context)
Ejemplo n.º 6
0
    def _deal_dynamic_option(one_module_config=None):
        """处理handler及凭证等动态变化参数,返回处理后参数列表"""
        options = one_module_config.get('OPTIONS')
        for option in options:
            # handler处理
            if option.get('name') == HANDLER_OPTION.get("name"):
                option['enum_list'] = Handler.list_handler_config()
                if len(option['enum_list']) == 1:  # 只有一个监听
                    option['default'] = option['enum_list'][0].get("value")

            # 凭证处理
            elif option.get('name') == CREDENTIAL_OPTION.get("name"):
                credentials = Credential.list_credential()
                tmp_enum_list = []
                try:
                    if option.get('extra_data') is None or option.get(
                            'extra_data').get('password_type') is None:
                        pass
                    else:
                        type_list = option.get('extra_data').get(
                            'password_type')
                        for credential in credentials:
                            if credential.get('password_type') in type_list:
                                name = "用户名:{} | 密码:{} | 标签:{} | 主机:{}".format(
                                    credential.get('username'),
                                    credential.get('password'),
                                    credential.get('tag'),
                                    credential.get('host_ipaddress'))
                                import json
                                value = json.dumps(credential)
                                tmp_enum_list.append({
                                    'name': name,
                                    'value': value
                                })
                    option['enum_list'] = tmp_enum_list
                except Exception as E:
                    logger.warning(E)
            # 文件处理
            elif option.get('name') == FILE_OPTION.get("name"):
                if option.get('extra_data') is None or option.get(
                        'extra_data').get('file_extension') is None:
                    file_extension_list = None
                else:
                    file_extension_list = option.get('extra_data').get(
                        'file_extension')

                files = FileMsf.list_msf_files()
                tmp_enum_list = []
                for file in files:
                    import json
                    # {
                    #     "filename": "test",
                    #     "filesize": 0,
                    #     "mtime": 1552273961
                    # },
                    name = file.get("name")
                    size = FileSession.get_size_in_nice_string(
                        file.get('size'))
                    mtime = file.get("mtime")
                    style_time = time.strftime("%Y-%m-%d %H:%M:%S",
                                               time.localtime(mtime))
                    show = False  # 是否满足文件后缀要求
                    if isinstance(file_extension_list, list):
                        for ext in file_extension_list:
                            if name.lower().endswith(ext.lower()):
                                show = True
                    else:
                        show = True
                    if show:
                        name = "文件: {}   大小: {}   修改时间: {}".format(
                            name, size, style_time)
                        value = json.dumps(file)
                        tmp_enum_list.append({'name': name, 'value': value})
                option['enum_list'] = tmp_enum_list
        return one_module_config