コード例 #1
0
    def get_nvt_refs(self, oid: str) -> Optional[Dict[str, str]]:
        """Get a full NVT.

        Arguments:
            oid: OID of VT from which to get the VT references.

        Returns:
            A dictionary with the VT references.
        """
        resp = OpenvasDB.get_list_item(
            self.ctx,
            "nvt:%s" % oid,
            start=NVT_META_FIELDS.index("NVT_CVES_POS"),
            end=NVT_META_FIELDS.index("NVT_XREFS_POS"),
        )

        if not isinstance(resp, list) or len(resp) == 0:
            return None

        subelem = ['cve', 'bid', 'xref']

        refs = dict()
        for child, res in zip(subelem, resp):
            refs[child] = res.split(", ")

        return refs
コード例 #2
0
ファイル: nvticache.py プロジェクト: benhe119/ospd-openvas
    def get_nvt_refs(self, oid):
        """ Get a full NVT.
        Arguments:
            oid (str) OID of VT from which to get the VT references.
        Returns:
            dict: A dictionary with the VT references.
        """
        ctx = self._openvas_db.get_kb_context()
        resp = self._openvas_db.get_list_item(
            "nvt:%s" % oid,
            ctx=ctx,
            start=NVT_META_FIELDS.index("NVT_CVES_POS"),
            end=NVT_META_FIELDS.index("NVT_XREFS_POS"),
        )

        if not isinstance(resp, list) or len(resp) == 0:
            return None

        subelem = ['cve', 'bid', 'xref']

        refs = dict()
        for child, res in zip(subelem, resp):
            refs[child] = res.split(", ")

        return refs
コード例 #3
0
    def get_nvt_metadata(self, oid: str) -> Optional[Dict[str, str]]:
        """Get a full NVT. Returns an XML tree with the NVT metadata.

        Arguments:
            oid: OID of VT from which to get the metadata.

        Returns:
            A dictionary with the VT metadata.
        """
        resp = OpenvasDB.get_list_item(
            self.ctx,
            f"nvt:{oid}",
            start=NVT_META_FIELDS.index("NVT_FILENAME_POS"),
            end=NVT_META_FIELDS.index("NVT_NAME_POS"),
        )

        if not isinstance(resp, list) or len(resp) == 0:
            return None

        subelem = [
            'filename',
            'required_keys',
            'mandatory_keys',
            'excluded_keys',
            'required_udp_ports',
            'required_ports',
            'dependencies',
            'tag',
            'cve',
            'bid',
            'xref',
            'category',
            'family',
            'name',
        ]

        custom = dict()
        custom['refs'] = dict()
        for child, res in zip(subelem, resp):
            if child not in ['cve', 'bid', 'xref', 'tag'] and res:
                custom[child] = res
            elif child == 'tag':
                custom.update(self._parse_metadata_tags(res, oid))
            elif child in ['cve', 'bid', 'xref'] and res:
                custom['refs'][child] = res.split(", ")

        custom['vt_params'] = dict()
        custom['vt_params'].update(self.get_nvt_params(oid))

        return custom
コード例 #4
0
ファイル: nvticache.py プロジェクト: benhe119/ospd-openvas
    def get_nvt_metadata(self, oid):
        """ Get a full NVT. Returns an XML tree with the NVT metadata.
        Arguments:
            oid (str) OID of VT from which to get the metadata.
        Returns:
            dict: A dictonary with the VT metadata.
        """
        ctx = self._openvas_db.get_kb_context()
        resp = self._openvas_db.get_list_item(
            "nvt:%s" % oid,
            ctx=ctx,
            start=NVT_META_FIELDS.index("NVT_FILENAME_POS"),
            end=NVT_META_FIELDS.index("NVT_NAME_POS"),
        )

        if not isinstance(resp, list) or len(resp) == 0:
            return None

        subelem = [
            'filename',
            'required_keys',
            'mandatory_keys',
            'excluded_keys',
            'required_udp_ports',
            'required_ports',
            'dependencies',
            'tag',
            'cve',
            'bid',
            'xref',
            'category',
            'timeout',
            'family',
            'name',
        ]

        custom = dict()
        for child, res in zip(subelem, resp):
            if child not in ['cve', 'bid', 'xref', 'tag'] and res:
                custom[child] = res
            elif child == 'tag':
                custom.update(self._parse_metadata_tags(res, oid))

        return custom
コード例 #5
0
    def get_nvt_family(self, oid: str) -> str:
        """Get NVT family
        Arguments:
            oid: OID of VT from which to get the VT family.

        Returns:
            A str with the VT family.
        """
        return OpenvasDB.get_single_item(
            self.ctx,
            'nvt:%s' % oid,
            index=NVT_META_FIELDS.index("NVT_FAMILY_POS"),
        )
コード例 #6
0
    def get_nvt_tag(self, ctx, oid):
        """ Get Tags of the given OID.
        Arguments:
            ctx (object): Redis context to be used.
            oid (str) OID of VT from which to get the VT tags.
        Returns:
            dict: A dictionary with the VT tags.
        """
        tag = self._openvas_db.get_single_item(
            'nvt:%s' % oid, ctx=ctx, index=NVT_META_FIELDS.index('NVT_TAGS_POS')
        )
        tags = tag.split('|')

        return dict([item.split('=', 1) for item in tags])
コード例 #7
0
ファイル: nvticache.py プロジェクト: benhe119/ospd-openvas
    def get_nvt_timeout(self, ctx, oid):
        """ Get NVT timeout
        Arguments:
            ctx (object): Redis context to be used.
            oid (str) OID of VT from which to get the script timeout.
        Returns:
            str: The timeout.
        """
        timeout = self._openvas_db.get_single_item(
            'nvt:%s' % oid,
            ctx=ctx,
            index=NVT_META_FIELDS.index("NVT_TIMEOUT_POS"),
        )

        return timeout
コード例 #8
0
    def get_nvt_timeout(self, oid: str) -> Optional[str]:
        """Get NVT timeout

        Arguments:
            ctx: Redis context to be used.
            oid: OID of VT from which to get the script timeout.

        Returns:
            The timeout.
        """
        return OpenvasDB.get_single_item(
            self.ctx,
            'nvt:%s' % oid,
            index=NVT_META_FIELDS.index("NVT_TIMEOUT_POS"),
        )
コード例 #9
0
    def get_nvt_family(self, oid: str) -> Optional[str]:
        """Get NVT family
        Arguments:
            oid: OID of VT from which to get the VT family.

        Returns:
            A str with the VT family.
        """
        notus_entry = self.notus.get_nvt_metadata(oid) if self.notus else None
        if notus_entry:
            return notus_entry.get("family")

        return OpenvasDB.get_single_item(
            self.ctx,
            f"nvt:{oid}",
            index=NVT_META_FIELDS.index("NVT_FAMILY_POS"),
        )
コード例 #10
0
    def get_nvt_tags(self, oid: str) -> Optional[Dict[str, str]]:
        """Get Tags of the given OID.

        Arguments:
            ctx: Redis context to be used.
            oid: OID of VT from which to get the VT tags.

        Returns:
            A dictionary with the VT tags.
        """
        tag = OpenvasDB.get_single_item(
            self.ctx,
            'nvt:%s' % oid,
            index=NVT_META_FIELDS.index('NVT_TAGS_POS'),
        )
        tags = tag.split('|')

        return dict([item.split('=', 1) for item in tags])