feat(threatq): new ThreatQ threat-intel integration
ThreatQ REST API, 5 commands: search/get indicators, create indicator, list events. OAuth2 password-grant auth, stdlib-only. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,78 @@
|
|||||||
|
id: threatq
|
||||||
|
name: ThreatQ
|
||||||
|
version: 1.0.0
|
||||||
|
description: "ThreatQuotient ThreatQ (REST API) — threat intelligence: search and read indicators, create an indicator, and list events. OAuth2 password-grant authentication; stdlib-only, no extra Python dependencies."
|
||||||
|
changelog: "1.0.0 — Initial release: search/get indicators, create indicator, list events."
|
||||||
|
category: threat_intel
|
||||||
|
|
||||||
|
# Per-instance configuration. Credentials are exchanged for a bearer token at
|
||||||
|
# /api/token; API calls go to /api.
|
||||||
|
config_schema:
|
||||||
|
properties:
|
||||||
|
base_url:
|
||||||
|
type: string
|
||||||
|
description: "ThreatQ URL (e.g. https://threatq.example.com)"
|
||||||
|
client_id:
|
||||||
|
type: string
|
||||||
|
description: "OAuth client ID"
|
||||||
|
email:
|
||||||
|
type: string
|
||||||
|
description: "ThreatQ user email"
|
||||||
|
password:
|
||||||
|
type: string
|
||||||
|
description: "ThreatQ password"
|
||||||
|
x-soar-sensitive: true
|
||||||
|
required:
|
||||||
|
- base_url
|
||||||
|
- client_id
|
||||||
|
- email
|
||||||
|
- password
|
||||||
|
|
||||||
|
commands:
|
||||||
|
- id: search_indicators
|
||||||
|
name: threatq-search-indicators
|
||||||
|
description: "Search indicators by value."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
value: { type: string, description: "Indicator value to search" }
|
||||||
|
limit: { type: number, description: "Max indicators (default 25)" }
|
||||||
|
required: [value]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: get_indicator
|
||||||
|
name: threatq-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: threatq-create-indicator
|
||||||
|
description: "Create an indicator."
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
value: { type: string, description: "Indicator value" }
|
||||||
|
type: { type: string, description: "Indicator type (e.g. IP Address, FQDN, MD5)" }
|
||||||
|
status: { type: string, description: "Status (e.g. Active, Review) — default Review" }
|
||||||
|
required: [value, type]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: list_events
|
||||||
|
name: threatq-list-events
|
||||||
|
description: "List events."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
limit: { type: number, description: "Max events (default 25)" }
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
|
||||||
|
- id: test_connection
|
||||||
|
name: threatq-test-connection
|
||||||
|
description: "Verify credentials via the token exchange (used by the Test button)."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties: {}
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
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("base_url", "")).rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
def _token(cfg):
|
||||||
|
body = json.dumps({
|
||||||
|
"grant_type": "password",
|
||||||
|
"email": str(cfg.get("email", "")),
|
||||||
|
"password": str(cfg.get("password", "")),
|
||||||
|
"client_id": str(cfg.get("client_id", "")),
|
||||||
|
}).encode("utf-8")
|
||||||
|
req = urllib.request.Request(_base(cfg) + "/api/token", data=body,
|
||||||
|
headers={"Content-Type": "application/json", "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, cfg, token, body=None, params=None):
|
||||||
|
url = _base(cfg) + "/api" + 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"}
|
||||||
|
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:
|
||||||
|
cfg = _cfg()
|
||||||
|
inputs = _inputs()
|
||||||
|
token = _token(cfg)
|
||||||
|
print(json.dumps(fn(cfg, 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(cfg, token, inputs):
|
||||||
|
value = inputs.get("value")
|
||||||
|
if not value:
|
||||||
|
raise Exception("value is required")
|
||||||
|
type_ = inputs.get("type")
|
||||||
|
if not type_:
|
||||||
|
raise Exception("type is required")
|
||||||
|
status = inputs.get("status")
|
||||||
|
return request("POST", "/indicators", cfg, token, body={
|
||||||
|
"value": value,
|
||||||
|
"type": type_,
|
||||||
|
"status": (status or "Review"),
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
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("base_url", "")).rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
def _token(cfg):
|
||||||
|
body = json.dumps({
|
||||||
|
"grant_type": "password",
|
||||||
|
"email": str(cfg.get("email", "")),
|
||||||
|
"password": str(cfg.get("password", "")),
|
||||||
|
"client_id": str(cfg.get("client_id", "")),
|
||||||
|
}).encode("utf-8")
|
||||||
|
req = urllib.request.Request(_base(cfg) + "/api/token", data=body,
|
||||||
|
headers={"Content-Type": "application/json", "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, cfg, token, body=None, params=None):
|
||||||
|
url = _base(cfg) + "/api" + 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"}
|
||||||
|
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:
|
||||||
|
cfg = _cfg()
|
||||||
|
inputs = _inputs()
|
||||||
|
token = _token(cfg)
|
||||||
|
print(json.dumps(fn(cfg, 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(cfg, token, inputs):
|
||||||
|
indicator_id = inputs.get("indicator_id")
|
||||||
|
if not indicator_id:
|
||||||
|
raise Exception("indicator_id is required")
|
||||||
|
return request("GET", "/indicators/" + q(indicator_id), cfg, token)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
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("base_url", "")).rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
def _token(cfg):
|
||||||
|
body = json.dumps({
|
||||||
|
"grant_type": "password",
|
||||||
|
"email": str(cfg.get("email", "")),
|
||||||
|
"password": str(cfg.get("password", "")),
|
||||||
|
"client_id": str(cfg.get("client_id", "")),
|
||||||
|
}).encode("utf-8")
|
||||||
|
req = urllib.request.Request(_base(cfg) + "/api/token", data=body,
|
||||||
|
headers={"Content-Type": "application/json", "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, cfg, token, body=None, params=None):
|
||||||
|
url = _base(cfg) + "/api" + 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"}
|
||||||
|
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:
|
||||||
|
cfg = _cfg()
|
||||||
|
inputs = _inputs()
|
||||||
|
token = _token(cfg)
|
||||||
|
print(json.dumps(fn(cfg, 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(cfg, token, inputs):
|
||||||
|
limit = inputs.get("limit")
|
||||||
|
limit = int(limit) if limit not in (None, "") else 25
|
||||||
|
return request("GET", "/events", cfg, token, params={"limit": limit})
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
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("base_url", "")).rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
def _token(cfg):
|
||||||
|
body = json.dumps({
|
||||||
|
"grant_type": "password",
|
||||||
|
"email": str(cfg.get("email", "")),
|
||||||
|
"password": str(cfg.get("password", "")),
|
||||||
|
"client_id": str(cfg.get("client_id", "")),
|
||||||
|
}).encode("utf-8")
|
||||||
|
req = urllib.request.Request(_base(cfg) + "/api/token", data=body,
|
||||||
|
headers={"Content-Type": "application/json", "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, cfg, token, body=None, params=None):
|
||||||
|
url = _base(cfg) + "/api" + 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"}
|
||||||
|
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:
|
||||||
|
cfg = _cfg()
|
||||||
|
inputs = _inputs()
|
||||||
|
token = _token(cfg)
|
||||||
|
print(json.dumps(fn(cfg, 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(cfg, token, inputs):
|
||||||
|
value = inputs.get("value")
|
||||||
|
if not value:
|
||||||
|
raise Exception("value is required")
|
||||||
|
limit = inputs.get("limit")
|
||||||
|
limit = int(limit) if limit not in (None, "") else 25
|
||||||
|
return request("GET", "/indicators", cfg, token, params={"value": value, "limit": limit})
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
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("base_url", "")).rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
def _token(cfg):
|
||||||
|
body = json.dumps({
|
||||||
|
"grant_type": "password",
|
||||||
|
"email": str(cfg.get("email", "")),
|
||||||
|
"password": str(cfg.get("password", "")),
|
||||||
|
"client_id": str(cfg.get("client_id", "")),
|
||||||
|
}).encode("utf-8")
|
||||||
|
req = urllib.request.Request(_base(cfg) + "/api/token", data=body,
|
||||||
|
headers={"Content-Type": "application/json", "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, cfg, token, body=None, params=None):
|
||||||
|
url = _base(cfg) + "/api" + 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"}
|
||||||
|
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:
|
||||||
|
cfg = _cfg()
|
||||||
|
inputs = _inputs()
|
||||||
|
token = _token(cfg)
|
||||||
|
print(json.dumps(fn(cfg, 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(cfg, token, inputs):
|
||||||
|
request("GET", "/indicators", cfg, token, params={"limit": 1})
|
||||||
|
return {"ok": True}
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
Reference in New Issue
Block a user