From 041cadade2f97f8ef08aed060f8086e0f9af8a3f Mon Sep 17 00:00:00 2001 From: Guillaume BOURGEOIS Date: Sun, 12 Jul 2026 00:48:03 +0200 Subject: [PATCH] feat(extrahop): new ExtraHop Reveal(x) NDR integration ExtraHop REST API v1, 6 commands: search/get detections, list/search devices, get device. ESA API-key auth, stdlib-only. Co-Authored-By: Claude Opus 4.8 (1M context) --- integrations/extrahop/manifest.yaml | 84 +++++++++++++++++++ .../extrahop/scripts/get_detection.py | 57 +++++++++++++ integrations/extrahop/scripts/get_device.py | 57 +++++++++++++ integrations/extrahop/scripts/list_devices.py | 54 ++++++++++++ .../extrahop/scripts/search_detections.py | 64 ++++++++++++++ .../extrahop/scripts/search_devices.py | 68 +++++++++++++++ .../extrahop/scripts/test_connection.py | 53 ++++++++++++ 7 files changed, 437 insertions(+) create mode 100644 integrations/extrahop/manifest.yaml create mode 100644 integrations/extrahop/scripts/get_detection.py create mode 100644 integrations/extrahop/scripts/get_device.py create mode 100644 integrations/extrahop/scripts/list_devices.py create mode 100644 integrations/extrahop/scripts/search_detections.py create mode 100644 integrations/extrahop/scripts/search_devices.py create mode 100644 integrations/extrahop/scripts/test_connection.py diff --git a/integrations/extrahop/manifest.yaml b/integrations/extrahop/manifest.yaml new file mode 100644 index 0000000..df584e2 --- /dev/null +++ b/integrations/extrahop/manifest.yaml @@ -0,0 +1,84 @@ +id: extrahop +name: ExtraHop +version: 1.0.0 +description: "ExtraHop Reveal(x) (REST API v1) — network detection and asset context: search and read detections, list and search devices, and read a device. API-key (ESA) authentication; stdlib-only, no extra Python dependencies." +changelog: "1.0.0 — Initial release: search/get detections, list/search devices, get device." +category: ndr + +# Per-instance configuration. Auth header 'Authorization: ESA '. +config_schema: + properties: + base_url: + type: string + description: "ExtraHop appliance URL (e.g. https://extrahop.example.com)" + api_key: + type: string + description: "ExtraHop REST API key" + x-soar-sensitive: true + insecure: + type: boolean + description: "Trust any TLS certificate (not secure)" + default: false + required: + - base_url + - api_key + +commands: + - id: search_detections + name: extrahop-search-detections + description: "Search detections in a time window." + risk: read + inputs_schema: + properties: + from_time: { type: number, description: "Start time (Unix ms, negative = relative, e.g. -3600000)" } + limit: { type: number, description: "Max detections (default 50)" } + min_risk_score: { type: number, description: "Minimum risk score 0-99 (optional)" } + required: [] + outputs_schema: { properties: {} } + - id: get_detection + name: extrahop-get-detection + description: "Get a single detection by ID." + risk: read + inputs_schema: + properties: + detection_id: { type: string, description: "Detection ID" } + required: [detection_id] + outputs_schema: { properties: {} } + - id: list_devices + name: extrahop-list-devices + description: "List devices." + risk: read + inputs_schema: + properties: + limit: { type: number, description: "Max devices (default 50)" } + required: [] + outputs_schema: { properties: {} } + - id: search_devices + name: extrahop-search-devices + description: "Search devices by IP, name, or MAC." + risk: read + inputs_schema: + properties: + field: { type: string, description: "Field to match: ipaddr, name, or macaddr (default ipaddr)" } + value: { type: string, description: "Value to match" } + limit: { type: number, description: "Max devices (default 50)" } + required: [value] + outputs_schema: { properties: {} } + - id: get_device + name: extrahop-get-device + description: "Get a single device by ID." + risk: read + inputs_schema: + properties: + device_id: { type: string, description: "Device ID" } + required: [device_id] + outputs_schema: { properties: {} } + + - id: test_connection + name: extrahop-test-connection + description: "Verify connectivity and the API key (used by the Test button)." + risk: read + inputs_schema: + properties: {} + required: [] + outputs_schema: { properties: {} } diff --git a/integrations/extrahop/scripts/get_detection.py b/integrations/extrahop/scripts/get_detection.py new file mode 100644 index 0000000..a532b19 --- /dev/null +++ b/integrations/extrahop/scripts/get_detection.py @@ -0,0 +1,57 @@ +import json, os, sys, ssl, urllib.parse, urllib.request, urllib.error + + +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 request(method, path, cfg, body=None, params=None): + url = str(cfg.get("base_url", "")).rstrip("/") + "/api/v1" + path + if params: + clean = {k: v for k, v in params.items() if v not in (None, "")} + if clean: + url += "?" + urllib.parse.urlencode(clean) + data = json.dumps(body).encode("utf-8") if body is not None else None + headers = {"Authorization": "ESA " + str(cfg.get("api_key", "")), "Accept": "application/json"} + if data is not None: + headers["Content-Type"] = "application/json" + req = urllib.request.Request(url, data=data, headers=headers, method=method) + with urllib.request.urlopen(req, timeout=60, context=_ctx(cfg)) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +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): + detection_id = inputs.get("detection_id") + if not detection_id: + raise Exception("detection_id is required") + + q = lambda v: urllib.parse.quote(str(v), safe="") + return request("GET", "/detections/" + q(detection_id), cfg) + + +_run(main) diff --git a/integrations/extrahop/scripts/get_device.py b/integrations/extrahop/scripts/get_device.py new file mode 100644 index 0000000..77f179a --- /dev/null +++ b/integrations/extrahop/scripts/get_device.py @@ -0,0 +1,57 @@ +import json, os, sys, ssl, urllib.parse, urllib.request, urllib.error + + +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 request(method, path, cfg, body=None, params=None): + url = str(cfg.get("base_url", "")).rstrip("/") + "/api/v1" + path + if params: + clean = {k: v for k, v in params.items() if v not in (None, "")} + if clean: + url += "?" + urllib.parse.urlencode(clean) + data = json.dumps(body).encode("utf-8") if body is not None else None + headers = {"Authorization": "ESA " + str(cfg.get("api_key", "")), "Accept": "application/json"} + if data is not None: + headers["Content-Type"] = "application/json" + req = urllib.request.Request(url, data=data, headers=headers, method=method) + with urllib.request.urlopen(req, timeout=60, context=_ctx(cfg)) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +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): + device_id = inputs.get("device_id") + if not device_id: + raise Exception("device_id is required") + + q = lambda v: urllib.parse.quote(str(v), safe="") + return request("GET", "/devices/" + q(device_id), cfg) + + +_run(main) diff --git a/integrations/extrahop/scripts/list_devices.py b/integrations/extrahop/scripts/list_devices.py new file mode 100644 index 0000000..2d9a3e6 --- /dev/null +++ b/integrations/extrahop/scripts/list_devices.py @@ -0,0 +1,54 @@ +import json, os, sys, ssl, urllib.parse, urllib.request, urllib.error + + +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 request(method, path, cfg, body=None, params=None): + url = str(cfg.get("base_url", "")).rstrip("/") + "/api/v1" + path + if params: + clean = {k: v for k, v in params.items() if v not in (None, "")} + if clean: + url += "?" + urllib.parse.urlencode(clean) + data = json.dumps(body).encode("utf-8") if body is not None else None + headers = {"Authorization": "ESA " + str(cfg.get("api_key", "")), "Accept": "application/json"} + if data is not None: + headers["Content-Type"] = "application/json" + req = urllib.request.Request(url, data=data, headers=headers, method=method) + with urllib.request.urlopen(req, timeout=60, context=_ctx(cfg)) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +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): + limit = inputs.get("limit") + response = request("GET", "/devices", cfg, params={"limit": int(limit or 50)}) + return {"devices": response} + + +_run(main) diff --git a/integrations/extrahop/scripts/search_detections.py b/integrations/extrahop/scripts/search_detections.py new file mode 100644 index 0000000..705b329 --- /dev/null +++ b/integrations/extrahop/scripts/search_detections.py @@ -0,0 +1,64 @@ +import json, os, sys, ssl, urllib.parse, urllib.request, urllib.error + + +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 request(method, path, cfg, body=None, params=None): + url = str(cfg.get("base_url", "")).rstrip("/") + "/api/v1" + path + if params: + clean = {k: v for k, v in params.items() if v not in (None, "")} + if clean: + url += "?" + urllib.parse.urlencode(clean) + data = json.dumps(body).encode("utf-8") if body is not None else None + headers = {"Authorization": "ESA " + str(cfg.get("api_key", "")), "Accept": "application/json"} + if data is not None: + headers["Content-Type"] = "application/json" + req = urllib.request.Request(url, data=data, headers=headers, method=method) + with urllib.request.urlopen(req, timeout=60, context=_ctx(cfg)) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +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): + from_time = inputs.get("from_time") + limit = inputs.get("limit") + min_risk_score = inputs.get("min_risk_score") + + body = { + "limit": int(limit or 50), + "from": int(from_time) if from_time not in (None, "") else -3600000, + } + if min_risk_score not in (None, ""): + body["filter"] = {"risk_score_min": int(min_risk_score)} + + response = request("POST", "/detections/search", cfg, body=body) + return {"detections": response} + + +_run(main) diff --git a/integrations/extrahop/scripts/search_devices.py b/integrations/extrahop/scripts/search_devices.py new file mode 100644 index 0000000..f3bea9f --- /dev/null +++ b/integrations/extrahop/scripts/search_devices.py @@ -0,0 +1,68 @@ +import json, os, sys, ssl, urllib.parse, urllib.request, urllib.error + + +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 request(method, path, cfg, body=None, params=None): + url = str(cfg.get("base_url", "")).rstrip("/") + "/api/v1" + path + if params: + clean = {k: v for k, v in params.items() if v not in (None, "")} + if clean: + url += "?" + urllib.parse.urlencode(clean) + data = json.dumps(body).encode("utf-8") if body is not None else None + headers = {"Authorization": "ESA " + str(cfg.get("api_key", "")), "Accept": "application/json"} + if data is not None: + headers["Content-Type"] = "application/json" + req = urllib.request.Request(url, data=data, headers=headers, method=method) + with urllib.request.urlopen(req, timeout=60, context=_ctx(cfg)) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +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): + field = inputs.get("field") + value = inputs.get("value") + limit = inputs.get("limit") + + if not value: + raise Exception("value is required") + + body = { + "filter": { + "field": field or "ipaddr", + "operand": value, + "operator": "=", + }, + "limit": int(limit or 50), + } + response = request("POST", "/devices/search", cfg, body=body) + return {"devices": response} + + +_run(main) diff --git a/integrations/extrahop/scripts/test_connection.py b/integrations/extrahop/scripts/test_connection.py new file mode 100644 index 0000000..241c2f5 --- /dev/null +++ b/integrations/extrahop/scripts/test_connection.py @@ -0,0 +1,53 @@ +import json, os, sys, ssl, urllib.parse, urllib.request, urllib.error + + +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 request(method, path, cfg, body=None, params=None): + url = str(cfg.get("base_url", "")).rstrip("/") + "/api/v1" + path + if params: + clean = {k: v for k, v in params.items() if v not in (None, "")} + if clean: + url += "?" + urllib.parse.urlencode(clean) + data = json.dumps(body).encode("utf-8") if body is not None else None + headers = {"Authorization": "ESA " + str(cfg.get("api_key", "")), "Accept": "application/json"} + if data is not None: + headers["Content-Type"] = "application/json" + req = urllib.request.Request(url, data=data, headers=headers, method=method) + with urllib.request.urlopen(req, timeout=60, context=_ctx(cfg)) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +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): + request("GET", "/extrahop", cfg) + return {"ok": True} + + +_run(main)