feat(feed): add Microsoft 365 endpoints feed connector (allowlist / known infra)

This commit is contained in:
Guillaume BOURGEOIS
2026-07-13 12:15:50 +02:00
parent 40252dadcb
commit ae7c494658
3 changed files with 187 additions and 0 deletions
@@ -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)