Compare commits
3 Commits
6b8dd13297
...
796a95d5f8
| Author | SHA1 | Date | |
|---|---|---|---|
| 796a95d5f8 | |||
| a5db725529 | |||
| ecc301d95d |
@@ -0,0 +1,112 @@
|
|||||||
|
id: anomali_threatstream
|
||||||
|
name: Anomali ThreatStream
|
||||||
|
version: 1.0.0
|
||||||
|
description: "Anomali ThreatStream (API v2/v1) — threat intelligence: reputation lookups for IPs, domains, file hashes and URLs, indicator search, passive DNS, threat-model listing, and indicator import (with or without approval). API-key authentication; stdlib-only, no extra Python dependencies."
|
||||||
|
changelog: "1.0.0 — Initial release: ip/domain/file/url reputation, indicator search, passive DNS, threat models, import indicator."
|
||||||
|
category: threat_intel
|
||||||
|
|
||||||
|
# Per-instance configuration. Auth header 'Authorization: apikey <username>:<api_key>'.
|
||||||
|
config_schema:
|
||||||
|
properties:
|
||||||
|
url:
|
||||||
|
type: string
|
||||||
|
description: "ThreatStream API URL"
|
||||||
|
default: "https://api.threatstream.com"
|
||||||
|
username:
|
||||||
|
type: string
|
||||||
|
description: "ThreatStream username"
|
||||||
|
api_key:
|
||||||
|
type: string
|
||||||
|
description: "ThreatStream API key"
|
||||||
|
x-soar-sensitive: true
|
||||||
|
required:
|
||||||
|
- username
|
||||||
|
- api_key
|
||||||
|
|
||||||
|
commands:
|
||||||
|
- id: ip_reputation
|
||||||
|
name: anomali-ip-reputation
|
||||||
|
description: "Look up threat intelligence for an IP address."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
ip: { type: string, description: "IP address" }
|
||||||
|
required: [ip]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: domain_reputation
|
||||||
|
name: anomali-domain-reputation
|
||||||
|
description: "Look up threat intelligence for a domain."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
domain: { type: string, description: "Domain name" }
|
||||||
|
required: [domain]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: file_reputation
|
||||||
|
name: anomali-file-reputation
|
||||||
|
description: "Look up threat intelligence for a file hash."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
file_hash: { type: string, description: "MD5/SHA1/SHA256 hash" }
|
||||||
|
required: [file_hash]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: url_reputation
|
||||||
|
name: anomali-url-reputation
|
||||||
|
description: "Look up threat intelligence for a URL."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
url: { type: string, description: "URL" }
|
||||||
|
required: [url]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: get_indicators
|
||||||
|
name: anomali-get-indicators
|
||||||
|
description: "Search indicators with a free-text query."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
query: { type: string, description: "ThreatStream search query (q=)" }
|
||||||
|
limit: { type: number, description: "Max indicators (default 20)" }
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: passive_dns
|
||||||
|
name: anomali-passive-dns
|
||||||
|
description: "Get passive DNS records for an IP or domain."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
value: { type: string, description: "IP or domain" }
|
||||||
|
type: { type: string, description: "ip or domain (default ip)" }
|
||||||
|
required: [value]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: get_threat_models
|
||||||
|
name: anomali-get-threat-models
|
||||||
|
description: "List threat models (actors, campaigns, incidents, ...)."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
query: { type: string, description: "Optional name search" }
|
||||||
|
limit: { type: number, description: "Max models (default 20)" }
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: import_indicator
|
||||||
|
name: anomali-import-indicator
|
||||||
|
description: "Import an observable as an indicator (optionally requiring approval)."
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
value: { type: string, description: "Observable value (IP, domain, hash, URL)" }
|
||||||
|
itype: { type: string, description: "Indicator type (e.g. mal_ip, mal_domain, apt_md5)" }
|
||||||
|
confidence: { type: number, description: "Confidence 0-100 (default 50)" }
|
||||||
|
approve: { type: boolean, description: "Import without approval (default false = requires approval)" }
|
||||||
|
required: [value, itype]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
|
||||||
|
- id: test_connection
|
||||||
|
name: anomali-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,54 @@
|
|||||||
|
import json, os, sys, 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("url") or "https://api.threatstream.com")).rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
def _auth(cfg):
|
||||||
|
return "apikey " + str(cfg.get("username", "")) + ":" + str(cfg.get("api_key", ""))
|
||||||
|
|
||||||
|
|
||||||
|
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 = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
domain = inputs.get("domain")
|
||||||
|
if not domain:
|
||||||
|
raise Exception("domain is required")
|
||||||
|
return request("GET", "/api/v2/intelligence/", cfg, params={"value": domain, "type": "domain", "limit": 50})
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
import json, os, sys, 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("url") or "https://api.threatstream.com")).rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
def _auth(cfg):
|
||||||
|
return "apikey " + str(cfg.get("username", "")) + ":" + str(cfg.get("api_key", ""))
|
||||||
|
|
||||||
|
|
||||||
|
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 = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
file_hash = inputs.get("file_hash")
|
||||||
|
if not file_hash:
|
||||||
|
raise Exception("file_hash is required")
|
||||||
|
return request("GET", "/api/v2/intelligence/", cfg, params={"value": file_hash, "type": "md5", "limit": 50})
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
import json, os, sys, 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("url") or "https://api.threatstream.com")).rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
def _auth(cfg):
|
||||||
|
return "apikey " + str(cfg.get("username", "")) + ":" + str(cfg.get("api_key", ""))
|
||||||
|
|
||||||
|
|
||||||
|
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 = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
query = inputs.get("query")
|
||||||
|
limit = inputs.get("limit")
|
||||||
|
return request("GET", "/api/v2/intelligence/", cfg, params={"q": query, "limit": int(limit or 20)})
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
import json, os, sys, 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("url") or "https://api.threatstream.com")).rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
def _auth(cfg):
|
||||||
|
return "apikey " + str(cfg.get("username", "")) + ":" + str(cfg.get("api_key", ""))
|
||||||
|
|
||||||
|
|
||||||
|
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 = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
query = inputs.get("query")
|
||||||
|
limit = inputs.get("limit")
|
||||||
|
return request("GET", "/api/v1/threat_model_search/", cfg, params={"name": query, "limit": int(limit or 20)})
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
import json, os, sys, 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("url") or "https://api.threatstream.com")).rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
def _auth(cfg):
|
||||||
|
return "apikey " + str(cfg.get("username", "")) + ":" + str(cfg.get("api_key", ""))
|
||||||
|
|
||||||
|
|
||||||
|
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 = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
value = inputs.get("value")
|
||||||
|
if not value:
|
||||||
|
raise Exception("value is required")
|
||||||
|
itype = inputs.get("itype")
|
||||||
|
if not itype:
|
||||||
|
raise Exception("itype is required")
|
||||||
|
confidence = inputs.get("confidence")
|
||||||
|
approve = inputs.get("approve")
|
||||||
|
body = {"objects": [{"value": value, "itype": itype, "confidence": int(confidence or 50)}]}
|
||||||
|
params = {}
|
||||||
|
if approve:
|
||||||
|
params["approve"] = "true"
|
||||||
|
return request("POST", "/api/v2/intelligence/", cfg, body=body, params=params or None)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
import json, os, sys, 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("url") or "https://api.threatstream.com")).rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
def _auth(cfg):
|
||||||
|
return "apikey " + str(cfg.get("username", "")) + ":" + str(cfg.get("api_key", ""))
|
||||||
|
|
||||||
|
|
||||||
|
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 = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
ip = inputs.get("ip")
|
||||||
|
if not ip:
|
||||||
|
raise Exception("ip is required")
|
||||||
|
return request("GET", "/api/v2/intelligence/", cfg, params={"value": ip, "type": "ip", "limit": 50})
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
import json, os, sys, 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("url") or "https://api.threatstream.com")).rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
def _auth(cfg):
|
||||||
|
return "apikey " + str(cfg.get("username", "")) + ":" + str(cfg.get("api_key", ""))
|
||||||
|
|
||||||
|
|
||||||
|
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 = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||||
|
value = inputs.get("value")
|
||||||
|
if not value:
|
||||||
|
raise Exception("value is required")
|
||||||
|
itype = inputs.get("type") or "ip"
|
||||||
|
path = "/api/v1/pdns/" + q(itype) + "/" + q(value) + "/"
|
||||||
|
return request("GET", path, cfg)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import json, os, sys, 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("url") or "https://api.threatstream.com")).rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
def _auth(cfg):
|
||||||
|
return "apikey " + str(cfg.get("username", "")) + ":" + str(cfg.get("api_key", ""))
|
||||||
|
|
||||||
|
|
||||||
|
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 = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
request("GET", "/api/v2/intelligence/", cfg, params={"limit": 1})
|
||||||
|
return {"ok": True}
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
import json, os, sys, 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("url") or "https://api.threatstream.com")).rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
def _auth(cfg):
|
||||||
|
return "apikey " + str(cfg.get("username", "")) + ":" + str(cfg.get("api_key", ""))
|
||||||
|
|
||||||
|
|
||||||
|
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 = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
url = inputs.get("url")
|
||||||
|
if not url:
|
||||||
|
raise Exception("url is required")
|
||||||
|
return request("GET", "/api/v2/intelligence/", cfg, params={"value": url, "type": "url", "limit": 50})
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
id: mandiant
|
||||||
|
name: Mandiant Advantage
|
||||||
|
version: 1.0.0
|
||||||
|
description: "Mandiant Advantage Threat Intelligence (API v4) — threat intelligence: look up indicators, threat actors, malware families, and vulnerabilities, and list/read intelligence reports. Key + secret authentication (OAuth2 token exchange); stdlib-only, no extra Python dependencies."
|
||||||
|
changelog: "1.0.0 — Initial release: search/get indicator, get actor/malware/vulnerability, list/get reports."
|
||||||
|
category: threat_intel
|
||||||
|
|
||||||
|
# Per-instance configuration. The key + secret are exchanged (HTTP Basic against
|
||||||
|
# /token) for a bearer token used on the v4 API.
|
||||||
|
config_schema:
|
||||||
|
properties:
|
||||||
|
api_key:
|
||||||
|
type: string
|
||||||
|
description: "Mandiant API key (public key)"
|
||||||
|
secret_key:
|
||||||
|
type: string
|
||||||
|
description: "Mandiant secret key"
|
||||||
|
x-soar-sensitive: true
|
||||||
|
required:
|
||||||
|
- api_key
|
||||||
|
- secret_key
|
||||||
|
|
||||||
|
commands:
|
||||||
|
- id: search_indicator
|
||||||
|
name: mandiant-search-indicator
|
||||||
|
description: "Look up threat intelligence for an indicator value (IP, domain, URL, or hash)."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
value: { type: string, description: "Indicator value" }
|
||||||
|
required: [value]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: get_indicator
|
||||||
|
name: mandiant-get-indicator
|
||||||
|
description: "Get a single indicator by its Mandiant ID."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
indicator_id: { type: string, description: "Mandiant indicator ID" }
|
||||||
|
required: [indicator_id]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: get_actor
|
||||||
|
name: mandiant-get-actor
|
||||||
|
description: "Get a threat actor by ID or name."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
actor_id: { type: string, description: "Threat actor ID or name" }
|
||||||
|
required: [actor_id]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: get_malware
|
||||||
|
name: mandiant-get-malware
|
||||||
|
description: "Get a malware family by ID or name."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
malware_id: { type: string, description: "Malware family ID or name" }
|
||||||
|
required: [malware_id]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: get_vulnerability
|
||||||
|
name: mandiant-get-vulnerability
|
||||||
|
description: "Get vulnerability intelligence by CVE ID."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
cve_id: { type: string, description: "CVE ID (e.g. CVE-2024-1234)" }
|
||||||
|
required: [cve_id]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: list_reports
|
||||||
|
name: mandiant-list-reports
|
||||||
|
description: "List intelligence reports."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
limit: { type: number, description: "Max reports (default 25)" }
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: get_report
|
||||||
|
name: mandiant-get-report
|
||||||
|
description: "Get a single intelligence report by ID."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
report_id: { type: string, description: "Report ID" }
|
||||||
|
required: [report_id]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
|
||||||
|
- id: test_connection
|
||||||
|
name: mandiant-test-connection
|
||||||
|
description: "Verify connectivity and the token exchange (used by the Test button)."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties: {}
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
BASE = "https://api.intelligence.mandiant.com"
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _token(cfg):
|
||||||
|
creds = str(cfg.get("api_key", "")) + ":" + str(cfg.get("secret_key", ""))
|
||||||
|
basic = base64.b64encode(creds.encode("utf-8")).decode("utf-8")
|
||||||
|
form = urllib.parse.urlencode({"grant_type": "client_credentials"}).encode("utf-8")
|
||||||
|
req = urllib.request.Request(BASE + "/token", data=form, headers={
|
||||||
|
"Authorization": "Basic " + basic,
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
|
"Accept": "application/json",
|
||||||
|
}, method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
tok = json.loads(r.read())
|
||||||
|
if not tok.get("access_token"):
|
||||||
|
raise Exception("Token request failed: " + json.dumps(tok))
|
||||||
|
return tok["access_token"]
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, token, body=None, params=None):
|
||||||
|
url = BASE + path
|
||||||
|
if params:
|
||||||
|
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||||
|
if clean:
|
||||||
|
url += "?" + urllib.parse.urlencode(clean)
|
||||||
|
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": "Bearer " + token, "Accept": "application/json", "X-App-Name": "riposte-soar"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
cfg = _cfg()
|
||||||
|
inputs = _inputs()
|
||||||
|
token = _token(cfg)
|
||||||
|
print(json.dumps(fn(token, 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(token, inputs):
|
||||||
|
actor_id = inputs.get("actor_id")
|
||||||
|
if not actor_id:
|
||||||
|
raise Exception("actor_id is required")
|
||||||
|
return request("GET", "/v4/actor/" + q(actor_id), token)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
BASE = "https://api.intelligence.mandiant.com"
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _token(cfg):
|
||||||
|
creds = str(cfg.get("api_key", "")) + ":" + str(cfg.get("secret_key", ""))
|
||||||
|
basic = base64.b64encode(creds.encode("utf-8")).decode("utf-8")
|
||||||
|
form = urllib.parse.urlencode({"grant_type": "client_credentials"}).encode("utf-8")
|
||||||
|
req = urllib.request.Request(BASE + "/token", data=form, headers={
|
||||||
|
"Authorization": "Basic " + basic,
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
|
"Accept": "application/json",
|
||||||
|
}, method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
tok = json.loads(r.read())
|
||||||
|
if not tok.get("access_token"):
|
||||||
|
raise Exception("Token request failed: " + json.dumps(tok))
|
||||||
|
return tok["access_token"]
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, token, body=None, params=None):
|
||||||
|
url = BASE + path
|
||||||
|
if params:
|
||||||
|
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||||
|
if clean:
|
||||||
|
url += "?" + urllib.parse.urlencode(clean)
|
||||||
|
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": "Bearer " + token, "Accept": "application/json", "X-App-Name": "riposte-soar"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
cfg = _cfg()
|
||||||
|
inputs = _inputs()
|
||||||
|
token = _token(cfg)
|
||||||
|
print(json.dumps(fn(token, 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(token, inputs):
|
||||||
|
indicator_id = inputs.get("indicator_id")
|
||||||
|
if not indicator_id:
|
||||||
|
raise Exception("indicator_id is required")
|
||||||
|
return request("GET", "/v4/indicator/" + q(indicator_id), token)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
BASE = "https://api.intelligence.mandiant.com"
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _token(cfg):
|
||||||
|
creds = str(cfg.get("api_key", "")) + ":" + str(cfg.get("secret_key", ""))
|
||||||
|
basic = base64.b64encode(creds.encode("utf-8")).decode("utf-8")
|
||||||
|
form = urllib.parse.urlencode({"grant_type": "client_credentials"}).encode("utf-8")
|
||||||
|
req = urllib.request.Request(BASE + "/token", data=form, headers={
|
||||||
|
"Authorization": "Basic " + basic,
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
|
"Accept": "application/json",
|
||||||
|
}, method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
tok = json.loads(r.read())
|
||||||
|
if not tok.get("access_token"):
|
||||||
|
raise Exception("Token request failed: " + json.dumps(tok))
|
||||||
|
return tok["access_token"]
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, token, body=None, params=None):
|
||||||
|
url = BASE + path
|
||||||
|
if params:
|
||||||
|
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||||
|
if clean:
|
||||||
|
url += "?" + urllib.parse.urlencode(clean)
|
||||||
|
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": "Bearer " + token, "Accept": "application/json", "X-App-Name": "riposte-soar"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
cfg = _cfg()
|
||||||
|
inputs = _inputs()
|
||||||
|
token = _token(cfg)
|
||||||
|
print(json.dumps(fn(token, 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(token, inputs):
|
||||||
|
malware_id = inputs.get("malware_id")
|
||||||
|
if not malware_id:
|
||||||
|
raise Exception("malware_id is required")
|
||||||
|
return request("GET", "/v4/malware/" + q(malware_id), token)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
BASE = "https://api.intelligence.mandiant.com"
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _token(cfg):
|
||||||
|
creds = str(cfg.get("api_key", "")) + ":" + str(cfg.get("secret_key", ""))
|
||||||
|
basic = base64.b64encode(creds.encode("utf-8")).decode("utf-8")
|
||||||
|
form = urllib.parse.urlencode({"grant_type": "client_credentials"}).encode("utf-8")
|
||||||
|
req = urllib.request.Request(BASE + "/token", data=form, headers={
|
||||||
|
"Authorization": "Basic " + basic,
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
|
"Accept": "application/json",
|
||||||
|
}, method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
tok = json.loads(r.read())
|
||||||
|
if not tok.get("access_token"):
|
||||||
|
raise Exception("Token request failed: " + json.dumps(tok))
|
||||||
|
return tok["access_token"]
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, token, body=None, params=None):
|
||||||
|
url = BASE + path
|
||||||
|
if params:
|
||||||
|
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||||
|
if clean:
|
||||||
|
url += "?" + urllib.parse.urlencode(clean)
|
||||||
|
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": "Bearer " + token, "Accept": "application/json", "X-App-Name": "riposte-soar"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
cfg = _cfg()
|
||||||
|
inputs = _inputs()
|
||||||
|
token = _token(cfg)
|
||||||
|
print(json.dumps(fn(token, 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(token, inputs):
|
||||||
|
report_id = inputs.get("report_id")
|
||||||
|
if not report_id:
|
||||||
|
raise Exception("report_id is required")
|
||||||
|
return request("GET", "/v4/report/" + q(report_id), token)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
BASE = "https://api.intelligence.mandiant.com"
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _token(cfg):
|
||||||
|
creds = str(cfg.get("api_key", "")) + ":" + str(cfg.get("secret_key", ""))
|
||||||
|
basic = base64.b64encode(creds.encode("utf-8")).decode("utf-8")
|
||||||
|
form = urllib.parse.urlencode({"grant_type": "client_credentials"}).encode("utf-8")
|
||||||
|
req = urllib.request.Request(BASE + "/token", data=form, headers={
|
||||||
|
"Authorization": "Basic " + basic,
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
|
"Accept": "application/json",
|
||||||
|
}, method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
tok = json.loads(r.read())
|
||||||
|
if not tok.get("access_token"):
|
||||||
|
raise Exception("Token request failed: " + json.dumps(tok))
|
||||||
|
return tok["access_token"]
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, token, body=None, params=None):
|
||||||
|
url = BASE + path
|
||||||
|
if params:
|
||||||
|
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||||
|
if clean:
|
||||||
|
url += "?" + urllib.parse.urlencode(clean)
|
||||||
|
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": "Bearer " + token, "Accept": "application/json", "X-App-Name": "riposte-soar"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
cfg = _cfg()
|
||||||
|
inputs = _inputs()
|
||||||
|
token = _token(cfg)
|
||||||
|
print(json.dumps(fn(token, 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(token, inputs):
|
||||||
|
cve_id = inputs.get("cve_id")
|
||||||
|
if not cve_id:
|
||||||
|
raise Exception("cve_id is required")
|
||||||
|
return request("GET", "/v4/vulnerability/" + q(cve_id), token)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
BASE = "https://api.intelligence.mandiant.com"
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _token(cfg):
|
||||||
|
creds = str(cfg.get("api_key", "")) + ":" + str(cfg.get("secret_key", ""))
|
||||||
|
basic = base64.b64encode(creds.encode("utf-8")).decode("utf-8")
|
||||||
|
form = urllib.parse.urlencode({"grant_type": "client_credentials"}).encode("utf-8")
|
||||||
|
req = urllib.request.Request(BASE + "/token", data=form, headers={
|
||||||
|
"Authorization": "Basic " + basic,
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
|
"Accept": "application/json",
|
||||||
|
}, method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
tok = json.loads(r.read())
|
||||||
|
if not tok.get("access_token"):
|
||||||
|
raise Exception("Token request failed: " + json.dumps(tok))
|
||||||
|
return tok["access_token"]
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, token, body=None, params=None):
|
||||||
|
url = BASE + path
|
||||||
|
if params:
|
||||||
|
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||||
|
if clean:
|
||||||
|
url += "?" + urllib.parse.urlencode(clean)
|
||||||
|
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": "Bearer " + token, "Accept": "application/json", "X-App-Name": "riposte-soar"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
cfg = _cfg()
|
||||||
|
inputs = _inputs()
|
||||||
|
token = _token(cfg)
|
||||||
|
print(json.dumps(fn(token, 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(token, inputs):
|
||||||
|
limit = inputs.get("limit")
|
||||||
|
limit = int(limit) if limit not in (None, "") else 25
|
||||||
|
return request("GET", "/v4/reports", token, params={"limit": limit})
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
BASE = "https://api.intelligence.mandiant.com"
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _token(cfg):
|
||||||
|
creds = str(cfg.get("api_key", "")) + ":" + str(cfg.get("secret_key", ""))
|
||||||
|
basic = base64.b64encode(creds.encode("utf-8")).decode("utf-8")
|
||||||
|
form = urllib.parse.urlencode({"grant_type": "client_credentials"}).encode("utf-8")
|
||||||
|
req = urllib.request.Request(BASE + "/token", data=form, headers={
|
||||||
|
"Authorization": "Basic " + basic,
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
|
"Accept": "application/json",
|
||||||
|
}, method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
tok = json.loads(r.read())
|
||||||
|
if not tok.get("access_token"):
|
||||||
|
raise Exception("Token request failed: " + json.dumps(tok))
|
||||||
|
return tok["access_token"]
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, token, body=None, params=None):
|
||||||
|
url = BASE + path
|
||||||
|
if params:
|
||||||
|
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||||
|
if clean:
|
||||||
|
url += "?" + urllib.parse.urlencode(clean)
|
||||||
|
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": "Bearer " + token, "Accept": "application/json", "X-App-Name": "riposte-soar"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
cfg = _cfg()
|
||||||
|
inputs = _inputs()
|
||||||
|
token = _token(cfg)
|
||||||
|
print(json.dumps(fn(token, 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(token, inputs):
|
||||||
|
value = inputs.get("value")
|
||||||
|
if not value:
|
||||||
|
raise Exception("value is required")
|
||||||
|
body = {"requests": [{"values": [value]}]}
|
||||||
|
return request("POST", "/v4/indicator", token, body=body)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
BASE = "https://api.intelligence.mandiant.com"
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _token(cfg):
|
||||||
|
creds = str(cfg.get("api_key", "")) + ":" + str(cfg.get("secret_key", ""))
|
||||||
|
basic = base64.b64encode(creds.encode("utf-8")).decode("utf-8")
|
||||||
|
form = urllib.parse.urlencode({"grant_type": "client_credentials"}).encode("utf-8")
|
||||||
|
req = urllib.request.Request(BASE + "/token", data=form, headers={
|
||||||
|
"Authorization": "Basic " + basic,
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
|
"Accept": "application/json",
|
||||||
|
}, method="POST")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
tok = json.loads(r.read())
|
||||||
|
if not tok.get("access_token"):
|
||||||
|
raise Exception("Token request failed: " + json.dumps(tok))
|
||||||
|
return tok["access_token"]
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, token, body=None, params=None):
|
||||||
|
url = BASE + path
|
||||||
|
if params:
|
||||||
|
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||||
|
if clean:
|
||||||
|
url += "?" + urllib.parse.urlencode(clean)
|
||||||
|
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": "Bearer " + token, "Accept": "application/json", "X-App-Name": "riposte-soar"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=90) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
cfg = _cfg()
|
||||||
|
inputs = _inputs()
|
||||||
|
token = _token(cfg)
|
||||||
|
print(json.dumps(fn(token, 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(token, inputs):
|
||||||
|
request("GET", "/v4/reports", token, params={"limit": 1})
|
||||||
|
return {"ok": True}
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
id: threatconnect
|
||||||
|
name: ThreatConnect
|
||||||
|
version: 1.0.0
|
||||||
|
description: "ThreatConnect (API v3) — threat intelligence: query and read indicators and groups (TQL), create and delete indicators, create groups, and tag indicators. HMAC-SHA256 signed authentication; stdlib-only, no extra Python dependencies."
|
||||||
|
changelog: "1.0.0 — Initial release: list/get/create/delete indicators, list/get/create groups, add indicator tag."
|
||||||
|
category: threat_intel
|
||||||
|
|
||||||
|
# Per-instance configuration. Requests are signed with HMAC-SHA256 using the
|
||||||
|
# access ID + secret key (header 'Authorization: TC <accessId>:<signature>').
|
||||||
|
config_schema:
|
||||||
|
properties:
|
||||||
|
base_url:
|
||||||
|
type: string
|
||||||
|
description: "ThreatConnect base URL (e.g. https://app.threatconnect.com)"
|
||||||
|
access_id:
|
||||||
|
type: string
|
||||||
|
description: "API access ID"
|
||||||
|
api_secret_key:
|
||||||
|
type: string
|
||||||
|
description: "API secret key"
|
||||||
|
x-soar-sensitive: true
|
||||||
|
required:
|
||||||
|
- base_url
|
||||||
|
- access_id
|
||||||
|
- api_secret_key
|
||||||
|
|
||||||
|
commands:
|
||||||
|
- id: list_indicators
|
||||||
|
name: tc-list-indicators
|
||||||
|
description: "Query indicators using a TQL expression."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
tql: { type: string, description: "ThreatConnect Query Language expression (e.g. summary contains \"1.2.3.4\")" }
|
||||||
|
limit: { type: number, description: "Max indicators (default 50)" }
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: get_indicator
|
||||||
|
name: tc-get-indicator
|
||||||
|
description: "Get a single indicator by ID."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
indicator_id: { type: string, description: "Indicator ID" }
|
||||||
|
required: [indicator_id]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: create_indicator
|
||||||
|
name: tc-create-indicator
|
||||||
|
description: "Create an indicator (e.g. Address, Host, File, URL, EmailAddress)."
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
type: { type: string, description: "Indicator type: Address, Host, File, URL, or EmailAddress" }
|
||||||
|
summary: { type: string, description: "Indicator value (IP, domain, hash, URL, email)" }
|
||||||
|
owner_name: { type: string, description: "Owner (organization) name" }
|
||||||
|
rating: { type: number, description: "Threat rating 0-5 (optional)" }
|
||||||
|
confidence: { type: number, description: "Confidence 0-100 (optional)" }
|
||||||
|
required: [type, summary]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: delete_indicator
|
||||||
|
name: tc-delete-indicator
|
||||||
|
description: "Delete an indicator by ID."
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
indicator_id: { type: string, description: "Indicator ID" }
|
||||||
|
required: [indicator_id]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: list_groups
|
||||||
|
name: tc-list-groups
|
||||||
|
description: "Query groups (incidents, threats, campaigns, ...) using a TQL expression."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
tql: { type: string, description: "TQL expression" }
|
||||||
|
limit: { type: number, description: "Max groups (default 50)" }
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: get_group
|
||||||
|
name: tc-get-group
|
||||||
|
description: "Get a single group by ID."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
group_id: { type: string, description: "Group ID" }
|
||||||
|
required: [group_id]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: create_group
|
||||||
|
name: tc-create-group
|
||||||
|
description: "Create a group (Incident, Threat, Campaign, Adversary, ...)."
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
type: { type: string, description: "Group type: Incident, Threat, Campaign, Adversary, Document, ..." }
|
||||||
|
name: { type: string, description: "Group name" }
|
||||||
|
owner_name: { type: string, description: "Owner (organization) name" }
|
||||||
|
required: [type, name]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: add_indicator_tag
|
||||||
|
name: tc-add-indicator-tag
|
||||||
|
description: "Add a tag to an indicator."
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
indicator_id: { type: string, description: "Indicator ID" }
|
||||||
|
tag: { type: string, description: "Tag name" }
|
||||||
|
required: [indicator_id, tag]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
|
||||||
|
- id: test_connection
|
||||||
|
name: tc-test-connection
|
||||||
|
description: "Verify connectivity and the signed credentials (used by the Test button)."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties: {}
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
import json, os, sys, time, hmac, hashlib, base64
|
||||||
|
import 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 request(method, api_path, cfg, body=None):
|
||||||
|
# api_path MUST include the leading /api/v3/... and any ?query string.
|
||||||
|
base = str(cfg.get("base_url", "")).rstrip("/")
|
||||||
|
url = base + api_path
|
||||||
|
timestamp = str(int(time.time()))
|
||||||
|
to_sign = api_path + ":" + method.upper() + ":" + timestamp
|
||||||
|
secret = str(cfg.get("api_secret_key", "")).encode("utf-8")
|
||||||
|
signature = base64.b64encode(hmac.new(secret, to_sign.encode("utf-8"), hashlib.sha256).digest()).decode("utf-8")
|
||||||
|
authorization = "TC " + str(cfg.get("access_id", "")) + ":" + signature
|
||||||
|
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": authorization, "Timestamp": timestamp, "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
indicator_id = inputs.get("indicator_id")
|
||||||
|
tag = inputs.get("tag")
|
||||||
|
if not indicator_id:
|
||||||
|
raise Exception("indicator_id is required")
|
||||||
|
if not tag:
|
||||||
|
raise Exception("tag is required")
|
||||||
|
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||||
|
path = "/api/v3/indicators/" + q(indicator_id)
|
||||||
|
body = {"tags": {"data": [{"name": tag}], "mode": "append"}}
|
||||||
|
return request("PUT", path, cfg, body)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
import json, os, sys, time, hmac, hashlib, base64
|
||||||
|
import 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 request(method, api_path, cfg, body=None):
|
||||||
|
# api_path MUST include the leading /api/v3/... and any ?query string.
|
||||||
|
base = str(cfg.get("base_url", "")).rstrip("/")
|
||||||
|
url = base + api_path
|
||||||
|
timestamp = str(int(time.time()))
|
||||||
|
to_sign = api_path + ":" + method.upper() + ":" + timestamp
|
||||||
|
secret = str(cfg.get("api_secret_key", "")).encode("utf-8")
|
||||||
|
signature = base64.b64encode(hmac.new(secret, to_sign.encode("utf-8"), hashlib.sha256).digest()).decode("utf-8")
|
||||||
|
authorization = "TC " + str(cfg.get("access_id", "")) + ":" + signature
|
||||||
|
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": authorization, "Timestamp": timestamp, "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
type_ = inputs.get("type")
|
||||||
|
name = inputs.get("name")
|
||||||
|
if not type_:
|
||||||
|
raise Exception("type is required")
|
||||||
|
if not name:
|
||||||
|
raise Exception("name is required")
|
||||||
|
owner_name = inputs.get("owner_name")
|
||||||
|
body = {"type": type_, "name": name}
|
||||||
|
if owner_name:
|
||||||
|
body["ownerName"] = owner_name
|
||||||
|
return request("POST", "/api/v3/groups", cfg, body)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
import json, os, sys, time, hmac, hashlib, base64
|
||||||
|
import 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 request(method, api_path, cfg, body=None):
|
||||||
|
# api_path MUST include the leading /api/v3/... and any ?query string.
|
||||||
|
base = str(cfg.get("base_url", "")).rstrip("/")
|
||||||
|
url = base + api_path
|
||||||
|
timestamp = str(int(time.time()))
|
||||||
|
to_sign = api_path + ":" + method.upper() + ":" + timestamp
|
||||||
|
secret = str(cfg.get("api_secret_key", "")).encode("utf-8")
|
||||||
|
signature = base64.b64encode(hmac.new(secret, to_sign.encode("utf-8"), hashlib.sha256).digest()).decode("utf-8")
|
||||||
|
authorization = "TC " + str(cfg.get("access_id", "")) + ":" + signature
|
||||||
|
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": authorization, "Timestamp": timestamp, "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
type_ = inputs.get("type")
|
||||||
|
summary = inputs.get("summary")
|
||||||
|
if not type_:
|
||||||
|
raise Exception("type is required")
|
||||||
|
if not summary:
|
||||||
|
raise Exception("summary is required")
|
||||||
|
owner_name = inputs.get("owner_name")
|
||||||
|
rating = inputs.get("rating")
|
||||||
|
confidence = inputs.get("confidence")
|
||||||
|
body = {"type": type_, "summary": summary}
|
||||||
|
if owner_name:
|
||||||
|
body["ownerName"] = owner_name
|
||||||
|
if rating not in (None, ""):
|
||||||
|
body["rating"] = int(rating)
|
||||||
|
if confidence not in (None, ""):
|
||||||
|
body["confidence"] = int(confidence)
|
||||||
|
return request("POST", "/api/v3/indicators", cfg, body)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
import json, os, sys, time, hmac, hashlib, base64
|
||||||
|
import 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 request(method, api_path, cfg, body=None):
|
||||||
|
# api_path MUST include the leading /api/v3/... and any ?query string.
|
||||||
|
base = str(cfg.get("base_url", "")).rstrip("/")
|
||||||
|
url = base + api_path
|
||||||
|
timestamp = str(int(time.time()))
|
||||||
|
to_sign = api_path + ":" + method.upper() + ":" + timestamp
|
||||||
|
secret = str(cfg.get("api_secret_key", "")).encode("utf-8")
|
||||||
|
signature = base64.b64encode(hmac.new(secret, to_sign.encode("utf-8"), hashlib.sha256).digest()).decode("utf-8")
|
||||||
|
authorization = "TC " + str(cfg.get("access_id", "")) + ":" + signature
|
||||||
|
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": authorization, "Timestamp": timestamp, "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
indicator_id = inputs.get("indicator_id")
|
||||||
|
if not indicator_id:
|
||||||
|
raise Exception("indicator_id is required")
|
||||||
|
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||||
|
path = "/api/v3/indicators/" + q(indicator_id)
|
||||||
|
result = request("DELETE", path, cfg)
|
||||||
|
if not result:
|
||||||
|
return {"ok": True, "deleted": indicator_id}
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import json, os, sys, time, hmac, hashlib, base64
|
||||||
|
import 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 request(method, api_path, cfg, body=None):
|
||||||
|
# api_path MUST include the leading /api/v3/... and any ?query string.
|
||||||
|
base = str(cfg.get("base_url", "")).rstrip("/")
|
||||||
|
url = base + api_path
|
||||||
|
timestamp = str(int(time.time()))
|
||||||
|
to_sign = api_path + ":" + method.upper() + ":" + timestamp
|
||||||
|
secret = str(cfg.get("api_secret_key", "")).encode("utf-8")
|
||||||
|
signature = base64.b64encode(hmac.new(secret, to_sign.encode("utf-8"), hashlib.sha256).digest()).decode("utf-8")
|
||||||
|
authorization = "TC " + str(cfg.get("access_id", "")) + ":" + signature
|
||||||
|
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": authorization, "Timestamp": timestamp, "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
group_id = inputs.get("group_id")
|
||||||
|
if not group_id:
|
||||||
|
raise Exception("group_id is required")
|
||||||
|
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||||
|
path = "/api/v3/groups/" + q(group_id)
|
||||||
|
return request("GET", path, cfg)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import json, os, sys, time, hmac, hashlib, base64
|
||||||
|
import 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 request(method, api_path, cfg, body=None):
|
||||||
|
# api_path MUST include the leading /api/v3/... and any ?query string.
|
||||||
|
base = str(cfg.get("base_url", "")).rstrip("/")
|
||||||
|
url = base + api_path
|
||||||
|
timestamp = str(int(time.time()))
|
||||||
|
to_sign = api_path + ":" + method.upper() + ":" + timestamp
|
||||||
|
secret = str(cfg.get("api_secret_key", "")).encode("utf-8")
|
||||||
|
signature = base64.b64encode(hmac.new(secret, to_sign.encode("utf-8"), hashlib.sha256).digest()).decode("utf-8")
|
||||||
|
authorization = "TC " + str(cfg.get("access_id", "")) + ":" + signature
|
||||||
|
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": authorization, "Timestamp": timestamp, "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
indicator_id = inputs.get("indicator_id")
|
||||||
|
if not indicator_id:
|
||||||
|
raise Exception("indicator_id is required")
|
||||||
|
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||||
|
path = "/api/v3/indicators/" + q(indicator_id)
|
||||||
|
return request("GET", path, cfg)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
import json, os, sys, time, hmac, hashlib, base64
|
||||||
|
import 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 request(method, api_path, cfg, body=None):
|
||||||
|
# api_path MUST include the leading /api/v3/... and any ?query string.
|
||||||
|
base = str(cfg.get("base_url", "")).rstrip("/")
|
||||||
|
url = base + api_path
|
||||||
|
timestamp = str(int(time.time()))
|
||||||
|
to_sign = api_path + ":" + method.upper() + ":" + timestamp
|
||||||
|
secret = str(cfg.get("api_secret_key", "")).encode("utf-8")
|
||||||
|
signature = base64.b64encode(hmac.new(secret, to_sign.encode("utf-8"), hashlib.sha256).digest()).decode("utf-8")
|
||||||
|
authorization = "TC " + str(cfg.get("access_id", "")) + ":" + signature
|
||||||
|
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": authorization, "Timestamp": timestamp, "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
tql = inputs.get("tql")
|
||||||
|
limit = inputs.get("limit")
|
||||||
|
params = {"resultLimit": int(limit or 50)}
|
||||||
|
if tql:
|
||||||
|
params["tql"] = tql
|
||||||
|
path = "/api/v3/groups?" + urllib.parse.urlencode(params)
|
||||||
|
return request("GET", path, cfg)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
import json, os, sys, time, hmac, hashlib, base64
|
||||||
|
import 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 request(method, api_path, cfg, body=None):
|
||||||
|
# api_path MUST include the leading /api/v3/... and any ?query string.
|
||||||
|
base = str(cfg.get("base_url", "")).rstrip("/")
|
||||||
|
url = base + api_path
|
||||||
|
timestamp = str(int(time.time()))
|
||||||
|
to_sign = api_path + ":" + method.upper() + ":" + timestamp
|
||||||
|
secret = str(cfg.get("api_secret_key", "")).encode("utf-8")
|
||||||
|
signature = base64.b64encode(hmac.new(secret, to_sign.encode("utf-8"), hashlib.sha256).digest()).decode("utf-8")
|
||||||
|
authorization = "TC " + str(cfg.get("access_id", "")) + ":" + signature
|
||||||
|
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": authorization, "Timestamp": timestamp, "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
tql = inputs.get("tql")
|
||||||
|
limit = inputs.get("limit")
|
||||||
|
params = {"resultLimit": int(limit or 50)}
|
||||||
|
if tql:
|
||||||
|
params["tql"] = tql
|
||||||
|
path = "/api/v3/indicators?" + urllib.parse.urlencode(params)
|
||||||
|
return request("GET", path, cfg)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
import json, os, sys, time, hmac, hashlib, base64
|
||||||
|
import 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 request(method, api_path, cfg, body=None):
|
||||||
|
# api_path MUST include the leading /api/v3/... and any ?query string.
|
||||||
|
base = str(cfg.get("base_url", "")).rstrip("/")
|
||||||
|
url = base + api_path
|
||||||
|
timestamp = str(int(time.time()))
|
||||||
|
to_sign = api_path + ":" + method.upper() + ":" + timestamp
|
||||||
|
secret = str(cfg.get("api_secret_key", "")).encode("utf-8")
|
||||||
|
signature = base64.b64encode(hmac.new(secret, to_sign.encode("utf-8"), hashlib.sha256).digest()).decode("utf-8")
|
||||||
|
authorization = "TC " + str(cfg.get("access_id", "")) + ":" + signature
|
||||||
|
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Authorization": authorization, "Timestamp": timestamp, "Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
path = "/api/v3/indicators?" + urllib.parse.urlencode({"resultLimit": 1})
|
||||||
|
request("GET", path, cfg)
|
||||||
|
return {"ok": True}
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
Reference in New Issue
Block a user