Compare commits

...

3 Commits

Author SHA1 Message Date
Guillaume BOURGEOIS c779c38dab feat(feed-taxii2): new generic TAXII 2.1 / STIX feed connector
Pulls STIX 2.x indicators from any TAXII 2.1 server, parses the STIX patterns
into normalized IOCs {value,type} for TIM import. list-collections + fetch.
Basic/bearer/none auth, stdlib-only. py_compile clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-12 22:43:17 +02:00
Guillaume BOURGEOIS 4f94b59e17 feat(feed-plaintext): new generic plain-text threat-intel feed connector
Fetches a line-per-indicator blocklist URL and emits normalized IOCs {value,type}
for TIM import. Comment-char/field-index/type config, auto type-detection.
Optional bearer auth, stdlib-only. py_compile clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-12 22:43:17 +02:00
Guillaume BOURGEOIS f09d00114f feat(feed-csv): new generic CSV threat-intel feed connector
Fetches a delimited feed URL and emits normalized IOCs {value,type} for TIM
import (works with the /indicators/feed-extract -> /indicators/bulk flow).
Column/delimiter/comment/type config, auto type-detection. New 'feed' category.
Optional bearer auth, stdlib-only. py_compile clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-12 22:43:16 +02:00
10 changed files with 790 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
id: feed_csv
name: CSV Feed
version: 1.0.0
description: "Generic CSV threat-intel feed connector — fetch a CSV (or delimited) indicator list from a URL and emit normalized IOCs (value + type) for import into the Threat Indicator Manager. One connector, many feeds. No authentication (or an optional bearer token); stdlib-only, no extra Python dependencies."
changelog: "1.0.0 — Initial release: fetch indicators from a delimited feed URL."
category: feed
# Per-instance configuration. The feed is fetched over HTTP(S) from feed_url.
# An optional bearer token is sent if the feed requires authentication.
config_schema:
properties:
feed_url:
type: string
description: "URL of the CSV/delimited feed"
api_token:
type: string
description: "Optional bearer token (if the feed requires auth)"
x-soar-sensitive: true
insecure:
type: boolean
description: "Trust any TLS certificate (not secure)"
default: false
required:
- feed_url
commands:
- id: fetch_indicators
name: feed-csv-fetch-indicators
description: "Fetch and parse the CSV feed, returning normalized indicators."
risk: read
inputs_schema:
properties:
value_column: { type: number, description: "0-based column index holding the IOC value (default 0)" }
delimiter: { type: string, description: "Field delimiter (default ',')" }
ioc_type: { type: string, description: "auto | ip | domain | url | hash | email (default auto — detect per value)" }
skip_header: { type: boolean, description: "Skip the first row (default false)" }
comment_char: { type: string, description: "Lines starting with this are ignored (default '#')" }
max_indicators: { type: number, description: "Max indicators to return (default 10000)" }
required: []
outputs_schema: { properties: {} }
- id: test_connection
name: feed-csv-test-connection
description: "Verify the feed URL is reachable (used by the Test button)."
risk: read
inputs_schema:
properties: {}
required: []
outputs_schema: { properties: {} }
@@ -0,0 +1,107 @@
import json, os, sys, io, csv, re, ssl, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def _fetch(cfg):
url = str(cfg.get("feed_url", ""))
if not url:
raise Exception("feed_url is not configured")
headers = {"Accept": "text/plain, text/csv, */*", "User-Agent": "Riposte-SOAR"}
if cfg.get("api_token"):
headers["Authorization"] = "Bearer " + str(cfg["api_token"])
req = urllib.request.Request(url, headers=headers, method="GET")
with urllib.request.urlopen(req, timeout=120, context=_ctx(cfg)) as r:
return r.read().decode("utf-8", "replace")
_IPV4 = re.compile(r"^\d{1,3}(?:\.\d{1,3}){3}(?:/\d{1,2})?$")
_HASH = re.compile(r"^[a-fA-F0-9]{32}$|^[a-fA-F0-9]{40}$|^[a-fA-F0-9]{64}$")
_EMAIL = re.compile(r"^[^@\s]+@[^@\s]+\.[^@\s]+$")
def detect_type(value):
v = value.strip()
if _IPV4.match(v) or (":" in v and re.match(r"^[0-9a-fA-F:]+$", v)):
return "ip"
if v.lower().startswith("http://") or v.lower().startswith("https://"):
return "url"
if _EMAIL.match(v):
return "email"
if _HASH.match(v):
return "hash"
if "." in v and " " not in v:
return "domain"
return "unknown"
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):
text = _fetch(cfg)
value_column = inputs.get("value_column", 0)
delimiter = inputs.get("delimiter", ",")
ioc_type = inputs.get("ioc_type", "auto")
skip_header = inputs.get("skip_header", False)
comment_char = inputs.get("comment_char", "#")
max_indicators = inputs.get("max_indicators", 10000)
col = int(value_column or 0)
delim = (delimiter or ",")
if delim == "\\t":
delim = "\t"
cc = (comment_char or "#")
itype = (ioc_type or "auto")
cap = int(max_indicators or 10000)
indicators = []
header_skipped = False
reader = csv.reader(io.StringIO(text), delimiter=delim)
for row in reader:
if len(indicators) >= cap:
break
if not row:
continue
if row[0].strip().startswith(cc):
continue
if skip_header and not header_skipped:
header_skipped = True
continue
if len(row) > col:
val = row[col].strip()
if not val:
continue
t = itype if itype != "auto" else detect_type(val)
if t == "unknown":
continue
indicators.append({"value": val, "type": t})
return {"source": cfg.get("feed_url"), "count": len(indicators), "indicators": indicators}
_run(main)
@@ -0,0 +1,69 @@
import json, os, sys, io, csv, re, ssl, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def _fetch(cfg):
url = str(cfg.get("feed_url", ""))
if not url:
raise Exception("feed_url is not configured")
headers = {"Accept": "text/plain, text/csv, */*", "User-Agent": "Riposte-SOAR"}
if cfg.get("api_token"):
headers["Authorization"] = "Bearer " + str(cfg["api_token"])
req = urllib.request.Request(url, headers=headers, method="GET")
with urllib.request.urlopen(req, timeout=120, context=_ctx(cfg)) as r:
return r.read().decode("utf-8", "replace")
_IPV4 = re.compile(r"^\d{1,3}(?:\.\d{1,3}){3}(?:/\d{1,2})?$")
_HASH = re.compile(r"^[a-fA-F0-9]{32}$|^[a-fA-F0-9]{40}$|^[a-fA-F0-9]{64}$")
_EMAIL = re.compile(r"^[^@\s]+@[^@\s]+\.[^@\s]+$")
def detect_type(value):
v = value.strip()
if _IPV4.match(v) or (":" in v and re.match(r"^[0-9a-fA-F:]+$", v)):
return "ip"
if v.lower().startswith("http://") or v.lower().startswith("https://"):
return "url"
if _EMAIL.match(v):
return "email"
if _HASH.match(v):
return "hash"
if "." in v and " " not in v:
return "domain"
return "unknown"
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):
body = _fetch(cfg)
return {"ok": True, "bytes": len(body)}
_run(main)
+46
View File
@@ -0,0 +1,46 @@
id: feed_plaintext
name: Plain Text Feed
version: 1.0.0
description: "Generic plain-text threat-intel feed connector — fetch a line-per-indicator list from a URL (e.g. an IP or domain blocklist) and emit normalized IOCs (value + type) for import into the Threat Indicator Manager. One connector, many feeds. No authentication (or an optional bearer token); stdlib-only, no extra Python dependencies."
changelog: "1.0.0 — Initial release: fetch indicators from a plain-text feed URL."
category: feed
# Per-instance configuration. The feed is fetched over HTTP(S) from feed_url.
config_schema:
properties:
feed_url:
type: string
description: "URL of the plain-text feed (one indicator per line)"
api_token:
type: string
description: "Optional bearer token (if the feed requires auth)"
x-soar-sensitive: true
insecure:
type: boolean
description: "Trust any TLS certificate (not secure)"
default: false
required:
- feed_url
commands:
- id: fetch_indicators
name: feed-plaintext-fetch-indicators
description: "Fetch and parse the plain-text feed, returning normalized indicators."
risk: read
inputs_schema:
properties:
ioc_type: { type: string, description: "auto | ip | domain | url | hash | email (default auto — detect per value)" }
comment_char: { type: string, description: "Lines starting with this are ignored (default '#')" }
field_index: { type: number, description: "If lines have multiple whitespace-separated fields, the 0-based field to take (default 0)" }
max_indicators: { type: number, description: "Max indicators to return (default 10000)" }
required: []
outputs_schema: { properties: {} }
- id: test_connection
name: feed-plaintext-test-connection
description: "Verify the feed URL is reachable (used by the Test button)."
risk: read
inputs_schema:
properties: {}
required: []
outputs_schema: { properties: {} }
@@ -0,0 +1,92 @@
import json, os, sys, re, ssl, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def _fetch(cfg):
url = str(cfg.get("feed_url", ""))
if not url:
raise Exception("feed_url is not configured")
headers = {"Accept": "text/plain, */*", "User-Agent": "Riposte-SOAR"}
if cfg.get("api_token"):
headers["Authorization"] = "Bearer " + str(cfg["api_token"])
req = urllib.request.Request(url, headers=headers, method="GET")
with urllib.request.urlopen(req, timeout=120, context=_ctx(cfg)) as r:
return r.read().decode("utf-8", "replace")
_IPV4 = re.compile(r"^\d{1,3}(?:\.\d{1,3}){3}(?:/\d{1,2})?$")
_HASH = re.compile(r"^[a-fA-F0-9]{32}$|^[a-fA-F0-9]{40}$|^[a-fA-F0-9]{64}$")
_EMAIL = re.compile(r"^[^@\s]+@[^@\s]+\.[^@\s]+$")
def detect_type(value):
v = value.strip()
if _IPV4.match(v) or (":" in v and re.match(r"^[0-9a-fA-F:]+$", v)):
return "ip"
if v.lower().startswith("http://") or v.lower().startswith("https://"):
return "url"
if _EMAIL.match(v):
return "email"
if _HASH.match(v):
return "hash"
if "." in v and " " not in v:
return "domain"
return "unknown"
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):
text = _fetch(cfg)
cc = inputs.get("comment_char") or "#"
itype = inputs.get("ioc_type") or "auto"
fi = int(inputs.get("field_index") or 0)
cap = int(inputs.get("max_indicators") or 10000)
indicators = []
for line in text.splitlines():
line = line.strip()
if not line or line.startswith(cc):
continue
fields = line.split()
if len(fields) <= fi:
continue
val = fields[fi].strip()
if not val:
continue
type_ = itype if itype != "auto" else detect_type(val)
if type_ == "unknown":
continue
indicators.append({"value": val, "type": type_})
if len(indicators) >= cap:
break
return {"source": cfg.get("feed_url"), "count": len(indicators), "indicators": indicators}
_run(main)
@@ -0,0 +1,69 @@
import json, os, sys, re, ssl, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def _fetch(cfg):
url = str(cfg.get("feed_url", ""))
if not url:
raise Exception("feed_url is not configured")
headers = {"Accept": "text/plain, */*", "User-Agent": "Riposte-SOAR"}
if cfg.get("api_token"):
headers["Authorization"] = "Bearer " + str(cfg["api_token"])
req = urllib.request.Request(url, headers=headers, method="GET")
with urllib.request.urlopen(req, timeout=120, context=_ctx(cfg)) as r:
return r.read().decode("utf-8", "replace")
_IPV4 = re.compile(r"^\d{1,3}(?:\.\d{1,3}){3}(?:/\d{1,2})?$")
_HASH = re.compile(r"^[a-fA-F0-9]{32}$|^[a-fA-F0-9]{40}$|^[a-fA-F0-9]{64}$")
_EMAIL = re.compile(r"^[^@\s]+@[^@\s]+\.[^@\s]+$")
def detect_type(value):
v = value.strip()
if _IPV4.match(v) or (":" in v and re.match(r"^[0-9a-fA-F:]+$", v)):
return "ip"
if v.lower().startswith("http://") or v.lower().startswith("https://"):
return "url"
if _EMAIL.match(v):
return "email"
if _HASH.match(v):
return "hash"
if "." in v and " " not in v:
return "domain"
return "unknown"
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):
body = _fetch(cfg)
return {"ok": True, "bytes": len(body)}
_run(main)
+64
View File
@@ -0,0 +1,64 @@
id: feed_taxii2
name: TAXII 2 Feed
version: 1.0.0
description: "Generic TAXII 2.1 threat-intel feed connector — pull STIX 2.x indicators from any TAXII 2.1 server (OpenCTI, Anomali, MISP, CISA AIS, ...) and emit normalized IOCs (value + type) parsed from the STIX patterns, for import into the Threat Indicator Manager. Basic or bearer authentication; stdlib-only, no extra Python dependencies."
changelog: "1.0.0 — Initial release: list collections, fetch indicators from a TAXII 2.1 collection."
category: feed
# Per-instance configuration. api_root_url is the TAXII 2.1 API root
# (e.g. https://server/taxii2/api1). auth_type selects none/basic/bearer.
config_schema:
properties:
api_root_url:
type: string
description: "TAXII 2.1 API root URL (e.g. https://server/taxii2/api1)"
collection_id:
type: string
description: "Default collection ID to fetch from"
auth_type:
type: string
description: "none, basic, or bearer (default basic)"
default: "basic"
username:
type: string
description: "Username (for basic auth)"
password:
type: string
description: "Password (basic) or token (bearer)"
x-soar-sensitive: true
insecure:
type: boolean
description: "Trust any TLS certificate (not secure)"
default: false
required:
- api_root_url
commands:
- id: list_collections
name: feed-taxii2-list-collections
description: "List the collections available on the TAXII 2.1 API root."
risk: read
inputs_schema:
properties: {}
required: []
outputs_schema: { properties: {} }
- id: fetch_indicators
name: feed-taxii2-fetch-indicators
description: "Fetch STIX indicators from a collection and return normalized IOCs."
risk: read
inputs_schema:
properties:
collection_id: { type: string, description: "Collection ID (defaults to the configured one)" }
added_after: { type: string, description: "Only objects added after this timestamp (ISO-8601)" }
limit: { type: number, description: "Max objects to request (default 500)" }
required: []
outputs_schema: { properties: {} }
- id: test_connection
name: feed-taxii2-test-connection
description: "Verify the TAXII server and credentials (used by the Test button)."
risk: read
inputs_schema:
properties: {}
required: []
outputs_schema: { properties: {} }
@@ -0,0 +1,117 @@
import json, os, sys, re, ssl, base64, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def _root(cfg):
return str(cfg.get("api_root_url", "")).rstrip("/")
def _headers(cfg):
h = {"Accept": "application/taxii+json;version=2.1", "User-Agent": "Riposte-SOAR"}
at = str(cfg.get("auth_type") or "basic").lower()
if at == "basic":
raw = str(cfg.get("username", "")) + ":" + str(cfg.get("password", ""))
h["Authorization"] = "Basic " + base64.b64encode(raw.encode("utf-8")).decode("ascii")
elif at == "bearer":
h["Authorization"] = "Bearer " + str(cfg.get("password", ""))
return h
def request(path, cfg, params=None):
url = _root(cfg) + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
req = urllib.request.Request(url, headers=_headers(cfg), method="GET")
with urllib.request.urlopen(req, timeout=120, context=_ctx(cfg)) as r:
raw = r.read()
return json.loads(raw) if raw else {}
# STIX pattern parsing: extract stix object type + value from an indicator pattern
# e.g. [ipv4-addr:value = '1.2.3.4'] , [domain-name:value = 'bad.com'] ,
# [file:hashes.'SHA-256' = 'abc...'] , [url:value = 'http://x']
_PAT = re.compile(r"(\w[\w-]*):(?:value|hashes\.'?[\w:-]+'?)\s*=\s*'([^']+)'")
_STIX_TYPE = {
"ipv4-addr": "ip", "ipv6-addr": "ip",
"domain-name": "domain",
"url": "url",
"email-addr": "email", "email-message": "email",
"file": "hash",
"user-account": "user",
}
def parse_pattern(pattern):
out = []
for m in _PAT.finditer(pattern or ""):
stix_type, value = m.group(1), m.group(2)
t = _STIX_TYPE.get(stix_type)
if t:
out.append({"value": value, "type": t})
return out
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
q = lambda v: urllib.parse.quote(str(v), safe="")
def main(cfg, inputs):
cid = inputs.get("collection_id") or cfg.get("collection_id")
if not cid:
raise Exception("collection_id is required")
added_after = inputs.get("added_after")
limit = inputs.get("limit")
resp = request(
"/collections/" + q(cid) + "/objects/",
cfg,
params={"added_after": added_after, "limit": int(limit or 500)},
)
indicators = []
for obj in resp.get("objects", []):
if obj.get("type") == "indicator":
for parsed in parse_pattern(obj.get("pattern")):
parsed["stix_id"] = obj.get("id")
parsed["labels"] = obj.get("labels")
indicators.append(parsed)
return {
"collection_id": cid,
"count": len(indicators),
"indicators": indicators,
"more": resp.get("more", False),
}
_run(main)
@@ -0,0 +1,88 @@
import json, os, sys, re, ssl, base64, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def _root(cfg):
return str(cfg.get("api_root_url", "")).rstrip("/")
def _headers(cfg):
h = {"Accept": "application/taxii+json;version=2.1", "User-Agent": "Riposte-SOAR"}
at = str(cfg.get("auth_type") or "basic").lower()
if at == "basic":
raw = str(cfg.get("username", "")) + ":" + str(cfg.get("password", ""))
h["Authorization"] = "Basic " + base64.b64encode(raw.encode("utf-8")).decode("ascii")
elif at == "bearer":
h["Authorization"] = "Bearer " + str(cfg.get("password", ""))
return h
def request(path, cfg, params=None):
url = _root(cfg) + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
req = urllib.request.Request(url, headers=_headers(cfg), method="GET")
with urllib.request.urlopen(req, timeout=120, context=_ctx(cfg)) as r:
raw = r.read()
return json.loads(raw) if raw else {}
# STIX pattern parsing: extract stix object type + value from an indicator pattern
# e.g. [ipv4-addr:value = '1.2.3.4'] , [domain-name:value = 'bad.com'] ,
# [file:hashes.'SHA-256' = 'abc...'] , [url:value = 'http://x']
_PAT = re.compile(r"(\w[\w-]*):(?:value|hashes\.'?[\w:-]+'?)\s*=\s*'([^']+)'")
_STIX_TYPE = {
"ipv4-addr": "ip", "ipv6-addr": "ip",
"domain-name": "domain",
"url": "url",
"email-addr": "email", "email-message": "email",
"file": "hash",
"user-account": "user",
}
def parse_pattern(pattern):
out = []
for m in _PAT.finditer(pattern or ""):
stix_type, value = m.group(1), m.group(2)
t = _STIX_TYPE.get(stix_type)
if t:
out.append({"value": value, "type": t})
return out
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
return request("/collections/", cfg)
_run(main)
@@ -0,0 +1,89 @@
import json, os, sys, re, ssl, base64, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _ctx(cfg):
if cfg.get("insecure"):
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
return c
return None
def _root(cfg):
return str(cfg.get("api_root_url", "")).rstrip("/")
def _headers(cfg):
h = {"Accept": "application/taxii+json;version=2.1", "User-Agent": "Riposte-SOAR"}
at = str(cfg.get("auth_type") or "basic").lower()
if at == "basic":
raw = str(cfg.get("username", "")) + ":" + str(cfg.get("password", ""))
h["Authorization"] = "Basic " + base64.b64encode(raw.encode("utf-8")).decode("ascii")
elif at == "bearer":
h["Authorization"] = "Bearer " + str(cfg.get("password", ""))
return h
def request(path, cfg, params=None):
url = _root(cfg) + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
req = urllib.request.Request(url, headers=_headers(cfg), method="GET")
with urllib.request.urlopen(req, timeout=120, context=_ctx(cfg)) as r:
raw = r.read()
return json.loads(raw) if raw else {}
# STIX pattern parsing: extract stix object type + value from an indicator pattern
# e.g. [ipv4-addr:value = '1.2.3.4'] , [domain-name:value = 'bad.com'] ,
# [file:hashes.'SHA-256' = 'abc...'] , [url:value = 'http://x']
_PAT = re.compile(r"(\w[\w-]*):(?:value|hashes\.'?[\w:-]+'?)\s*=\s*'([^']+)'")
_STIX_TYPE = {
"ipv4-addr": "ip", "ipv6-addr": "ip",
"domain-name": "domain",
"url": "url",
"email-addr": "email", "email-message": "email",
"file": "hash",
"user-account": "user",
}
def parse_pattern(pattern):
out = []
for m in _PAT.finditer(pattern or ""):
stix_type, value = m.group(1), m.group(2)
t = _STIX_TYPE.get(stix_type)
if t:
out.append({"value": value, "type": t})
return out
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("/collections/", cfg)
return {"ok": True}
_run(main)