Compare commits
3 Commits
d5b7e38dd7
...
9be28a2ff7
| Author | SHA1 | Date | |
|---|---|---|---|
| 9be28a2ff7 | |||
| 1292a8c798 | |||
| b6af7d1b68 |
@@ -0,0 +1,79 @@
|
|||||||
|
id: cape
|
||||||
|
name: CAPE Sandbox
|
||||||
|
version: 1.0.0
|
||||||
|
description: "CAPE Sandbox (APIv2) — dynamic malware analysis and config extraction: submit files and URLs, read task status and reports, and list tasks. Token authentication; stdlib-only, no extra Python dependencies."
|
||||||
|
changelog: "1.0.0 — Initial release: submit file/URL, get task, get report, list tasks."
|
||||||
|
category: enrichment
|
||||||
|
|
||||||
|
# Per-instance configuration. The token is sent as 'Authorization: Token <api_token>'.
|
||||||
|
config_schema:
|
||||||
|
properties:
|
||||||
|
base_url:
|
||||||
|
type: string
|
||||||
|
description: "CAPE URL (e.g. https://cape.example.com)"
|
||||||
|
api_token:
|
||||||
|
type: string
|
||||||
|
description: "CAPE API token"
|
||||||
|
x-soar-sensitive: true
|
||||||
|
insecure:
|
||||||
|
type: boolean
|
||||||
|
description: "Trust any TLS certificate (not secure)"
|
||||||
|
default: false
|
||||||
|
required:
|
||||||
|
- base_url
|
||||||
|
- api_token
|
||||||
|
|
||||||
|
commands:
|
||||||
|
- id: submit_file
|
||||||
|
name: cape-submit-file
|
||||||
|
description: "Submit a file (base64) for analysis."
|
||||||
|
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: submit_url
|
||||||
|
name: cape-submit-url
|
||||||
|
description: "Submit a URL for analysis."
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
url: { type: string, description: "URL to detonate" }
|
||||||
|
required: [url]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: get_task
|
||||||
|
name: cape-get-task
|
||||||
|
description: "Get a task's status and metadata."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
task_id: { type: string, description: "Task ID" }
|
||||||
|
required: [task_id]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: get_report
|
||||||
|
name: cape-get-report
|
||||||
|
description: "Get a task's full analysis report (JSON)."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
task_id: { type: string, description: "Task ID" }
|
||||||
|
required: [task_id]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: list_tasks
|
||||||
|
name: cape-list-tasks
|
||||||
|
description: "List recent tasks."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
limit: { type: number, description: "Max tasks (default 50)" }
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
|
||||||
|
- id: test_connection
|
||||||
|
name: cape-test-connection
|
||||||
|
description: "Verify connectivity and the token (used by the Test button)."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties: {}
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
import json, os, sys, base64, ssl, 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 _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, extra=None):
|
||||||
|
h = {"Accept": "application/json", "Authorization": "Token " + str(cfg.get("api_token", ""))}
|
||||||
|
if extra:
|
||||||
|
h.update(extra)
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, cfg, form=None):
|
||||||
|
url = str(cfg.get("base_url", "")).rstrip("/") + path
|
||||||
|
data = None
|
||||||
|
extra = {}
|
||||||
|
if form is not None:
|
||||||
|
data = urllib.parse.urlencode(form).encode("utf-8")
|
||||||
|
extra["Content-Type"] = "application/x-www-form-urlencoded"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, extra), method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=120, context=_ctx(cfg)) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def multipart(fields, file_field, file_name, file_bytes):
|
||||||
|
boundary = "----riposte" + uuid.uuid4().hex
|
||||||
|
parts = []
|
||||||
|
for k, v in (fields or {}).items():
|
||||||
|
parts.append(("--" + boundary + "\r\n"
|
||||||
|
'Content-Disposition: form-data; name="' + k + '"\r\n\r\n' + str(v) + "\r\n").encode("utf-8"))
|
||||||
|
parts.append(("--" + 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"))
|
||||||
|
parts.append(file_bytes)
|
||||||
|
parts.append(("\r\n--" + boundary + "--\r\n").encode("utf-8"))
|
||||||
|
return b"".join(parts), "multipart/form-data; boundary=" + boundary
|
||||||
|
|
||||||
|
|
||||||
|
def request_multipart(path, cfg, fields, file_field, file_name, file_bytes):
|
||||||
|
url = str(cfg.get("base_url", "")).rstrip("/") + path
|
||||||
|
data, content_type = multipart(fields, file_field, file_name, file_bytes)
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, {"Content-Type": content_type}), method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=180, 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):
|
||||||
|
task_id = inputs.get("task_id")
|
||||||
|
if not task_id:
|
||||||
|
raise Exception("task_id is required")
|
||||||
|
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||||
|
return request("GET", "/apiv2/tasks/get/report/" + q(task_id) + "/", cfg)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
import json, os, sys, base64, ssl, 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 _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, extra=None):
|
||||||
|
h = {"Accept": "application/json", "Authorization": "Token " + str(cfg.get("api_token", ""))}
|
||||||
|
if extra:
|
||||||
|
h.update(extra)
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, cfg, form=None):
|
||||||
|
url = str(cfg.get("base_url", "")).rstrip("/") + path
|
||||||
|
data = None
|
||||||
|
extra = {}
|
||||||
|
if form is not None:
|
||||||
|
data = urllib.parse.urlencode(form).encode("utf-8")
|
||||||
|
extra["Content-Type"] = "application/x-www-form-urlencoded"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, extra), method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=120, context=_ctx(cfg)) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def multipart(fields, file_field, file_name, file_bytes):
|
||||||
|
boundary = "----riposte" + uuid.uuid4().hex
|
||||||
|
parts = []
|
||||||
|
for k, v in (fields or {}).items():
|
||||||
|
parts.append(("--" + boundary + "\r\n"
|
||||||
|
'Content-Disposition: form-data; name="' + k + '"\r\n\r\n' + str(v) + "\r\n").encode("utf-8"))
|
||||||
|
parts.append(("--" + 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"))
|
||||||
|
parts.append(file_bytes)
|
||||||
|
parts.append(("\r\n--" + boundary + "--\r\n").encode("utf-8"))
|
||||||
|
return b"".join(parts), "multipart/form-data; boundary=" + boundary
|
||||||
|
|
||||||
|
|
||||||
|
def request_multipart(path, cfg, fields, file_field, file_name, file_bytes):
|
||||||
|
url = str(cfg.get("base_url", "")).rstrip("/") + path
|
||||||
|
data, content_type = multipart(fields, file_field, file_name, file_bytes)
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, {"Content-Type": content_type}), method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=180, 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):
|
||||||
|
task_id = inputs.get("task_id")
|
||||||
|
if not task_id:
|
||||||
|
raise Exception("task_id is required")
|
||||||
|
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||||
|
return request("GET", "/apiv2/tasks/view/" + q(task_id) + "/", cfg)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
import json, os, sys, base64, ssl, 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 _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, extra=None):
|
||||||
|
h = {"Accept": "application/json", "Authorization": "Token " + str(cfg.get("api_token", ""))}
|
||||||
|
if extra:
|
||||||
|
h.update(extra)
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, cfg, form=None):
|
||||||
|
url = str(cfg.get("base_url", "")).rstrip("/") + path
|
||||||
|
data = None
|
||||||
|
extra = {}
|
||||||
|
if form is not None:
|
||||||
|
data = urllib.parse.urlencode(form).encode("utf-8")
|
||||||
|
extra["Content-Type"] = "application/x-www-form-urlencoded"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, extra), method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=120, context=_ctx(cfg)) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def multipart(fields, file_field, file_name, file_bytes):
|
||||||
|
boundary = "----riposte" + uuid.uuid4().hex
|
||||||
|
parts = []
|
||||||
|
for k, v in (fields or {}).items():
|
||||||
|
parts.append(("--" + boundary + "\r\n"
|
||||||
|
'Content-Disposition: form-data; name="' + k + '"\r\n\r\n' + str(v) + "\r\n").encode("utf-8"))
|
||||||
|
parts.append(("--" + 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"))
|
||||||
|
parts.append(file_bytes)
|
||||||
|
parts.append(("\r\n--" + boundary + "--\r\n").encode("utf-8"))
|
||||||
|
return b"".join(parts), "multipart/form-data; boundary=" + boundary
|
||||||
|
|
||||||
|
|
||||||
|
def request_multipart(path, cfg, fields, file_field, file_name, file_bytes):
|
||||||
|
url = str(cfg.get("base_url", "")).rstrip("/") + path
|
||||||
|
data, content_type = multipart(fields, file_field, file_name, file_bytes)
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, {"Content-Type": content_type}), method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=180, 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")
|
||||||
|
return request("GET", "/apiv2/tasks/list/" + str(int(limit or 50)) + "/", cfg)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
import json, os, sys, base64, ssl, 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 _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, extra=None):
|
||||||
|
h = {"Accept": "application/json", "Authorization": "Token " + str(cfg.get("api_token", ""))}
|
||||||
|
if extra:
|
||||||
|
h.update(extra)
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, cfg, form=None):
|
||||||
|
url = str(cfg.get("base_url", "")).rstrip("/") + path
|
||||||
|
data = None
|
||||||
|
extra = {}
|
||||||
|
if form is not None:
|
||||||
|
data = urllib.parse.urlencode(form).encode("utf-8")
|
||||||
|
extra["Content-Type"] = "application/x-www-form-urlencoded"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, extra), method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=120, context=_ctx(cfg)) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def multipart(fields, file_field, file_name, file_bytes):
|
||||||
|
boundary = "----riposte" + uuid.uuid4().hex
|
||||||
|
parts = []
|
||||||
|
for k, v in (fields or {}).items():
|
||||||
|
parts.append(("--" + boundary + "\r\n"
|
||||||
|
'Content-Disposition: form-data; name="' + k + '"\r\n\r\n' + str(v) + "\r\n").encode("utf-8"))
|
||||||
|
parts.append(("--" + 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"))
|
||||||
|
parts.append(file_bytes)
|
||||||
|
parts.append(("\r\n--" + boundary + "--\r\n").encode("utf-8"))
|
||||||
|
return b"".join(parts), "multipart/form-data; boundary=" + boundary
|
||||||
|
|
||||||
|
|
||||||
|
def request_multipart(path, cfg, fields, file_field, file_name, file_bytes):
|
||||||
|
url = str(cfg.get("base_url", "")).rstrip("/") + path
|
||||||
|
data, content_type = multipart(fields, file_field, file_name, file_bytes)
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, {"Content-Type": content_type}), method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=180, 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):
|
||||||
|
file_name = inputs.get("file_name")
|
||||||
|
content_base64 = inputs.get("content_base64")
|
||||||
|
if not file_name:
|
||||||
|
raise Exception("file_name is required")
|
||||||
|
if not content_base64:
|
||||||
|
raise Exception("content_base64 is required")
|
||||||
|
return request_multipart(
|
||||||
|
"/apiv2/tasks/create/file/",
|
||||||
|
cfg,
|
||||||
|
{},
|
||||||
|
"file",
|
||||||
|
file_name,
|
||||||
|
base64.b64decode(content_base64),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
import json, os, sys, base64, ssl, 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 _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, extra=None):
|
||||||
|
h = {"Accept": "application/json", "Authorization": "Token " + str(cfg.get("api_token", ""))}
|
||||||
|
if extra:
|
||||||
|
h.update(extra)
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, cfg, form=None):
|
||||||
|
url = str(cfg.get("base_url", "")).rstrip("/") + path
|
||||||
|
data = None
|
||||||
|
extra = {}
|
||||||
|
if form is not None:
|
||||||
|
data = urllib.parse.urlencode(form).encode("utf-8")
|
||||||
|
extra["Content-Type"] = "application/x-www-form-urlencoded"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, extra), method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=120, context=_ctx(cfg)) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def multipart(fields, file_field, file_name, file_bytes):
|
||||||
|
boundary = "----riposte" + uuid.uuid4().hex
|
||||||
|
parts = []
|
||||||
|
for k, v in (fields or {}).items():
|
||||||
|
parts.append(("--" + boundary + "\r\n"
|
||||||
|
'Content-Disposition: form-data; name="' + k + '"\r\n\r\n' + str(v) + "\r\n").encode("utf-8"))
|
||||||
|
parts.append(("--" + 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"))
|
||||||
|
parts.append(file_bytes)
|
||||||
|
parts.append(("\r\n--" + boundary + "--\r\n").encode("utf-8"))
|
||||||
|
return b"".join(parts), "multipart/form-data; boundary=" + boundary
|
||||||
|
|
||||||
|
|
||||||
|
def request_multipart(path, cfg, fields, file_field, file_name, file_bytes):
|
||||||
|
url = str(cfg.get("base_url", "")).rstrip("/") + path
|
||||||
|
data, content_type = multipart(fields, file_field, file_name, file_bytes)
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, {"Content-Type": content_type}), method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=180, 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):
|
||||||
|
url = inputs.get("url")
|
||||||
|
if not url:
|
||||||
|
raise Exception("url is required")
|
||||||
|
return request("POST", "/apiv2/tasks/create/url/", cfg, form={"url": url})
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
import json, os, sys, base64, ssl, 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 _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, extra=None):
|
||||||
|
h = {"Accept": "application/json", "Authorization": "Token " + str(cfg.get("api_token", ""))}
|
||||||
|
if extra:
|
||||||
|
h.update(extra)
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, cfg, form=None):
|
||||||
|
url = str(cfg.get("base_url", "")).rstrip("/") + path
|
||||||
|
data = None
|
||||||
|
extra = {}
|
||||||
|
if form is not None:
|
||||||
|
data = urllib.parse.urlencode(form).encode("utf-8")
|
||||||
|
extra["Content-Type"] = "application/x-www-form-urlencoded"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, extra), method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=120, context=_ctx(cfg)) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def multipart(fields, file_field, file_name, file_bytes):
|
||||||
|
boundary = "----riposte" + uuid.uuid4().hex
|
||||||
|
parts = []
|
||||||
|
for k, v in (fields or {}).items():
|
||||||
|
parts.append(("--" + boundary + "\r\n"
|
||||||
|
'Content-Disposition: form-data; name="' + k + '"\r\n\r\n' + str(v) + "\r\n").encode("utf-8"))
|
||||||
|
parts.append(("--" + 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"))
|
||||||
|
parts.append(file_bytes)
|
||||||
|
parts.append(("\r\n--" + boundary + "--\r\n").encode("utf-8"))
|
||||||
|
return b"".join(parts), "multipart/form-data; boundary=" + boundary
|
||||||
|
|
||||||
|
|
||||||
|
def request_multipart(path, cfg, fields, file_field, file_name, file_bytes):
|
||||||
|
url = str(cfg.get("base_url", "")).rstrip("/") + path
|
||||||
|
data, content_type = multipart(fields, file_field, file_name, file_bytes)
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, {"Content-Type": content_type}), method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=180, 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", "/apiv2/cuckoo/status/", cfg)
|
||||||
|
return {"ok": True}
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
id: cuckoo
|
||||||
|
name: Cuckoo Sandbox
|
||||||
|
version: 1.0.0
|
||||||
|
description: "Cuckoo Sandbox (REST API) — dynamic malware analysis: submit files and URLs for detonation, read task status and reports, list tasks, and delete a task. Optional token authentication; stdlib-only, no extra Python dependencies."
|
||||||
|
changelog: "1.0.0 — Initial release: submit file/URL, get task, get report, list tasks, delete task."
|
||||||
|
category: enrichment
|
||||||
|
|
||||||
|
# Per-instance configuration. If the Cuckoo API server requires a token it is
|
||||||
|
# sent as 'Authorization: Bearer <api_token>'.
|
||||||
|
config_schema:
|
||||||
|
properties:
|
||||||
|
base_url:
|
||||||
|
type: string
|
||||||
|
description: "Cuckoo API URL (e.g. http://cuckoo.example.com:8090)"
|
||||||
|
api_token:
|
||||||
|
type: string
|
||||||
|
description: "API token (leave empty if the API server is unauthenticated)"
|
||||||
|
x-soar-sensitive: true
|
||||||
|
insecure:
|
||||||
|
type: boolean
|
||||||
|
description: "Trust any TLS certificate (not secure)"
|
||||||
|
default: false
|
||||||
|
required:
|
||||||
|
- base_url
|
||||||
|
|
||||||
|
commands:
|
||||||
|
- id: submit_file
|
||||||
|
name: cuckoo-submit-file
|
||||||
|
description: "Submit a file (base64) for analysis."
|
||||||
|
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: submit_url
|
||||||
|
name: cuckoo-submit-url
|
||||||
|
description: "Submit a URL for analysis."
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
url: { type: string, description: "URL to detonate" }
|
||||||
|
required: [url]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: get_task
|
||||||
|
name: cuckoo-get-task
|
||||||
|
description: "Get a task's status and metadata."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
task_id: { type: string, description: "Task ID" }
|
||||||
|
required: [task_id]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: get_report
|
||||||
|
name: cuckoo-get-report
|
||||||
|
description: "Get a task's full analysis report (JSON)."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
task_id: { type: string, description: "Task ID" }
|
||||||
|
required: [task_id]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: list_tasks
|
||||||
|
name: cuckoo-list-tasks
|
||||||
|
description: "List recent tasks."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
limit: { type: number, description: "Max tasks (default 50)" }
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: delete_task
|
||||||
|
name: cuckoo-delete-task
|
||||||
|
description: "Delete a task and its data."
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
task_id: { type: string, description: "Task ID" }
|
||||||
|
required: [task_id]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
|
||||||
|
- id: test_connection
|
||||||
|
name: cuckoo-test-connection
|
||||||
|
description: "Verify connectivity (used by the Test button)."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties: {}
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
import json, os, sys, base64, ssl, 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 _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, extra=None):
|
||||||
|
h = {"Accept": "application/json"}
|
||||||
|
if cfg.get("api_token"):
|
||||||
|
h["Authorization"] = "Bearer " + str(cfg["api_token"])
|
||||||
|
if extra:
|
||||||
|
h.update(extra)
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, cfg, body=None, form=None):
|
||||||
|
url = str(cfg.get("base_url", "")).rstrip("/") + path
|
||||||
|
data = None
|
||||||
|
extra = {}
|
||||||
|
if body is not None:
|
||||||
|
data = json.dumps(body).encode("utf-8")
|
||||||
|
extra["Content-Type"] = "application/json"
|
||||||
|
elif form is not None:
|
||||||
|
data = urllib.parse.urlencode(form).encode("utf-8")
|
||||||
|
extra["Content-Type"] = "application/x-www-form-urlencoded"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, extra), method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=120, context=_ctx(cfg)) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def multipart(fields, file_field, file_name, file_bytes):
|
||||||
|
boundary = "----riposte" + uuid.uuid4().hex
|
||||||
|
parts = []
|
||||||
|
for k, v in (fields or {}).items():
|
||||||
|
parts.append(("--" + boundary + "\r\n"
|
||||||
|
'Content-Disposition: form-data; name="' + k + '"\r\n\r\n' + str(v) + "\r\n").encode("utf-8"))
|
||||||
|
parts.append(("--" + 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"))
|
||||||
|
parts.append(file_bytes)
|
||||||
|
parts.append(("\r\n--" + boundary + "--\r\n").encode("utf-8"))
|
||||||
|
return b"".join(parts), "multipart/form-data; boundary=" + boundary
|
||||||
|
|
||||||
|
|
||||||
|
def request_multipart(path, cfg, fields, file_field, file_name, file_bytes):
|
||||||
|
url = str(cfg.get("base_url", "")).rstrip("/") + path
|
||||||
|
data, content_type = multipart(fields, file_field, file_name, file_bytes)
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, {"Content-Type": content_type}), method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=180, 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)
|
||||||
|
|
||||||
|
|
||||||
|
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
task_id = inputs.get("task_id")
|
||||||
|
if not task_id:
|
||||||
|
raise Exception("task_id is required")
|
||||||
|
request("GET", "/tasks/delete/" + q(task_id), cfg)
|
||||||
|
return {"ok": True, "task_id": task_id}
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
import json, os, sys, base64, ssl, 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 _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, extra=None):
|
||||||
|
h = {"Accept": "application/json"}
|
||||||
|
if cfg.get("api_token"):
|
||||||
|
h["Authorization"] = "Bearer " + str(cfg["api_token"])
|
||||||
|
if extra:
|
||||||
|
h.update(extra)
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, cfg, body=None, form=None):
|
||||||
|
url = str(cfg.get("base_url", "")).rstrip("/") + path
|
||||||
|
data = None
|
||||||
|
extra = {}
|
||||||
|
if body is not None:
|
||||||
|
data = json.dumps(body).encode("utf-8")
|
||||||
|
extra["Content-Type"] = "application/json"
|
||||||
|
elif form is not None:
|
||||||
|
data = urllib.parse.urlencode(form).encode("utf-8")
|
||||||
|
extra["Content-Type"] = "application/x-www-form-urlencoded"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, extra), method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=120, context=_ctx(cfg)) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def multipart(fields, file_field, file_name, file_bytes):
|
||||||
|
boundary = "----riposte" + uuid.uuid4().hex
|
||||||
|
parts = []
|
||||||
|
for k, v in (fields or {}).items():
|
||||||
|
parts.append(("--" + boundary + "\r\n"
|
||||||
|
'Content-Disposition: form-data; name="' + k + '"\r\n\r\n' + str(v) + "\r\n").encode("utf-8"))
|
||||||
|
parts.append(("--" + 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"))
|
||||||
|
parts.append(file_bytes)
|
||||||
|
parts.append(("\r\n--" + boundary + "--\r\n").encode("utf-8"))
|
||||||
|
return b"".join(parts), "multipart/form-data; boundary=" + boundary
|
||||||
|
|
||||||
|
|
||||||
|
def request_multipart(path, cfg, fields, file_field, file_name, file_bytes):
|
||||||
|
url = str(cfg.get("base_url", "")).rstrip("/") + path
|
||||||
|
data, content_type = multipart(fields, file_field, file_name, file_bytes)
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, {"Content-Type": content_type}), method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=180, 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)
|
||||||
|
|
||||||
|
|
||||||
|
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
task_id = inputs.get("task_id")
|
||||||
|
if not task_id:
|
||||||
|
raise Exception("task_id is required")
|
||||||
|
return request("GET", "/tasks/report/" + q(task_id), cfg)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
import json, os, sys, base64, ssl, 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 _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, extra=None):
|
||||||
|
h = {"Accept": "application/json"}
|
||||||
|
if cfg.get("api_token"):
|
||||||
|
h["Authorization"] = "Bearer " + str(cfg["api_token"])
|
||||||
|
if extra:
|
||||||
|
h.update(extra)
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, cfg, body=None, form=None):
|
||||||
|
url = str(cfg.get("base_url", "")).rstrip("/") + path
|
||||||
|
data = None
|
||||||
|
extra = {}
|
||||||
|
if body is not None:
|
||||||
|
data = json.dumps(body).encode("utf-8")
|
||||||
|
extra["Content-Type"] = "application/json"
|
||||||
|
elif form is not None:
|
||||||
|
data = urllib.parse.urlencode(form).encode("utf-8")
|
||||||
|
extra["Content-Type"] = "application/x-www-form-urlencoded"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, extra), method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=120, context=_ctx(cfg)) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def multipart(fields, file_field, file_name, file_bytes):
|
||||||
|
boundary = "----riposte" + uuid.uuid4().hex
|
||||||
|
parts = []
|
||||||
|
for k, v in (fields or {}).items():
|
||||||
|
parts.append(("--" + boundary + "\r\n"
|
||||||
|
'Content-Disposition: form-data; name="' + k + '"\r\n\r\n' + str(v) + "\r\n").encode("utf-8"))
|
||||||
|
parts.append(("--" + 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"))
|
||||||
|
parts.append(file_bytes)
|
||||||
|
parts.append(("\r\n--" + boundary + "--\r\n").encode("utf-8"))
|
||||||
|
return b"".join(parts), "multipart/form-data; boundary=" + boundary
|
||||||
|
|
||||||
|
|
||||||
|
def request_multipart(path, cfg, fields, file_field, file_name, file_bytes):
|
||||||
|
url = str(cfg.get("base_url", "")).rstrip("/") + path
|
||||||
|
data, content_type = multipart(fields, file_field, file_name, file_bytes)
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, {"Content-Type": content_type}), method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=180, 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)
|
||||||
|
|
||||||
|
|
||||||
|
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
task_id = inputs.get("task_id")
|
||||||
|
if not task_id:
|
||||||
|
raise Exception("task_id is required")
|
||||||
|
return request("GET", "/tasks/view/" + q(task_id), cfg)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
import json, os, sys, base64, ssl, 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 _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, extra=None):
|
||||||
|
h = {"Accept": "application/json"}
|
||||||
|
if cfg.get("api_token"):
|
||||||
|
h["Authorization"] = "Bearer " + str(cfg["api_token"])
|
||||||
|
if extra:
|
||||||
|
h.update(extra)
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, cfg, body=None, form=None):
|
||||||
|
url = str(cfg.get("base_url", "")).rstrip("/") + path
|
||||||
|
data = None
|
||||||
|
extra = {}
|
||||||
|
if body is not None:
|
||||||
|
data = json.dumps(body).encode("utf-8")
|
||||||
|
extra["Content-Type"] = "application/json"
|
||||||
|
elif form is not None:
|
||||||
|
data = urllib.parse.urlencode(form).encode("utf-8")
|
||||||
|
extra["Content-Type"] = "application/x-www-form-urlencoded"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, extra), method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=120, context=_ctx(cfg)) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def multipart(fields, file_field, file_name, file_bytes):
|
||||||
|
boundary = "----riposte" + uuid.uuid4().hex
|
||||||
|
parts = []
|
||||||
|
for k, v in (fields or {}).items():
|
||||||
|
parts.append(("--" + boundary + "\r\n"
|
||||||
|
'Content-Disposition: form-data; name="' + k + '"\r\n\r\n' + str(v) + "\r\n").encode("utf-8"))
|
||||||
|
parts.append(("--" + 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"))
|
||||||
|
parts.append(file_bytes)
|
||||||
|
parts.append(("\r\n--" + boundary + "--\r\n").encode("utf-8"))
|
||||||
|
return b"".join(parts), "multipart/form-data; boundary=" + boundary
|
||||||
|
|
||||||
|
|
||||||
|
def request_multipart(path, cfg, fields, file_field, file_name, file_bytes):
|
||||||
|
url = str(cfg.get("base_url", "")).rstrip("/") + path
|
||||||
|
data, content_type = multipart(fields, file_field, file_name, file_bytes)
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, {"Content-Type": content_type}), method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=180, 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")
|
||||||
|
limit = int(limit) if limit not in (None, "") else 50
|
||||||
|
return request("GET", "/tasks/list/" + str(limit), cfg)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
import json, os, sys, base64, ssl, 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 _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, extra=None):
|
||||||
|
h = {"Accept": "application/json"}
|
||||||
|
if cfg.get("api_token"):
|
||||||
|
h["Authorization"] = "Bearer " + str(cfg["api_token"])
|
||||||
|
if extra:
|
||||||
|
h.update(extra)
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, cfg, body=None, form=None):
|
||||||
|
url = str(cfg.get("base_url", "")).rstrip("/") + path
|
||||||
|
data = None
|
||||||
|
extra = {}
|
||||||
|
if body is not None:
|
||||||
|
data = json.dumps(body).encode("utf-8")
|
||||||
|
extra["Content-Type"] = "application/json"
|
||||||
|
elif form is not None:
|
||||||
|
data = urllib.parse.urlencode(form).encode("utf-8")
|
||||||
|
extra["Content-Type"] = "application/x-www-form-urlencoded"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, extra), method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=120, context=_ctx(cfg)) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def multipart(fields, file_field, file_name, file_bytes):
|
||||||
|
boundary = "----riposte" + uuid.uuid4().hex
|
||||||
|
parts = []
|
||||||
|
for k, v in (fields or {}).items():
|
||||||
|
parts.append(("--" + boundary + "\r\n"
|
||||||
|
'Content-Disposition: form-data; name="' + k + '"\r\n\r\n' + str(v) + "\r\n").encode("utf-8"))
|
||||||
|
parts.append(("--" + 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"))
|
||||||
|
parts.append(file_bytes)
|
||||||
|
parts.append(("\r\n--" + boundary + "--\r\n").encode("utf-8"))
|
||||||
|
return b"".join(parts), "multipart/form-data; boundary=" + boundary
|
||||||
|
|
||||||
|
|
||||||
|
def request_multipart(path, cfg, fields, file_field, file_name, file_bytes):
|
||||||
|
url = str(cfg.get("base_url", "")).rstrip("/") + path
|
||||||
|
data, content_type = multipart(fields, file_field, file_name, file_bytes)
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, {"Content-Type": content_type}), method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=180, 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):
|
||||||
|
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 request_multipart("/tasks/create/file", cfg, {}, "file", file_name, file_bytes)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
import json, os, sys, base64, ssl, 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 _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, extra=None):
|
||||||
|
h = {"Accept": "application/json"}
|
||||||
|
if cfg.get("api_token"):
|
||||||
|
h["Authorization"] = "Bearer " + str(cfg["api_token"])
|
||||||
|
if extra:
|
||||||
|
h.update(extra)
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, cfg, body=None, form=None):
|
||||||
|
url = str(cfg.get("base_url", "")).rstrip("/") + path
|
||||||
|
data = None
|
||||||
|
extra = {}
|
||||||
|
if body is not None:
|
||||||
|
data = json.dumps(body).encode("utf-8")
|
||||||
|
extra["Content-Type"] = "application/json"
|
||||||
|
elif form is not None:
|
||||||
|
data = urllib.parse.urlencode(form).encode("utf-8")
|
||||||
|
extra["Content-Type"] = "application/x-www-form-urlencoded"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, extra), method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=120, context=_ctx(cfg)) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def multipart(fields, file_field, file_name, file_bytes):
|
||||||
|
boundary = "----riposte" + uuid.uuid4().hex
|
||||||
|
parts = []
|
||||||
|
for k, v in (fields or {}).items():
|
||||||
|
parts.append(("--" + boundary + "\r\n"
|
||||||
|
'Content-Disposition: form-data; name="' + k + '"\r\n\r\n' + str(v) + "\r\n").encode("utf-8"))
|
||||||
|
parts.append(("--" + 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"))
|
||||||
|
parts.append(file_bytes)
|
||||||
|
parts.append(("\r\n--" + boundary + "--\r\n").encode("utf-8"))
|
||||||
|
return b"".join(parts), "multipart/form-data; boundary=" + boundary
|
||||||
|
|
||||||
|
|
||||||
|
def request_multipart(path, cfg, fields, file_field, file_name, file_bytes):
|
||||||
|
url = str(cfg.get("base_url", "")).rstrip("/") + path
|
||||||
|
data, content_type = multipart(fields, file_field, file_name, file_bytes)
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, {"Content-Type": content_type}), method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=180, 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):
|
||||||
|
url = inputs.get("url")
|
||||||
|
if not url:
|
||||||
|
raise Exception("url is required")
|
||||||
|
return request("POST", "/tasks/create/url", cfg, form={"url": url})
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
import json, os, sys, base64, ssl, 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 _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, extra=None):
|
||||||
|
h = {"Accept": "application/json"}
|
||||||
|
if cfg.get("api_token"):
|
||||||
|
h["Authorization"] = "Bearer " + str(cfg["api_token"])
|
||||||
|
if extra:
|
||||||
|
h.update(extra)
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, cfg, body=None, form=None):
|
||||||
|
url = str(cfg.get("base_url", "")).rstrip("/") + path
|
||||||
|
data = None
|
||||||
|
extra = {}
|
||||||
|
if body is not None:
|
||||||
|
data = json.dumps(body).encode("utf-8")
|
||||||
|
extra["Content-Type"] = "application/json"
|
||||||
|
elif form is not None:
|
||||||
|
data = urllib.parse.urlencode(form).encode("utf-8")
|
||||||
|
extra["Content-Type"] = "application/x-www-form-urlencoded"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, extra), method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=120, context=_ctx(cfg)) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def multipart(fields, file_field, file_name, file_bytes):
|
||||||
|
boundary = "----riposte" + uuid.uuid4().hex
|
||||||
|
parts = []
|
||||||
|
for k, v in (fields or {}).items():
|
||||||
|
parts.append(("--" + boundary + "\r\n"
|
||||||
|
'Content-Disposition: form-data; name="' + k + '"\r\n\r\n' + str(v) + "\r\n").encode("utf-8"))
|
||||||
|
parts.append(("--" + 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"))
|
||||||
|
parts.append(file_bytes)
|
||||||
|
parts.append(("\r\n--" + boundary + "--\r\n").encode("utf-8"))
|
||||||
|
return b"".join(parts), "multipart/form-data; boundary=" + boundary
|
||||||
|
|
||||||
|
|
||||||
|
def request_multipart(path, cfg, fields, file_field, file_name, file_bytes):
|
||||||
|
url = str(cfg.get("base_url", "")).rstrip("/") + path
|
||||||
|
data, content_type = multipart(fields, file_field, file_name, file_bytes)
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, {"Content-Type": content_type}), method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=180, 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", "/cuckoo/status", cfg)
|
||||||
|
return {"ok": True}
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
id: triage
|
||||||
|
name: Hatching Triage
|
||||||
|
version: 1.0.0
|
||||||
|
description: "Hatching Triage (tria.ge API v0) — dynamic malware analysis: submit files and URLs, read sample status and analysis overview, list samples, and search. Bearer-token authentication; stdlib-only, no extra Python dependencies."
|
||||||
|
changelog: "1.0.0 — Initial release: submit file/URL, get sample, get report overview, list samples, search."
|
||||||
|
category: enrichment
|
||||||
|
|
||||||
|
# Per-instance configuration. The API key is sent as 'Authorization: Bearer <api_token>'.
|
||||||
|
config_schema:
|
||||||
|
properties:
|
||||||
|
base_url:
|
||||||
|
type: string
|
||||||
|
description: "Triage API base URL"
|
||||||
|
default: "https://tria.ge"
|
||||||
|
api_token:
|
||||||
|
type: string
|
||||||
|
description: "Triage API key"
|
||||||
|
x-soar-sensitive: true
|
||||||
|
required:
|
||||||
|
- api_token
|
||||||
|
|
||||||
|
commands:
|
||||||
|
- id: submit_file
|
||||||
|
name: triage-submit-file
|
||||||
|
description: "Submit a file (base64) for analysis."
|
||||||
|
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: submit_url
|
||||||
|
name: triage-submit-url
|
||||||
|
description: "Submit a URL for analysis."
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
url: { type: string, description: "URL to detonate" }
|
||||||
|
required: [url]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: get_sample
|
||||||
|
name: triage-get-sample
|
||||||
|
description: "Get a sample's status and metadata."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
sample_id: { type: string, description: "Sample ID" }
|
||||||
|
required: [sample_id]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: get_report
|
||||||
|
name: triage-get-report
|
||||||
|
description: "Get a sample's analysis overview (verdict and behavior summary)."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
sample_id: { type: string, description: "Sample ID" }
|
||||||
|
required: [sample_id]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: list_samples
|
||||||
|
name: triage-list-samples
|
||||||
|
description: "List recent samples."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
limit: { type: number, description: "Max samples (default 20)" }
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: search
|
||||||
|
name: triage-search
|
||||||
|
description: "Search samples with a Triage search query."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
query: { type: string, description: "Triage search query (e.g. family:emotet)" }
|
||||||
|
limit: { type: number, description: "Max results (default 20)" }
|
||||||
|
required: [query]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
|
||||||
|
- id: test_connection
|
||||||
|
name: triage-test-connection
|
||||||
|
description: "Verify connectivity and the API key (used by the Test button)."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties: {}
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
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") or "https://tria.ge")).rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
def _headers(cfg, extra=None):
|
||||||
|
h = {"Accept": "application/json", "Authorization": "Bearer " + str(cfg.get("api_token", ""))}
|
||||||
|
if extra:
|
||||||
|
h.update(extra)
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, cfg, body=None, 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)
|
||||||
|
data = None
|
||||||
|
extra = {}
|
||||||
|
if body is not None:
|
||||||
|
data = json.dumps(body).encode("utf-8")
|
||||||
|
extra["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, extra), method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def submit_file_multipart(cfg, file_name, file_bytes, json_meta):
|
||||||
|
# Triage sample submission: multipart with a '_json' text part and a 'file' part.
|
||||||
|
boundary = "----riposte" + uuid.uuid4().hex
|
||||||
|
parts = []
|
||||||
|
parts.append(("--" + boundary + "\r\n"
|
||||||
|
'Content-Disposition: form-data; name="_json"\r\n\r\n' + json.dumps(json_meta) + "\r\n").encode("utf-8"))
|
||||||
|
parts.append(("--" + boundary + "\r\n"
|
||||||
|
'Content-Disposition: form-data; name="file"; filename="' + file_name + '"\r\n'
|
||||||
|
"Content-Type: application/octet-stream\r\n\r\n").encode("utf-8"))
|
||||||
|
parts.append(file_bytes)
|
||||||
|
parts.append(("\r\n--" + boundary + "--\r\n").encode("utf-8"))
|
||||||
|
data = b"".join(parts)
|
||||||
|
req = urllib.request.Request(_base(cfg) + "/api/v0/samples", 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):
|
||||||
|
sample_id = inputs.get("sample_id")
|
||||||
|
if not sample_id:
|
||||||
|
raise Exception("sample_id is required")
|
||||||
|
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||||
|
return request("GET", "/api/v0/samples/" + q(sample_id) + "/overview.json", cfg)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
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") or "https://tria.ge")).rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
def _headers(cfg, extra=None):
|
||||||
|
h = {"Accept": "application/json", "Authorization": "Bearer " + str(cfg.get("api_token", ""))}
|
||||||
|
if extra:
|
||||||
|
h.update(extra)
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, cfg, body=None, 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)
|
||||||
|
data = None
|
||||||
|
extra = {}
|
||||||
|
if body is not None:
|
||||||
|
data = json.dumps(body).encode("utf-8")
|
||||||
|
extra["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, extra), method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def submit_file_multipart(cfg, file_name, file_bytes, json_meta):
|
||||||
|
# Triage sample submission: multipart with a '_json' text part and a 'file' part.
|
||||||
|
boundary = "----riposte" + uuid.uuid4().hex
|
||||||
|
parts = []
|
||||||
|
parts.append(("--" + boundary + "\r\n"
|
||||||
|
'Content-Disposition: form-data; name="_json"\r\n\r\n' + json.dumps(json_meta) + "\r\n").encode("utf-8"))
|
||||||
|
parts.append(("--" + boundary + "\r\n"
|
||||||
|
'Content-Disposition: form-data; name="file"; filename="' + file_name + '"\r\n'
|
||||||
|
"Content-Type: application/octet-stream\r\n\r\n").encode("utf-8"))
|
||||||
|
parts.append(file_bytes)
|
||||||
|
parts.append(("\r\n--" + boundary + "--\r\n").encode("utf-8"))
|
||||||
|
data = b"".join(parts)
|
||||||
|
req = urllib.request.Request(_base(cfg) + "/api/v0/samples", 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):
|
||||||
|
sample_id = inputs.get("sample_id")
|
||||||
|
if not sample_id:
|
||||||
|
raise Exception("sample_id is required")
|
||||||
|
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||||
|
return request("GET", "/api/v0/samples/" + q(sample_id), cfg)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
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") or "https://tria.ge")).rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
def _headers(cfg, extra=None):
|
||||||
|
h = {"Accept": "application/json", "Authorization": "Bearer " + str(cfg.get("api_token", ""))}
|
||||||
|
if extra:
|
||||||
|
h.update(extra)
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, cfg, body=None, 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)
|
||||||
|
data = None
|
||||||
|
extra = {}
|
||||||
|
if body is not None:
|
||||||
|
data = json.dumps(body).encode("utf-8")
|
||||||
|
extra["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, extra), method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def submit_file_multipart(cfg, file_name, file_bytes, json_meta):
|
||||||
|
# Triage sample submission: multipart with a '_json' text part and a 'file' part.
|
||||||
|
boundary = "----riposte" + uuid.uuid4().hex
|
||||||
|
parts = []
|
||||||
|
parts.append(("--" + boundary + "\r\n"
|
||||||
|
'Content-Disposition: form-data; name="_json"\r\n\r\n' + json.dumps(json_meta) + "\r\n").encode("utf-8"))
|
||||||
|
parts.append(("--" + boundary + "\r\n"
|
||||||
|
'Content-Disposition: form-data; name="file"; filename="' + file_name + '"\r\n'
|
||||||
|
"Content-Type: application/octet-stream\r\n\r\n").encode("utf-8"))
|
||||||
|
parts.append(file_bytes)
|
||||||
|
parts.append(("\r\n--" + boundary + "--\r\n").encode("utf-8"))
|
||||||
|
data = b"".join(parts)
|
||||||
|
req = urllib.request.Request(_base(cfg) + "/api/v0/samples", 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):
|
||||||
|
limit = inputs.get("limit")
|
||||||
|
return request("GET", "/api/v0/samples", cfg, params={"subset": "owned", "limit": int(limit or 20)})
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
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") or "https://tria.ge")).rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
def _headers(cfg, extra=None):
|
||||||
|
h = {"Accept": "application/json", "Authorization": "Bearer " + str(cfg.get("api_token", ""))}
|
||||||
|
if extra:
|
||||||
|
h.update(extra)
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, cfg, body=None, 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)
|
||||||
|
data = None
|
||||||
|
extra = {}
|
||||||
|
if body is not None:
|
||||||
|
data = json.dumps(body).encode("utf-8")
|
||||||
|
extra["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, extra), method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def submit_file_multipart(cfg, file_name, file_bytes, json_meta):
|
||||||
|
# Triage sample submission: multipart with a '_json' text part and a 'file' part.
|
||||||
|
boundary = "----riposte" + uuid.uuid4().hex
|
||||||
|
parts = []
|
||||||
|
parts.append(("--" + boundary + "\r\n"
|
||||||
|
'Content-Disposition: form-data; name="_json"\r\n\r\n' + json.dumps(json_meta) + "\r\n").encode("utf-8"))
|
||||||
|
parts.append(("--" + boundary + "\r\n"
|
||||||
|
'Content-Disposition: form-data; name="file"; filename="' + file_name + '"\r\n'
|
||||||
|
"Content-Type: application/octet-stream\r\n\r\n").encode("utf-8"))
|
||||||
|
parts.append(file_bytes)
|
||||||
|
parts.append(("\r\n--" + boundary + "--\r\n").encode("utf-8"))
|
||||||
|
data = b"".join(parts)
|
||||||
|
req = urllib.request.Request(_base(cfg) + "/api/v0/samples", 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):
|
||||||
|
query = inputs.get("query")
|
||||||
|
if not query:
|
||||||
|
raise Exception("query is required")
|
||||||
|
limit = inputs.get("limit")
|
||||||
|
return request("GET", "/api/v0/search", cfg, params={"query": query, "limit": int(limit or 20)})
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
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") or "https://tria.ge")).rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
def _headers(cfg, extra=None):
|
||||||
|
h = {"Accept": "application/json", "Authorization": "Bearer " + str(cfg.get("api_token", ""))}
|
||||||
|
if extra:
|
||||||
|
h.update(extra)
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, cfg, body=None, 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)
|
||||||
|
data = None
|
||||||
|
extra = {}
|
||||||
|
if body is not None:
|
||||||
|
data = json.dumps(body).encode("utf-8")
|
||||||
|
extra["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, extra), method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def submit_file_multipart(cfg, file_name, file_bytes, json_meta):
|
||||||
|
# Triage sample submission: multipart with a '_json' text part and a 'file' part.
|
||||||
|
boundary = "----riposte" + uuid.uuid4().hex
|
||||||
|
parts = []
|
||||||
|
parts.append(("--" + boundary + "\r\n"
|
||||||
|
'Content-Disposition: form-data; name="_json"\r\n\r\n' + json.dumps(json_meta) + "\r\n").encode("utf-8"))
|
||||||
|
parts.append(("--" + boundary + "\r\n"
|
||||||
|
'Content-Disposition: form-data; name="file"; filename="' + file_name + '"\r\n'
|
||||||
|
"Content-Type: application/octet-stream\r\n\r\n").encode("utf-8"))
|
||||||
|
parts.append(file_bytes)
|
||||||
|
parts.append(("\r\n--" + boundary + "--\r\n").encode("utf-8"))
|
||||||
|
data = b"".join(parts)
|
||||||
|
req = urllib.request.Request(_base(cfg) + "/api/v0/samples", 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")
|
||||||
|
content_base64 = inputs.get("content_base64")
|
||||||
|
if not file_name:
|
||||||
|
raise Exception("file_name is required")
|
||||||
|
if not content_base64:
|
||||||
|
raise Exception("content_base64 is required")
|
||||||
|
file_bytes = base64.b64decode(content_base64)
|
||||||
|
return submit_file_multipart(cfg, file_name, file_bytes, {"kind": "file", "interactive": False})
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
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") or "https://tria.ge")).rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
def _headers(cfg, extra=None):
|
||||||
|
h = {"Accept": "application/json", "Authorization": "Bearer " + str(cfg.get("api_token", ""))}
|
||||||
|
if extra:
|
||||||
|
h.update(extra)
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, cfg, body=None, 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)
|
||||||
|
data = None
|
||||||
|
extra = {}
|
||||||
|
if body is not None:
|
||||||
|
data = json.dumps(body).encode("utf-8")
|
||||||
|
extra["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, extra), method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def submit_file_multipart(cfg, file_name, file_bytes, json_meta):
|
||||||
|
# Triage sample submission: multipart with a '_json' text part and a 'file' part.
|
||||||
|
boundary = "----riposte" + uuid.uuid4().hex
|
||||||
|
parts = []
|
||||||
|
parts.append(("--" + boundary + "\r\n"
|
||||||
|
'Content-Disposition: form-data; name="_json"\r\n\r\n' + json.dumps(json_meta) + "\r\n").encode("utf-8"))
|
||||||
|
parts.append(("--" + boundary + "\r\n"
|
||||||
|
'Content-Disposition: form-data; name="file"; filename="' + file_name + '"\r\n'
|
||||||
|
"Content-Type: application/octet-stream\r\n\r\n").encode("utf-8"))
|
||||||
|
parts.append(file_bytes)
|
||||||
|
parts.append(("\r\n--" + boundary + "--\r\n").encode("utf-8"))
|
||||||
|
data = b"".join(parts)
|
||||||
|
req = urllib.request.Request(_base(cfg) + "/api/v0/samples", 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):
|
||||||
|
url = inputs.get("url")
|
||||||
|
if not url:
|
||||||
|
raise Exception("url is required")
|
||||||
|
return request("POST", "/api/v0/samples", cfg, body={"kind": "url", "url": url, "interactive": False})
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
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") or "https://tria.ge")).rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
def _headers(cfg, extra=None):
|
||||||
|
h = {"Accept": "application/json", "Authorization": "Bearer " + str(cfg.get("api_token", ""))}
|
||||||
|
if extra:
|
||||||
|
h.update(extra)
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, cfg, body=None, 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)
|
||||||
|
data = None
|
||||||
|
extra = {}
|
||||||
|
if body is not None:
|
||||||
|
data = json.dumps(body).encode("utf-8")
|
||||||
|
extra["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=_headers(cfg, extra), method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def submit_file_multipart(cfg, file_name, file_bytes, json_meta):
|
||||||
|
# Triage sample submission: multipart with a '_json' text part and a 'file' part.
|
||||||
|
boundary = "----riposte" + uuid.uuid4().hex
|
||||||
|
parts = []
|
||||||
|
parts.append(("--" + boundary + "\r\n"
|
||||||
|
'Content-Disposition: form-data; name="_json"\r\n\r\n' + json.dumps(json_meta) + "\r\n").encode("utf-8"))
|
||||||
|
parts.append(("--" + boundary + "\r\n"
|
||||||
|
'Content-Disposition: form-data; name="file"; filename="' + file_name + '"\r\n'
|
||||||
|
"Content-Type: application/octet-stream\r\n\r\n").encode("utf-8"))
|
||||||
|
parts.append(file_bytes)
|
||||||
|
parts.append(("\r\n--" + boundary + "--\r\n").encode("utf-8"))
|
||||||
|
data = b"".join(parts)
|
||||||
|
req = urllib.request.Request(_base(cfg) + "/api/v0/samples", 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):
|
||||||
|
request("GET", "/api/v0/samples", cfg, params={"subset": "owned", "limit": 1})
|
||||||
|
return {"ok": True}
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
Reference in New Issue
Block a user