From 78fd620ec816a21ca797adb3c8c5389a5809d4bc Mon Sep 17 00:00:00 2001
From: Alexandre Dulaunoy
Date: Thu, 29 Oct 2026 18:07:22 +0100
Subject: [PATCH 1/2] feat: [greynoise_vuln] add dedicated CVE intelligence
lookups
---
documentation/expansion/greynoise_vuln.md | 11 ++
.../modules/expansion/greynoise_vuln.py | 165 ++++++++++++++++++
tests/test_greynoise_vuln.py | 105 +++++++++++
3 files changed, 281 insertions(+)
create mode 100644 documentation/expansion/greynoise_vuln.md
create mode 100644 misp_modules/modules/expansion/greynoise_vuln.py
create mode 100644 tests/test_greynoise_vuln.py
diff --git a/documentation/expansion/greynoise_vuln.md b/documentation/expansion/greynoise_vuln.md
new file mode 100644
index 00000000..9358d247
--- /dev/null
+++ b/documentation/expansion/greynoise_vuln.md
@@ -0,0 +1,11 @@
+# GreyNoise Vulnerability Intelligence
+
+Retrieve dedicated GreyNoise CVE intelligence, including available exploitation activity, exploit counts, product details and prioritization fields. Provider fields are preserved in a referenced annotation. Coverage depends on the API key entitlement. An absent CVE returns no enrichment and does not imply no exploitation.
+
+Input: vulnerability.
+
+Configuration: api_key, max_results. Required: api_key.
+
+max_results defaults to 25 and accepts 1–100. New attributes use `to_ids=false`; the source UUID, detection flag and metadata are preserved. Objects reference the source attribute. Requests verify TLS, reject redirects and use connection/read timeouts of 5/30 seconds. API errors do not echo credentials. No automatic submission retries or background polling occur.
+
+Reference: https://docs.greynoise.io/reference/getcve
diff --git a/misp_modules/modules/expansion/greynoise_vuln.py b/misp_modules/modules/expansion/greynoise_vuln.py
new file mode 100644
index 00000000..4027a6c3
--- /dev/null
+++ b/misp_modules/modules/expansion/greynoise_vuln.py
@@ -0,0 +1,165 @@
+import ipaddress
+import json
+import re
+import zipfile
+from uuid import UUID
+import requests
+from pymisp import MISPEvent, MISPObject
+from pymisp.exceptions import PyMISPError
+
+
+class ModuleError(ValueError):
+ """A diagnostic safe to show to the analyst."""
+
+
+def _integer(config, key, default, maximum=100):
+ value = config.get(key)
+ if value is None or value == "":
+ return default
+ if isinstance(value, bool) or not str(value).isdigit() or (not 1 <= int(value) <= maximum):
+ raise ModuleError(f"{key} must be an integer between 1 and {maximum}.")
+ return int(value)
+
+
+def _normalise(kind, value):
+ if not isinstance(value, str) or not value.strip() or any(ord(c) < 32 for c in value):
+ raise ModuleError("A nonempty string value is required.")
+ value = value.strip()
+ if kind in ("md5", "sha1", "sha256", "x509-fingerprint-sha256"):
+ length = {"md5": 32, "sha1": 40}.get(kind, 64)
+ if not re.fullmatch("[a-fA-F0-9]{%d}" % length, value):
+ raise ModuleError("Invalid hash.")
+ return value.lower()
+ if kind in ("ip-src", "ip-dst"):
+ return str(ipaddress.ip_address(value))
+ if kind in ("domain", "hostname"):
+ value = value.rstrip(".").encode("idna").decode("ascii").lower()
+ if len(value) > 253 or not all(
+ re.fullmatch("[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?", p) for p in value.split(".")
+ ):
+ raise ModuleError("Invalid DNS name.")
+ if kind == "vulnerability":
+ value = value.upper()
+ if not re.fullmatch("CVE-[0-9]{4}-[0-9]{4,}", value):
+ raise ModuleError("A CVE identifier is required.")
+ return value
+
+
+def _call(method, url, **kwargs):
+ try:
+ response = requests.request(method, url, timeout=(5, 30), verify=True, allow_redirects=False, **kwargs)
+ except requests.RequestException:
+ raise ModuleError(
+ "The service request failed or timed out; check the service before repeating a submission."
+ ) from None
+ if response.status_code in (204, 404) and method == "GET":
+ return None
+ if response.status_code not in (200, 201, 202):
+ raise ModuleError(f"The service returned HTTP {response.status_code}.")
+ try:
+ return response.json()
+ except ValueError:
+ raise ModuleError("The service returned invalid JSON.") from None
+
+
+def _object(event, attribute, name):
+ obj = MISPObject(name)
+ obj.add_reference(attribute["uuid"], "describes")
+ event.add_object(obj)
+ return obj
+
+
+def _annotation(event, attribute, title, data):
+ obj = _object(event, attribute, "annotation")
+ obj.comment = title
+ obj.add_attribute("text", value=json.dumps(data, sort_keys=True), to_ids=False, disable_correlation=True)
+ return obj
+
+
+def handler(q=False):
+ if q is False:
+ return False
+ try:
+ request = json.loads(q)
+ if not isinstance(request, dict) or not isinstance(request.get("attribute"), dict):
+ raise ModuleError("An attribute containing type, value and uuid is required.")
+ attribute = request["attribute"]
+ UUID(attribute["uuid"])
+ if attribute["type"] not in mispattributes["input"]:
+ raise ModuleError("Unsupported attribute type.")
+ value = _normalise(attribute["type"], attribute["value"])
+ config = request.get("config") or {}
+ if not isinstance(config, dict):
+ raise ModuleError("The config must be an object.")
+ for key in REQUIRED:
+ if not isinstance(config.get(key), str) or not config[key].strip():
+ raise ModuleError(f"Missing {key} configuration.")
+ limit = _integer(config, "max_results", 25)
+ event = MISPEvent()
+ event.add_attribute(**attribute)
+ _expand(event, attribute, value, config, limit)
+ result = json.loads(event.to_json())
+ return {"results": {key: result.get(key, []) for key in ("Attribute", "Object")}}
+ except ModuleError as exc:
+ return {"error": str(exc)}
+ except (
+ ValueError,
+ TypeError,
+ KeyError,
+ AttributeError,
+ IndexError,
+ OSError,
+ RuntimeError,
+ zipfile.BadZipFile,
+ PyMISPError,
+ ):
+ return {"error": "Invalid request or service response."}
+
+
+def introspection():
+ return mispattributes
+
+
+def version():
+ return dict(moduleinfo, config=moduleconfig)
+
+
+moduleinfo = {
+ "version": "1.0",
+ "author": "MISP Project",
+ "name": "GreyNoise Vulnerability Intelligence",
+ "description": (
+ "Retrieve dedicated GreyNoise CVE intelligence, including available exploitation activity, exploit counts,"
+ " product details and prioritization fields. Provider fields are preserved in a referenced annotation. Coverage"
+ " depends on the API key entitlement. An absent CVE returns no enrichment and does not imply no exploitation."
+ ),
+ "module-type": ["expansion"],
+ "data-source": "external",
+ "logo": "",
+ "requirements": ["requests", "pymisp"],
+ "features": (
+ "Retrieve dedicated GreyNoise CVE intelligence, including available exploitation activity, exploit counts,"
+ " product details and prioritization fields. Provider fields are preserved in a referenced annotation. Coverage"
+ " depends on the API key entitlement. An absent CVE returns no enrichment and does not imply no exploitation."
+ ),
+ "references": ["https://docs.greynoise.io/reference/getcve"],
+ "input": "vulnerability",
+ "output": "MISP objects linked to the original attribute.",
+}
+mispattributes = {"input": ["vulnerability"], "format": "misp_standard"}
+moduleconfig = ["api_key", "max_results"]
+REQUIRED = ["api_key"]
+
+
+def _expand(event, attribute, value, config, limit):
+ data = _call(
+ "GET",
+ "https://api.greynoise.io/v1/cve/" + value,
+ headers={"key": config["api_key"], "Accept": "application/json"},
+ )
+ if data is None:
+ return
+ if not isinstance(data, dict):
+ raise ModuleError("GreyNoise returned invalid vulnerability data.")
+ if data:
+ _annotation(event, attribute, moduleinfo["name"], data)
diff --git a/tests/test_greynoise_vuln.py b/tests/test_greynoise_vuln.py
new file mode 100644
index 00000000..929b7839
--- /dev/null
+++ b/tests/test_greynoise_vuln.py
@@ -0,0 +1,105 @@
+import json
+from unittest.mock import Mock, patch
+
+import pytest
+import requests
+
+from misp_modules.modules.expansion import greynoise_vuln as module
+
+UUID = "32876e4a-916d-4935-9e51-7b69a76718f8"
+SECRET = "test-service-secret"
+
+
+def query(kind=None, value="example.com", config=None, **attribute_fields):
+ attribute = {
+ "type": kind or module.mispattributes["input"][0],
+ "value": value,
+ "uuid": UUID,
+ "to_ids": True,
+ "comment": "source context",
+ **attribute_fields,
+ }
+ return json.dumps(
+ {"attribute": attribute, "config": config if config is not None else {k: SECRET for k in module.REQUIRED}}
+ )
+
+
+def reply(payload=None, status=200):
+ return Mock(status_code=status, headers={}, json=Mock(return_value=payload))
+
+
+def assert_source(result):
+ assert "results" in result, result
+ source = next(a for a in result["results"]["Attribute"] if a["uuid"] == UUID)
+ assert source["to_ids"] is True
+ assert source["comment"] == "source context"
+ for obj in result["results"]["Object"]:
+ assert any(r["referenced_uuid"] == UUID for r in obj["ObjectReference"])
+ assert all(a["to_ids"] is False for a in obj["Attribute"])
+
+
+def objects(result, name):
+ return [obj for obj in result["results"]["Object"] if obj["name"] == name]
+
+
+def values(obj, relation):
+ return [a["value"] for a in obj["Attribute"] if a["object_relation"] == relation]
+
+
+def test_discovery():
+ assert module.handler(False) is False
+ assert module.introspection()["format"] == "misp_standard"
+ assert module.version()["config"] == module.moduleconfig
+
+
+@pytest.mark.parametrize("raw", ["{", "[]", "null", "{}", '{"attribute": []}'])
+def test_invalid_envelope(raw):
+ with patch.object(module.requests, "request") as request:
+ assert "error" in module.handler(raw)
+ request.assert_not_called()
+
+
+@pytest.mark.parametrize("status", [301, 401, 403, 429, 503])
+def test_http_errors_are_sanitized(status):
+ with patch.object(module.requests, "request", return_value=reply({"error": SECRET}, status)):
+ with pytest.raises(module.ModuleError) as failure:
+ module._call("GET", "https://service.example/report")
+ assert str(status) in str(failure.value)
+ assert SECRET not in str(failure.value)
+
+
+def test_timeout_is_bounded_and_sanitized():
+ with patch.object(module.requests, "request", side_effect=requests.Timeout(SECRET)) as request:
+ with pytest.raises(module.ModuleError) as failure:
+ module._call("POST", "https://service.example/submit")
+ assert SECRET not in str(failure.value)
+ assert request.call_count == 1
+ assert request.call_args.kwargs["verify"] is True
+ assert request.call_args.kwargs["allow_redirects"] is False
+ assert request.call_args.kwargs["timeout"] == (5, 30)
+
+
+@pytest.mark.parametrize("raw", [0, -1, True, "bad", 101])
+def test_invalid_result_limit(raw):
+ with pytest.raises(module.ModuleError):
+ module._integer({"max_results": raw}, "max_results", 25)
+
+
+def test_cve_details_keep_zero_and_false():
+ data = {
+ "exploitation_activity": {"activity_seen": False},
+ "exploitation_stats": {"number_of_available_exploits": 0},
+ "details": {"cve_id": "CVE-2024-1234"},
+ }
+ with patch.object(module.requests, "request", return_value=reply(data)) as request:
+ result = module.handler(query(kind="vulnerability", value="cve-2024-1234"))
+ assert_source(result)
+ assert request.call_args.args[1].endswith("/CVE-2024-1234")
+ assert json.loads(values(objects(result, "annotation")[0], "text")[0]) == data
+
+
+def test_unknown_cve_is_not_a_benign_assertion():
+ with patch.object(module.requests, "request", return_value=reply(status=404)):
+ result = module.handler(query(kind="vulnerability", value="CVE-2024-1234"))
+ assert_source(result)
+ assert not result["results"]["Object"]
From 4930d91a8a3fa0ec523639d5ec860aef4c20df84 Mon Sep 17 00:00:00 2001
From: Alexandre Dulaunoy
Date: Thu, 29 Oct 2026 23:23:15 +0100
Subject: [PATCH 2/2] fix: [greynoise_vuln] address review findings
---
documentation/expansion/greynoise_vuln.md | 6 ++++--
misp_modules/modules/expansion/greynoise_vuln.py | 4 ++--
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/documentation/expansion/greynoise_vuln.md b/documentation/expansion/greynoise_vuln.md
index 9358d247..82e38938 100644
--- a/documentation/expansion/greynoise_vuln.md
+++ b/documentation/expansion/greynoise_vuln.md
@@ -4,8 +4,10 @@ Retrieve dedicated GreyNoise CVE intelligence, including available exploitation
Input: vulnerability.
-Configuration: api_key, max_results. Required: api_key.
+Configuration: api_key. Required: api_key.
-max_results defaults to 25 and accepts 1–100. New attributes use `to_ids=false`; the source UUID, detection flag and metadata are preserved. Objects reference the source attribute. Requests verify TLS, reject redirects and use connection/read timeouts of 5/30 seconds. API errors do not echo credentials. No automatic submission retries or background polling occur.
+New attributes use `to_ids=false`; the source UUID, detection flag and metadata are preserved. Objects reference the source attribute. Requests verify TLS, reject redirects and use connection/read timeouts of 5/30 seconds. API errors do not echo credentials. No automatic submission retries or background polling occur.
Reference: https://docs.greynoise.io/reference/getcve
+
+One complete provider report is retained per lookup; there is no result-count setting.
diff --git a/misp_modules/modules/expansion/greynoise_vuln.py b/misp_modules/modules/expansion/greynoise_vuln.py
index 4027a6c3..b2d68ec1 100644
--- a/misp_modules/modules/expansion/greynoise_vuln.py
+++ b/misp_modules/modules/expansion/greynoise_vuln.py
@@ -94,7 +94,7 @@ def handler(q=False):
for key in REQUIRED:
if not isinstance(config.get(key), str) or not config[key].strip():
raise ModuleError(f"Missing {key} configuration.")
- limit = _integer(config, "max_results", 25)
+ limit = 25
event = MISPEvent()
event.add_attribute(**attribute)
_expand(event, attribute, value, config, limit)
@@ -147,7 +147,7 @@ def version():
"output": "MISP objects linked to the original attribute.",
}
mispattributes = {"input": ["vulnerability"], "format": "misp_standard"}
-moduleconfig = ["api_key", "max_results"]
+moduleconfig = ["api_key"]
REQUIRED = ["api_key"]