feat(feed): add NVD CVE feed connector (recent CVEs, NVD 2.0 API)
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
id: feed_nvd
|
||||
name: NVD CVE Feed
|
||||
version: 1.0.0
|
||||
description: "NIST National Vulnerability Database (NVD) feed connector — pull recently-published CVEs from the NVD 2.0 API and emit normalized IOCs (CVE + type, with description/CVSS/status) for import into the Threat Indicator Manager. Works without a key; an optional free NVD API key raises the rate limit. Stdlib-only, no extra Python dependencies."
|
||||
changelog: "1.0.0 — Initial release: fetch recent CVEs from the NVD 2.0 API."
|
||||
category: feed
|
||||
|
||||
# The NVD 2.0 API is free. An optional API key (sent as the apiKey header)
|
||||
# raises the request rate limit.
|
||||
config_schema:
|
||||
properties:
|
||||
api_key:
|
||||
type: string
|
||||
description: "Optional NVD API key (free — raises the rate limit)"
|
||||
x-soar-sensitive: true
|
||||
days:
|
||||
type: number
|
||||
description: "Look-back window in days for recently-published CVEs (default 7, max 120)"
|
||||
default: 7
|
||||
insecure:
|
||||
type: boolean
|
||||
description: "Trust any TLS certificate (not secure)"
|
||||
default: false
|
||||
required: []
|
||||
|
||||
commands:
|
||||
- id: fetch_indicators
|
||||
name: feed-nvd-fetch-indicators
|
||||
description: "Fetch recently-published CVEs from NVD and return normalized indicators."
|
||||
risk: read
|
||||
inputs_schema:
|
||||
properties:
|
||||
days: { type: number, description: "Look-back window in days (overrides config, max 120)" }
|
||||
max_indicators: { type: number, description: "Max indicators to return (0 = API page size 2000, default 0)" }
|
||||
required: []
|
||||
outputs_schema: { properties: {} }
|
||||
|
||||
- id: test_connection
|
||||
name: feed-nvd-test-connection
|
||||
description: "Verify the NVD API is reachable (used by the Test button)."
|
||||
risk: read
|
||||
inputs_schema:
|
||||
properties: {}
|
||||
required: []
|
||||
outputs_schema: { properties: {} }
|
||||
@@ -0,0 +1,110 @@
|
||||
import json, os, sys, ssl, datetime, urllib.parse, urllib.request, urllib.error
|
||||
|
||||
BASE = "https://services.nvd.nist.gov/rest/json/cves/2.0"
|
||||
|
||||
|
||||
def _cfg():
|
||||
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||
|
||||
|
||||
def _inputs():
|
||||
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||
|
||||
|
||||
def _ctx(cfg):
|
||||
if cfg.get("insecure"):
|
||||
c = ssl.create_default_context()
|
||||
c.check_hostname = False
|
||||
c.verify_mode = ssl.CERT_NONE
|
||||
return c
|
||||
return None
|
||||
|
||||
|
||||
def _headers(cfg):
|
||||
h = {"User-Agent": "Riposte-SOAR", "Accept": "application/json"}
|
||||
k = cfg.get("api_key")
|
||||
if k:
|
||||
h["apiKey"] = str(k)
|
||||
return h
|
||||
|
||||
|
||||
def _get(url, cfg):
|
||||
req = urllib.request.Request(url, headers=_headers(cfg))
|
||||
with urllib.request.urlopen(req, timeout=120, context=_ctx(cfg)) as r:
|
||||
return r.read()
|
||||
|
||||
|
||||
def _run(fn):
|
||||
try:
|
||||
print(json.dumps(fn(_cfg(), _inputs())))
|
||||
except urllib.error.HTTPError as e:
|
||||
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": str(e)}))
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def _cvss(metrics):
|
||||
for key in ("cvssMetricV31", "cvssMetricV30", "cvssMetricV2"):
|
||||
arr = metrics.get(key)
|
||||
if arr and isinstance(arr, list) and isinstance(arr[0], dict):
|
||||
d = arr[0].get("cvssData", {})
|
||||
return d.get("baseScore"), d.get("baseSeverity") or arr[0].get("baseSeverity")
|
||||
return None, None
|
||||
|
||||
|
||||
def main(cfg, inputs):
|
||||
days = int(inputs.get("days") or cfg.get("days") or 7)
|
||||
days = max(1, min(days, 120))
|
||||
|
||||
end = datetime.datetime.now(datetime.timezone.utc)
|
||||
start = end - datetime.timedelta(days=days)
|
||||
fmt = "%Y-%m-%dT%H:%M:%S.000"
|
||||
|
||||
per = int(inputs.get("max_indicators") or 0) or 2000
|
||||
per = max(1, min(per, 2000))
|
||||
|
||||
params = {
|
||||
"pubStartDate": start.strftime(fmt),
|
||||
"pubEndDate": end.strftime(fmt),
|
||||
"resultsPerPage": per,
|
||||
}
|
||||
url = BASE + "?" + urllib.parse.urlencode(params)
|
||||
raw = _get(url, cfg)
|
||||
data = json.loads(raw) if raw else {}
|
||||
|
||||
maxn = int(inputs.get("max_indicators") or 0)
|
||||
out = []
|
||||
for v in data.get("vulnerabilities", []):
|
||||
cve = v.get("cve", {}) if isinstance(v, dict) else {}
|
||||
cid = cve.get("id")
|
||||
if not cid:
|
||||
continue
|
||||
desc = ""
|
||||
for d in cve.get("descriptions", []):
|
||||
if d.get("lang") == "en":
|
||||
desc = d.get("value")
|
||||
break
|
||||
score, severity = _cvss(cve.get("metrics", {}))
|
||||
out.append({
|
||||
"value": cid,
|
||||
"type": "cve",
|
||||
"description": desc,
|
||||
"cvss": score,
|
||||
"severity": severity,
|
||||
"published": cve.get("published"),
|
||||
"status": cve.get("vulnStatus"),
|
||||
})
|
||||
if maxn and len(out) >= maxn:
|
||||
break
|
||||
|
||||
return {
|
||||
"source": "nvd:recent",
|
||||
"count": len(out),
|
||||
"indicators": out,
|
||||
"total_results": data.get("totalResults"),
|
||||
}
|
||||
|
||||
|
||||
_run(main)
|
||||
@@ -0,0 +1,55 @@
|
||||
import json, os, sys, ssl, urllib.parse, urllib.request, urllib.error
|
||||
|
||||
BASE = "https://services.nvd.nist.gov/rest/json/cves/2.0"
|
||||
|
||||
|
||||
def _cfg():
|
||||
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||
|
||||
|
||||
def _inputs():
|
||||
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||
|
||||
|
||||
def _ctx(cfg):
|
||||
if cfg.get("insecure"):
|
||||
c = ssl.create_default_context()
|
||||
c.check_hostname = False
|
||||
c.verify_mode = ssl.CERT_NONE
|
||||
return c
|
||||
return None
|
||||
|
||||
|
||||
def _headers(cfg):
|
||||
h = {"User-Agent": "Riposte-SOAR", "Accept": "application/json"}
|
||||
k = cfg.get("api_key")
|
||||
if k:
|
||||
h["apiKey"] = str(k)
|
||||
return h
|
||||
|
||||
|
||||
def _get(url, cfg):
|
||||
req = urllib.request.Request(url, headers=_headers(cfg))
|
||||
with urllib.request.urlopen(req, timeout=60, context=_ctx(cfg)) as r:
|
||||
return r.read()
|
||||
|
||||
|
||||
def _run(fn):
|
||||
try:
|
||||
print(json.dumps(fn(_cfg(), _inputs())))
|
||||
except urllib.error.HTTPError as e:
|
||||
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": str(e)}))
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def main(cfg, inputs):
|
||||
url = BASE + "?" + urllib.parse.urlencode({"resultsPerPage": 1})
|
||||
raw = _get(url, cfg)
|
||||
data = json.loads(raw) if raw else {}
|
||||
return {"ok": True, "total_results": data.get("totalResults")}
|
||||
|
||||
|
||||
_run(main)
|
||||
Reference in New Issue
Block a user