|
""" |
|
Parsers for Vulnerability Intelligence Agent. |
|
This module contains parsers for different vulnerability data formats. |
|
""" |
|
import re |
|
from typing import Dict, List, Any, Optional |
|
|
|
class CWEParser: |
|
"""Parser for Common Weakness Enumeration (CWE) entries.""" |
|
|
|
@staticmethod |
|
def extract_cwe_from_cve(description: str) -> List[str]: |
|
""" |
|
Extract CWE IDs from a CVE description. |
|
|
|
Args: |
|
description: CVE description text |
|
|
|
Returns: |
|
List of CWE IDs found in the description |
|
""" |
|
|
|
pattern = r"CWE-(\d+)" |
|
matches = re.findall(pattern, description) |
|
|
|
|
|
cwe_ids = [f"CWE-{match}" for match in matches] |
|
|
|
return cwe_ids |
|
|
|
|
|
class NVDParser: |
|
"""Parser for National Vulnerability Database entries.""" |
|
|
|
@staticmethod |
|
def parse_nvd_api_response(response_json: Dict[str, Any], software: str, version: str) -> List[Dict[str, Any]]: |
|
""" |
|
Parse a response from the NVD API. |
|
|
|
Args: |
|
response_json: JSON response from NVD API |
|
software: Software name being searched |
|
version: Software version being searched |
|
|
|
Returns: |
|
List of parsed vulnerabilities |
|
""" |
|
|
|
return [] |
|
|
|
|
|
class CVEParser: |
|
"""Parser for Common Vulnerabilities and Exposures (CVE) entries.""" |
|
|
|
@staticmethod |
|
def parse_cve_data(html_content: str, software: str, version: str) -> List[Dict[str, Any]]: |
|
""" |
|
Parse CVE data from HTML content. |
|
|
|
Args: |
|
html_content: HTML content from the CVE website |
|
software: Software name being searched |
|
version: Software version being searched |
|
|
|
Returns: |
|
List of parsed vulnerabilities |
|
""" |
|
|
|
return [] |
|
|
|
|
|
class CISAParser: |
|
"""Parser for CISA Known Exploited Vulnerabilities (KEV) catalog entries.""" |
|
|
|
@staticmethod |
|
def parse_kev_data(json_data: Dict[str, Any], software: str, version: str) -> List[Dict[str, Any]]: |
|
""" |
|
Parse data from the CISA KEV catalog. |
|
|
|
Args: |
|
json_data: JSON data from the CISA KEV catalog |
|
software: Software name being searched |
|
version: Software version being searched |
|
|
|
Returns: |
|
List of parsed vulnerabilities |
|
""" |
|
|
|
return [] |