Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added nvd_cve analyzer closes (#2245) #2560

Merged
merged 8 commits into from
Nov 11, 2024
14 changes: 13 additions & 1 deletion api_app/analyzers_manager/observable_analyzers/nvd_cve.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

import requests

from api_app.analyzers_manager.classes import AnalyzerRunException, ObservableAnalyzer
Expand All @@ -7,6 +9,7 @@
class NVDDetails(ObservableAnalyzer):
url: str = "https://services.nvd.nist.gov/rest/json/cves/2.0"
_nvd_api_key: str = None
cve_pattern = r"^CVE-\d{4}-\d{4,7}$"
spoiicy marked this conversation as resolved.
Show resolved Hide resolved

@classmethod
def update(self) -> bool:
Expand All @@ -16,10 +19,19 @@ def run(self):
headers = {}
if self._nvd_api_key:
headers.update({"apiKey": self._nvd_api_key})
params = {"cveId": self.observable_name}

try:
# Validate if CVE format is correct E.g CVE-2014-1234 or CVE-2022-1234567
if not re.match(self.cve_pattern, self.observable_name):
spoiicy marked this conversation as resolved.
Show resolved Hide resolved
raise ValueError(f"Invalid CVE format: {self.observable_name}")

params = {"cveId": self.observable_name}
response = requests.get(url=self.url, params=params, headers=headers)
response.raise_for_status()

except ValueError as e:
raise AnalyzerRunException(e)

except requests.RequestException as e:
raise AnalyzerRunException(e)

Expand Down
Loading