import json, os, sys, ssl, io, csv, urllib.request, urllib.error LISTS = { "ips": "https://sslbl.abuse.ch/blacklist/sslipblacklist.csv", "fingerprints": "https://sslbl.abuse.ch/blacklist/sslblacklist.csv", } 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 _headers(cfg): h = {"User-Agent": "Riposte-SOAR"} k = cfg.get("api_key") if k: h["Auth-Key"] = str(k) return h def _get(url, cfg): req = urllib.request.Request(url, headers=_headers(cfg)) 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): key = str(inputs.get("list") or cfg.get("list") or "ips").lower() url = LISTS.get(key, LISTS["ips"]) raw = _get(url, cfg).decode("utf-8", "replace") maxn = int(inputs.get("max_indicators") or 0) out = [] for row in csv.reader(io.StringIO(raw)): if not row or row[0].lstrip().startswith("#"): continue first = row[0].strip() if first.lower() in ("firstseen", "listingdate"): # header row continue if key == "ips": # Firstseen,DstIP,DstPort if len(row) < 2: continue ip = row[1].strip() if not ip: continue item = {"value": ip, "type": "ip"} if len(row) > 2: item["port"] = row[2].strip() out.append(item) else: # Listingdate,SHA1,Listingreason if len(row) < 2: continue fp = row[1].strip() if not fp: continue item = {"value": fp, "type": "hash"} if len(row) > 2: item["reason"] = row[2].strip() out.append(item) if maxn and len(out) >= maxn: break return {"source": "sslbl:" + key, "count": len(out), "indicators": out} _run(main)