diff --git a/integrations/signalsciences/manifest.yaml b/integrations/signalsciences/manifest.yaml new file mode 100644 index 0000000..a9009d6 --- /dev/null +++ b/integrations/signalsciences/manifest.yaml @@ -0,0 +1,72 @@ +id: signalsciences +name: Signal Sciences +version: 1.0.0 +description: "Signal Sciences (Fastly NGWAF, API v0) — web-attack visibility and containment: list sites, read suspicious IPs and events, and add an IP to a site list (block). API-token authentication; stdlib-only, no extra Python dependencies." +changelog: "1.0.0 — Initial release: list sites, get suspicious IPs, list events, add IP to list." +category: network + +# Per-instance configuration. Auth headers 'x-api-user' (email) and 'x-api-token'. +config_schema: + properties: + email: + type: string + description: "API user email" + api_token: + type: string + description: "API token" + x-soar-sensitive: true + corp_name: + type: string + description: "Corp (organization) short name" + required: + - email + - api_token + - corp_name + +commands: + - id: list_sites + name: sigsci-list-sites + description: "List sites in the corp." + risk: read + inputs_schema: + properties: {} + required: [] + outputs_schema: { properties: {} } + - id: get_suspicious_ips + name: sigsci-get-suspicious-ips + description: "List a site's suspicious IPs." + risk: read + inputs_schema: + properties: + site_name: { type: string, description: "Site short name" } + required: [site_name] + outputs_schema: { properties: {} } + - id: list_events + name: sigsci-list-events + description: "List a site's flagged-IP events." + risk: read + inputs_schema: + properties: + site_name: { type: string, description: "Site short name" } + limit: { type: number, description: "Max events (default 50)" } + required: [site_name] + outputs_schema: { properties: {} } + - id: add_ip_to_list + name: sigsci-add-ip-to-list + description: "Add an IP to a site custom list (e.g. a block list)." + inputs_schema: + properties: + site_name: { type: string, description: "Site short name" } + list_id: { type: string, description: "Custom list ID" } + ip: { type: string, description: "IP or CIDR to add" } + required: [site_name, list_id, ip] + outputs_schema: { properties: {} } + + - id: test_connection + name: sigsci-test-connection + description: "Verify the API token (used by the Test button)." + risk: read + inputs_schema: + properties: {} + required: [] + outputs_schema: { properties: {} } diff --git a/integrations/signalsciences/scripts/add_ip_to_list.py b/integrations/signalsciences/scripts/add_ip_to_list.py new file mode 100644 index 0000000..3b0358f --- /dev/null +++ b/integrations/signalsciences/scripts/add_ip_to_list.py @@ -0,0 +1,70 @@ +import json, os, sys, urllib.parse, urllib.request, urllib.error + +BASE = "https://dashboard.signalsciences.net/api/v0" + + +def _cfg(): + return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}")) + + +def _inputs(): + return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}")) + + +def _corp(cfg): + return "/corps/" + urllib.parse.quote(str(cfg.get("corp_name", "")), safe="") + + +def request(method, path, cfg, body=None, params=None): + url = BASE + 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 = { + "x-api-user": str(cfg.get("email", "")), + "x-api-token": str(cfg.get("api_token", "")), + "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) 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) + + +q = lambda v: urllib.parse.quote(str(v), safe="") + + +def main(cfg, inputs): + site_name = inputs.get("site_name") + if not site_name: + raise Exception("site_name is required") + list_id = inputs.get("list_id") + if not list_id: + raise Exception("list_id is required") + ip = inputs.get("ip") + if not ip: + raise Exception("ip is required") + return request( + "PATCH", + _corp(cfg) + "/sites/" + q(site_name) + "/lists/" + q(list_id), + cfg, + body={"entries": {"additions": [ip], "deletions": []}}, + ) + + +_run(main) diff --git a/integrations/signalsciences/scripts/get_suspicious_ips.py b/integrations/signalsciences/scripts/get_suspicious_ips.py new file mode 100644 index 0000000..1f2f1d5 --- /dev/null +++ b/integrations/signalsciences/scripts/get_suspicious_ips.py @@ -0,0 +1,59 @@ +import json, os, sys, urllib.parse, urllib.request, urllib.error + +BASE = "https://dashboard.signalsciences.net/api/v0" + + +def _cfg(): + return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}")) + + +def _inputs(): + return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}")) + + +def _corp(cfg): + return "/corps/" + urllib.parse.quote(str(cfg.get("corp_name", "")), safe="") + + +def request(method, path, cfg, body=None, params=None): + url = BASE + 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 = { + "x-api-user": str(cfg.get("email", "")), + "x-api-token": str(cfg.get("api_token", "")), + "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) 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) + + +q = lambda v: urllib.parse.quote(str(v), safe="") + + +def main(cfg, inputs): + site_name = inputs.get("site_name") + if not site_name: + raise Exception("site_name is required") + return request("GET", _corp(cfg) + "/sites/" + q(site_name) + "/suspiciousIPs", cfg) + + +_run(main) diff --git a/integrations/signalsciences/scripts/list_events.py b/integrations/signalsciences/scripts/list_events.py new file mode 100644 index 0000000..b83e8b2 --- /dev/null +++ b/integrations/signalsciences/scripts/list_events.py @@ -0,0 +1,65 @@ +import json, os, sys, urllib.parse, urllib.request, urllib.error + +BASE = "https://dashboard.signalsciences.net/api/v0" + + +def _cfg(): + return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}")) + + +def _inputs(): + return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}")) + + +def _corp(cfg): + return "/corps/" + urllib.parse.quote(str(cfg.get("corp_name", "")), safe="") + + +def request(method, path, cfg, body=None, params=None): + url = BASE + 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 = { + "x-api-user": str(cfg.get("email", "")), + "x-api-token": str(cfg.get("api_token", "")), + "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) 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) + + +q = lambda v: urllib.parse.quote(str(v), safe="") + + +def main(cfg, inputs): + site_name = inputs.get("site_name") + if not site_name: + raise Exception("site_name is required") + limit = inputs.get("limit") + return request( + "GET", + _corp(cfg) + "/sites/" + q(site_name) + "/events", + cfg, + params={"limit": int(limit or 50)}, + ) + + +_run(main) diff --git a/integrations/signalsciences/scripts/list_sites.py b/integrations/signalsciences/scripts/list_sites.py new file mode 100644 index 0000000..73291b9 --- /dev/null +++ b/integrations/signalsciences/scripts/list_sites.py @@ -0,0 +1,53 @@ +import json, os, sys, urllib.parse, urllib.request, urllib.error + +BASE = "https://dashboard.signalsciences.net/api/v0" + + +def _cfg(): + return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}")) + + +def _inputs(): + return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}")) + + +def _corp(cfg): + return "/corps/" + urllib.parse.quote(str(cfg.get("corp_name", "")), safe="") + + +def request(method, path, cfg, body=None, params=None): + url = BASE + 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 = { + "x-api-user": str(cfg.get("email", "")), + "x-api-token": str(cfg.get("api_token", "")), + "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) 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): + return request("GET", _corp(cfg) + "/sites", cfg) + + +_run(main) diff --git a/integrations/signalsciences/scripts/test_connection.py b/integrations/signalsciences/scripts/test_connection.py new file mode 100644 index 0000000..c40b3e9 --- /dev/null +++ b/integrations/signalsciences/scripts/test_connection.py @@ -0,0 +1,54 @@ +import json, os, sys, urllib.parse, urllib.request, urllib.error + +BASE = "https://dashboard.signalsciences.net/api/v0" + + +def _cfg(): + return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}")) + + +def _inputs(): + return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}")) + + +def _corp(cfg): + return "/corps/" + urllib.parse.quote(str(cfg.get("corp_name", "")), safe="") + + +def request(method, path, cfg, body=None, params=None): + url = BASE + 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 = { + "x-api-user": str(cfg.get("email", "")), + "x-api-token": str(cfg.get("api_token", "")), + "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) 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", _corp(cfg) + "/sites", cfg) + return {"ok": True} + + +_run(main)