feat(feed): add Microsoft 365 endpoints feed connector (allowlist / known infra)
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
id: feed_office365
|
||||
name: Microsoft 365 Endpoints Feed
|
||||
version: 1.0.0
|
||||
description: "Microsoft 365 endpoints feed connector — pull the official published IP ranges and URLs for Microsoft 365 / Office 365 services and emit normalized IOCs (CIDR and domain + type, with service area) for import into the Threat Indicator Manager. Intended as an allowlist / known-infrastructure feed (mark benign in TIM). Free public endpoint, no authentication required; stdlib-only, no extra Python dependencies."
|
||||
changelog: "1.0.0 — Initial release: fetch the Microsoft 365 worldwide endpoints (IPs + URLs)."
|
||||
category: feed
|
||||
|
||||
# The endpoints.office.com service is free. instance selects the cloud
|
||||
# (Worldwide, USGovDoD, USGovGCCHigh, China, Germany).
|
||||
config_schema:
|
||||
properties:
|
||||
instance:
|
||||
type: string
|
||||
description: "Which M365 cloud instance: Worldwide, USGovDoD, USGovGCCHigh, China, Germany (default Worldwide)"
|
||||
default: "Worldwide"
|
||||
include_urls:
|
||||
type: boolean
|
||||
description: "Also emit the published service URLs as domain indicators (default true)"
|
||||
default: true
|
||||
insecure:
|
||||
type: boolean
|
||||
description: "Trust any TLS certificate (not secure)"
|
||||
default: false
|
||||
required: []
|
||||
|
||||
commands:
|
||||
- id: fetch_indicators
|
||||
name: feed-office365-fetch-indicators
|
||||
description: "Fetch the Microsoft 365 endpoints and return normalized indicators."
|
||||
risk: read
|
||||
inputs_schema:
|
||||
properties:
|
||||
instance: { type: string, description: "Cloud instance (overrides config)" }
|
||||
include_urls: { type: boolean, description: "Emit URLs as domain indicators (overrides config)" }
|
||||
max_indicators: { type: number, description: "Max indicators to return (0 = no limit, default 0)" }
|
||||
required: []
|
||||
outputs_schema: { properties: {} }
|
||||
|
||||
- id: test_connection
|
||||
name: feed-office365-test-connection
|
||||
description: "Verify the Microsoft 365 endpoints service is reachable (used by the Test button)."
|
||||
risk: read
|
||||
inputs_schema:
|
||||
properties: {}
|
||||
required: []
|
||||
outputs_schema: { properties: {} }
|
||||
@@ -0,0 +1,89 @@
|
||||
import json, os, sys, ssl, urllib.parse, urllib.request, urllib.error
|
||||
|
||||
BASE = "https://endpoints.office.com/endpoints/"
|
||||
# A fixed client request id is acceptable for this public, unauthenticated API.
|
||||
CLIENT_ID = "b10c5ed1-bad1-445f-b386-b919946339a7"
|
||||
|
||||
|
||||
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 _get(url, cfg):
|
||||
req = urllib.request.Request(
|
||||
url, headers={"User-Agent": "Riposte-SOAR", "Accept": "application/json"}
|
||||
)
|
||||
with urllib.request.urlopen(req, timeout=120, context=_ctx(cfg)) as r:
|
||||
return r.read()
|
||||
|
||||
|
||||
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):
|
||||
instance = str(inputs.get("instance") or cfg.get("instance") or "Worldwide")
|
||||
include_urls = inputs.get("include_urls")
|
||||
if include_urls is None:
|
||||
include_urls = cfg.get("include_urls")
|
||||
if include_urls is None:
|
||||
include_urls = True
|
||||
|
||||
url = BASE + urllib.parse.quote(instance, safe="") + "?" + urllib.parse.urlencode({"clientrequestid": CLIENT_ID})
|
||||
raw = _get(url, cfg)
|
||||
data = json.loads(raw) if raw else []
|
||||
if not isinstance(data, list):
|
||||
data = []
|
||||
|
||||
maxn = int(inputs.get("max_indicators") or 0)
|
||||
seen = set()
|
||||
out = []
|
||||
|
||||
def add(value, typ, area):
|
||||
key = (typ, value)
|
||||
if key in seen:
|
||||
return False
|
||||
seen.add(key)
|
||||
out.append({"value": value, "type": typ, "service_area": area, "provider": "microsoft365"})
|
||||
return not (maxn and len(out) >= maxn)
|
||||
|
||||
for ep in data:
|
||||
if not isinstance(ep, dict):
|
||||
continue
|
||||
area = ep.get("serviceArea")
|
||||
for cidr in ep.get("ips", []) or []:
|
||||
typ = "cidr" if "/" in str(cidr) else "ip"
|
||||
if not add(str(cidr), typ, area):
|
||||
return {"source": "microsoft365:" + instance, "count": len(out), "indicators": out}
|
||||
if include_urls:
|
||||
for u in ep.get("urls", []) or []:
|
||||
dom = str(u).lstrip("*.").strip()
|
||||
if not dom:
|
||||
continue
|
||||
if not add(dom, "domain", area):
|
||||
return {"source": "microsoft365:" + instance, "count": len(out), "indicators": out}
|
||||
|
||||
return {"source": "microsoft365:" + instance, "count": len(out), "indicators": out}
|
||||
|
||||
|
||||
_run(main)
|
||||
@@ -0,0 +1,52 @@
|
||||
import json, os, sys, ssl, urllib.parse, urllib.request, urllib.error
|
||||
|
||||
BASE = "https://endpoints.office.com/endpoints/"
|
||||
CLIENT_ID = "b10c5ed1-bad1-445f-b386-b919946339a7"
|
||||
|
||||
|
||||
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 _get(url, cfg):
|
||||
req = urllib.request.Request(
|
||||
url, headers={"User-Agent": "Riposte-SOAR", "Accept": "application/json"}
|
||||
)
|
||||
with urllib.request.urlopen(req, timeout=60, context=_ctx(cfg)) as r:
|
||||
return r.read()
|
||||
|
||||
|
||||
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):
|
||||
instance = str(cfg.get("instance") or "Worldwide")
|
||||
url = BASE + urllib.parse.quote(instance, safe="") + "?" + urllib.parse.urlencode({"clientrequestid": CLIENT_ID})
|
||||
raw = _get(url, cfg)
|
||||
data = json.loads(raw) if raw else []
|
||||
n = len(data) if isinstance(data, list) else 0
|
||||
return {"ok": True, "endpoint_sets": n, "instance": instance}
|
||||
|
||||
|
||||
_run(main)
|
||||
Reference in New Issue
Block a user