diff --git a/integrations/glimps/manifest.yaml b/integrations/glimps/manifest.yaml new file mode 100644 index 0000000..8f6d237 --- /dev/null +++ b/integrations/glimps/manifest.yaml @@ -0,0 +1,58 @@ +id: glimps +name: GLIMPS Detect +version: 1.0.0 +description: "GLIMPS Detect (GDetect API lite v2) — deep malware analysis: submit a file for analysis, poll the result by UUID, and look up a file by SHA-256. Token authentication; stdlib-only, no extra Python dependencies. (French vendor.)" +changelog: "1.0.0 — Initial release: submit file, get result, search by hash." +category: enrichment + +# Per-instance configuration. Auth header 'X-Auth-Token: '. +config_schema: + properties: + base_url: + type: string + description: "GLIMPS Detect appliance URL (e.g. https://gdetect.example.com)" + api_token: + type: string + description: "GDetect API token" + x-soar-sensitive: true + required: + - base_url + - api_token + +commands: + - id: submit_file + name: glimps-submit-file + description: "Submit a file (base64) for analysis. Returns an analysis UUID." + inputs_schema: + properties: + file_name: { type: string, description: "File name" } + content_base64: { type: string, description: "File content, base64-encoded" } + required: [file_name, content_base64] + outputs_schema: { properties: {} } + - id: get_result + name: glimps-get-result + description: "Get an analysis result by UUID." + risk: read + inputs_schema: + properties: + uuid: { type: string, description: "Analysis UUID" } + required: [uuid] + outputs_schema: { properties: {} } + - id: search_hash + name: glimps-search-hash + description: "Look up a previously analyzed file by SHA-256." + risk: read + inputs_schema: + properties: + sha256: { type: string, description: "SHA-256 hash" } + required: [sha256] + outputs_schema: { properties: {} } + + - id: test_connection + name: glimps-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/glimps/scripts/get_result.py b/integrations/glimps/scripts/get_result.py new file mode 100644 index 0000000..b6873f5 --- /dev/null +++ b/integrations/glimps/scripts/get_result.py @@ -0,0 +1,71 @@ +import json, os, sys, base64, uuid, 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 _base(cfg): + return str(cfg.get("base_url", "")).rstrip("/") + "/api/lite/v2" + + +def _headers(cfg, extra=None): + h = {"X-Auth-Token": str(cfg.get("api_token", "")), "Accept": "application/json"} + if extra: + h.update(extra) + return h + + +def get(path, cfg, params=None): + url = _base(cfg) + path + if params: + clean = {k: v for k, v in params.items() if v not in (None, "")} + if clean: + url += "?" + urllib.parse.urlencode(clean) + req = urllib.request.Request(url, headers=_headers(cfg), method="GET") + with urllib.request.urlopen(req, timeout=90) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +def submit_multipart(path, cfg, file_field, file_name, file_bytes): + boundary = "----riposte" + uuid.uuid4().hex + parts = [("--" + boundary + "\r\n" + 'Content-Disposition: form-data; name="' + file_field + '"; filename="' + file_name + '"\r\n' + "Content-Type: application/octet-stream\r\n\r\n").encode("utf-8"), + file_bytes, + ("\r\n--" + boundary + "--\r\n").encode("utf-8")] + data = b"".join(parts) + req = urllib.request.Request(_base(cfg) + path, data=data, + headers=_headers(cfg, {"Content-Type": "multipart/form-data; boundary=" + boundary}), method="POST") + with urllib.request.urlopen(req, timeout=180) 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): + the_uuid = inputs.get("uuid") + if not the_uuid: + raise Exception("uuid is required") + return get("/results/" + q(the_uuid), cfg) + + +_run(main) diff --git a/integrations/glimps/scripts/search_hash.py b/integrations/glimps/scripts/search_hash.py new file mode 100644 index 0000000..91f6fdb --- /dev/null +++ b/integrations/glimps/scripts/search_hash.py @@ -0,0 +1,71 @@ +import json, os, sys, base64, uuid, 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 _base(cfg): + return str(cfg.get("base_url", "")).rstrip("/") + "/api/lite/v2" + + +def _headers(cfg, extra=None): + h = {"X-Auth-Token": str(cfg.get("api_token", "")), "Accept": "application/json"} + if extra: + h.update(extra) + return h + + +def get(path, cfg, params=None): + url = _base(cfg) + path + if params: + clean = {k: v for k, v in params.items() if v not in (None, "")} + if clean: + url += "?" + urllib.parse.urlencode(clean) + req = urllib.request.Request(url, headers=_headers(cfg), method="GET") + with urllib.request.urlopen(req, timeout=90) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +def submit_multipart(path, cfg, file_field, file_name, file_bytes): + boundary = "----riposte" + uuid.uuid4().hex + parts = [("--" + boundary + "\r\n" + 'Content-Disposition: form-data; name="' + file_field + '"; filename="' + file_name + '"\r\n' + "Content-Type: application/octet-stream\r\n\r\n").encode("utf-8"), + file_bytes, + ("\r\n--" + boundary + "--\r\n").encode("utf-8")] + data = b"".join(parts) + req = urllib.request.Request(_base(cfg) + path, data=data, + headers=_headers(cfg, {"Content-Type": "multipart/form-data; boundary=" + boundary}), method="POST") + with urllib.request.urlopen(req, timeout=180) 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): + sha256 = inputs.get("sha256") + if not sha256: + raise Exception("sha256 is required") + return get("/search/" + q(sha256), cfg) + + +_run(main) diff --git a/integrations/glimps/scripts/submit_file.py b/integrations/glimps/scripts/submit_file.py new file mode 100644 index 0000000..25d899a --- /dev/null +++ b/integrations/glimps/scripts/submit_file.py @@ -0,0 +1,72 @@ +import json, os, sys, base64, uuid, 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 _base(cfg): + return str(cfg.get("base_url", "")).rstrip("/") + "/api/lite/v2" + + +def _headers(cfg, extra=None): + h = {"X-Auth-Token": str(cfg.get("api_token", "")), "Accept": "application/json"} + if extra: + h.update(extra) + return h + + +def get(path, cfg, params=None): + url = _base(cfg) + path + if params: + clean = {k: v for k, v in params.items() if v not in (None, "")} + if clean: + url += "?" + urllib.parse.urlencode(clean) + req = urllib.request.Request(url, headers=_headers(cfg), method="GET") + with urllib.request.urlopen(req, timeout=90) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +def submit_multipart(path, cfg, file_field, file_name, file_bytes): + boundary = "----riposte" + uuid.uuid4().hex + parts = [("--" + boundary + "\r\n" + 'Content-Disposition: form-data; name="' + file_field + '"; filename="' + file_name + '"\r\n' + "Content-Type: application/octet-stream\r\n\r\n").encode("utf-8"), + file_bytes, + ("\r\n--" + boundary + "--\r\n").encode("utf-8")] + data = b"".join(parts) + req = urllib.request.Request(_base(cfg) + path, data=data, + headers=_headers(cfg, {"Content-Type": "multipart/form-data; boundary=" + boundary}), method="POST") + with urllib.request.urlopen(req, timeout=180) 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): + file_name = inputs.get("file_name") + if not file_name: + raise Exception("file_name is required") + content_base64 = inputs.get("content_base64") + if not content_base64: + raise Exception("content_base64 is required") + file_bytes = base64.b64decode(content_base64) + return submit_multipart("/submit", cfg, "file", file_name, file_bytes) + + +_run(main) diff --git a/integrations/glimps/scripts/test_connection.py b/integrations/glimps/scripts/test_connection.py new file mode 100644 index 0000000..15e95d3 --- /dev/null +++ b/integrations/glimps/scripts/test_connection.py @@ -0,0 +1,66 @@ +import json, os, sys, base64, uuid, 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 _base(cfg): + return str(cfg.get("base_url", "")).rstrip("/") + "/api/lite/v2" + + +def _headers(cfg, extra=None): + h = {"X-Auth-Token": str(cfg.get("api_token", "")), "Accept": "application/json"} + if extra: + h.update(extra) + return h + + +def get(path, cfg, params=None): + url = _base(cfg) + path + if params: + clean = {k: v for k, v in params.items() if v not in (None, "")} + if clean: + url += "?" + urllib.parse.urlencode(clean) + req = urllib.request.Request(url, headers=_headers(cfg), method="GET") + with urllib.request.urlopen(req, timeout=90) as r: + raw = r.read() + return json.loads(raw) if raw else {} + + +def submit_multipart(path, cfg, file_field, file_name, file_bytes): + boundary = "----riposte" + uuid.uuid4().hex + parts = [("--" + boundary + "\r\n" + 'Content-Disposition: form-data; name="' + file_field + '"; filename="' + file_name + '"\r\n' + "Content-Type: application/octet-stream\r\n\r\n").encode("utf-8"), + file_bytes, + ("\r\n--" + boundary + "--\r\n").encode("utf-8")] + data = b"".join(parts) + req = urllib.request.Request(_base(cfg) + path, data=data, + headers=_headers(cfg, {"Content-Type": "multipart/form-data; boundary=" + boundary}), method="POST") + with urllib.request.urlopen(req, timeout=180) 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): + get("/status", cfg) + return {"ok": True} + + +_run(main)