diff --git a/integrations/harfanglab/manifest.yaml b/integrations/harfanglab/manifest.yaml index 3c41012..666f0dc 100644 --- a/integrations/harfanglab/manifest.yaml +++ b/integrations/harfanglab/manifest.yaml @@ -1,8 +1,8 @@ id: harfanglab name: HarfangLab EDR -version: 1.5.0 +version: 1.6.0 description: "HarfangLab EDR — endpoint detection & response: alert/threat ingestion, endpoint enrichment, isolation, threat-intelligence (IOC/whitelist), telemetry hunting and forensic collection jobs." -changelog: "1.5.0 — Declare the risk tier on the 71 commands that carried none: 39 read, 24 safe_write, 8 destructive. An unset risk is read as destructive by the agent approval gate, so the 63 that only read or only annotate sat behind the same prompt as the ones that change the estate. deisolate_from_threat and unquarantine_file move from safe_write to destructive in the same pass: undoing a containment mid-incident is its own decision, and is tiered like the containment it lifts. | 1.4.1 — get_alerts now maps image_name, the one process path present on every alert subtype and the only one on those carrying neither a process object nor an event log (yara, binary, ioc). HarfangLab prefixes it with the matched threat name in brackets, so both halves are split out: the clean path feeds actor.process.file.path and its basename actor.process.name, and the threat name feeds malware.name — which now surfaces on every subtype rather than only on Defender event-log detections. Each half is guarded on the bracket being present so an unprefixed path is never written into malware.name. 1.4.0 — Mapper coverage from real payloads: get_alerts now maps the Windows event-log payload sigma alerts carry (alert_subtype = eventlog), which was entirely unmapped — Defender 1116/1117 yields the malware name, classification, severity and provider, the detected file, the process that touched it and the acting user, plus the log provider and event code. Also added the agent IP, DNS domain, device type, agent version and groups, the tenant, the alert subtype and threat type, the string severity and the event time. get_threats gained the threat level (previously never reaching the OCSF document at all), the event time and the top agent's reachability. 1.3.1 — Flagged get_alerts as ingestion-ready (ingest hints: results_path/dedup/incremental on from_date) so it appears in the recommended ingestion commands when creating an instance. 1.3.0 — Response & triage expansion: kill/dump process, on-demand AV/YARA scans, file/service/scheduled-task deletion, quarantine management, threat-level isolation, job cancel/relaunch/wait; alert search (get_alerts) and full alert/threat triage (tag, comments, notes, status, level, history, details); exhaustive alert OCSF mappers; reworked get_threats mapper (fixed MITRE tactics map handling, full top-agent/user/rule and counts coverage, rule-based incident title/description). 1.2.2 — Documentation wording cleanup. 1.2.1 — Corrected the get_threats OCSF mapper to native threat fields (top_agents/top_impacted_users/top_rules/mitre_tactics) instead of enriched-only arrays; added agent.osversion to get_security_events. 1.2.0 — Added ingestion commands get_security_events (alerts) and get_threats with bundled OCSF mappers and ingest hints (results_path/dedup/incremental). 1.1.1 — Added test_connection for the instance Test button. 1.1.0 — Command names prefixed with 'harfanglab-' (e.g. harfanglab-isolate-endpoint) for easier toolbox search; command IDs unchanged. 1.0.0 — Initial release: endpoint/agent management, isolation, policy assignment, IOC & whitelist management, security-event triage, telemetry hunting (processes, network, DNS, authentications, binaries, event logs), threat hunting by hash, and forensic collection jobs (pipes, prefetch, run keys, scheduled tasks, drivers, services, processes, network, sessions, WMI, IOC scan, artifacts, RAM dump) with their result retrieval commands. Compatible with HarfangLab EDR 2.13.7+." +changelog: "1.6.0 — New endpoint_count command: counts agents matching filters without listing them. The HarfangLab agent collection is DRF-paginated, so its `count` field already carries the filtered total; endpoint_count asks for limit=1 and reads it, instead of pulling up to 10000 agent records back through the playbook the way endpoint_search does. Filters cover the documented agent query parameters (hostname, os, version, status, isolation_state, tenant, network), add lastseen/firstseen bounds, and leave a raw `filters` escape hatch for the rest. The API silently drops a parameter it does not recognise as a filter — which turns a typo into a plausible-looking fleet-wide total — so the fleet `total` is returned next to `count` to make that case visible. | 1.5.0 — Declare the risk tier on the 71 commands that carried none: 39 read, 24 safe_write, 8 destructive. An unset risk is read as destructive by the agent approval gate, so the 63 that only read or only annotate sat behind the same prompt as the ones that change the estate. deisolate_from_threat and unquarantine_file move from safe_write to destructive in the same pass: undoing a containment mid-incident is its own decision, and is tiered like the containment it lifts. | 1.4.1 — get_alerts now maps image_name, the one process path present on every alert subtype and the only one on those carrying neither a process object nor an event log (yara, binary, ioc). HarfangLab prefixes it with the matched threat name in brackets, so both halves are split out: the clean path feeds actor.process.file.path and its basename actor.process.name, and the threat name feeds malware.name — which now surfaces on every subtype rather than only on Defender event-log detections. Each half is guarded on the bracket being present so an unprefixed path is never written into malware.name. 1.4.0 — Mapper coverage from real payloads: get_alerts now maps the Windows event-log payload sigma alerts carry (alert_subtype = eventlog), which was entirely unmapped — Defender 1116/1117 yields the malware name, classification, severity and provider, the detected file, the process that touched it and the acting user, plus the log provider and event code. Also added the agent IP, DNS domain, device type, agent version and groups, the tenant, the alert subtype and threat type, the string severity and the event time. get_threats gained the threat level (previously never reaching the OCSF document at all), the event time and the top agent's reachability. 1.3.1 — Flagged get_alerts as ingestion-ready (ingest hints: results_path/dedup/incremental on from_date) so it appears in the recommended ingestion commands when creating an instance. 1.3.0 — Response & triage expansion: kill/dump process, on-demand AV/YARA scans, file/service/scheduled-task deletion, quarantine management, threat-level isolation, job cancel/relaunch/wait; alert search (get_alerts) and full alert/threat triage (tag, comments, notes, status, level, history, details); exhaustive alert OCSF mappers; reworked get_threats mapper (fixed MITRE tactics map handling, full top-agent/user/rule and counts coverage, rule-based incident title/description). 1.2.2 — Documentation wording cleanup. 1.2.1 — Corrected the get_threats OCSF mapper to native threat fields (top_agents/top_impacted_users/top_rules/mitre_tactics) instead of enriched-only arrays; added agent.osversion to get_security_events. 1.2.0 — Added ingestion commands get_security_events (alerts) and get_threats with bundled OCSF mappers and ingest hints (results_path/dedup/incremental). 1.1.1 — Added test_connection for the instance Test button. 1.1.0 — Command names prefixed with 'harfanglab-' (e.g. harfanglab-isolate-endpoint) for easier toolbox search; command IDs unchanged. 1.0.0 — Initial release: endpoint/agent management, isolation, policy assignment, IOC & whitelist management, security-event triage, telemetry hunting (processes, network, DNS, authentications, binaries, event logs), threat hunting by hash, and forensic collection jobs (pipes, prefetch, run keys, scheduled tasks, drivers, services, processes, network, sessions, WMI, IOC scan, artifacts, RAM dump) with their result retrieval commands. Compatible with HarfangLab EDR 2.13.7+." category: endpoint # Per-instance configuration. Scripts use as the API base and call /api/... paths. @@ -83,6 +83,32 @@ commands: hostname: { type: string, description: "Hostname to filter agents by" } required: [] outputs_schema: { properties: {} } + - id: endpoint_count + name: harfanglab-endpoint-count + description: "Count endpoints (agents) matching filters, without listing them. Returns {count, total, filters}: count is the number of matching agents, total the whole fleet. An unrecognised filter is silently ignored by the API, so compare count against total before trusting a figure." + risk: read + inputs_schema: + properties: + hostname: { type: string, description: "Exact hostname" } + domainname: { type: string, description: "Exact DNS domain name" } + domain: { type: string, description: "Exact Windows domain" } + ipaddress: { type: string, description: "Exact internal IP address" } + external_ipaddress: { type: string, description: "Exact external IP address" } + ostype: { type: string, description: "Operating system type (windows, linux, macos)" } + osproducttype: { type: string, description: "OS product type, e.g. Server or Workstation" } + osversion: { type: string, description: "Exact OS version string" } + producttype: { type: string, description: "Exact product type" } + version: { type: string, description: "Exact agent version" } + status: { type: string, description: "Agent status, e.g. online or offline" } + isolation_state: { type: boolean, description: "true counts isolated agents, false counts non-isolated ones" } + tenant: { type: string, description: "Exact tenant identifier" } + lastseen_after: { type: string, description: "ISO8601 lower bound on lastseen — agents seen since that instant" } + lastseen_before: { type: string, description: "ISO8601 upper bound on lastseen — agents not seen since that instant" } + firstseen_after: { type: string, description: "ISO8601 lower bound on firstseen — agents enrolled since that instant" } + firstseen_before: { type: string, description: "ISO8601 upper bound on firstseen" } + filters: { type: string, description: "Any other API filter, as k=v pairs joined by & (e.g. groups__name=Serveurs&osmajor=10)" } + required: [] + outputs_schema: { properties: {} } - id: isolate_endpoint name: harfanglab-isolate-endpoint description: Network-isolate an endpoint (agent) by agent ID. diff --git a/integrations/harfanglab/scripts/endpoint_count.py b/integrations/harfanglab/scripts/endpoint_count.py new file mode 100644 index 0000000..c1f741d --- /dev/null +++ b/integrations/harfanglab/scripts/endpoint_count.py @@ -0,0 +1,112 @@ +import json, os, sys, urllib.request, urllib.parse, urllib.error + + +def request(method, url, headers, body=None): + data = json.dumps(body).encode("utf-8") if body is not None else None + req = urllib.request.Request(url, data=data, headers=headers, method=method) + with urllib.request.urlopen(req, timeout=60) as resp: + raw = resp.read() + return json.loads(raw) if raw else {} + + +def qs(params): + clean = {} + for k, v in params.items(): + if v is None or v == "" or v == []: + continue + if isinstance(v, bool): + v = "true" if v else "false" + clean[k] = v + return ("?" + urllib.parse.urlencode(clean)) if clean else "" + + +def csv(v): + return [x.strip() for x in str(v or "").split(",") if x.strip()] + + +# Agent fields HarfangLab exposes as exact-match query filters on +# /api/data/endpoint/Agent/. Input name == API filter name. +EXACT_FILTERS = [ + "hostname", + "domainname", + "domain", + "ipaddress", + "external_ipaddress", + "ostype", + "osproducttype", + "osversion", + "producttype", + "version", + "status", + "isolation_state", + "tenant", +] + +# Convenience bounds mapped onto Django REST Framework range lookups. +RANGE_FILTERS = { + "lastseen_after": "lastseen__gte", + "lastseen_before": "lastseen__lte", + "firstseen_after": "firstseen__gte", + "firstseen_before": "firstseen__lte", +} + + +def to_bool(v): + if isinstance(v, bool): + return v + return str(v).strip().lower() in ("true", "1", "yes") + + +def main(): + secrets = json.loads(os.environ.get("INTEGRATION_SECRETS", "{}")) + inputs = json.loads(os.environ.get("INTEGRATION_INPUTS", "{}")) + base = secrets.get("url", "").rstrip("/") + headers = { + "Authorization": "Token " + secrets.get("api_token", ""), + "Accept": "application/json", + "Content-Type": "application/json", + } + # === per-command logic === + filters = {} + for field in EXACT_FILTERS: + value = inputs.get(field) + if value is None or value == "": + continue + filters[field] = to_bool(value) if field == "isolation_state" else value + for field, lookup in RANGE_FILTERS.items(): + value = inputs.get(field) + if value: + filters[lookup] = value + # Escape hatch for any filter this command does not name explicitly, + # e.g. "groups__name=Serveurs&osmajor=10". + for tok in str(inputs.get("filters") or "").split("&"): + kv = tok.split("=", 1) + if len(kv) == 2 and kv[0].strip(): + filters[kv[0].strip()] = kv[1] + + # The agent list is a DRF paginated collection: `count` is the total number + # of matches, independent of the page size. limit=1 keeps the payload tiny. + agents = base + "/api/data/endpoint/Agent/" + matched = request("GET", agents + qs(dict(filters, limit=1, offset=0)), headers) + result = {"count": matched.get("count", 0), "filters": filters} + + # The API silently drops a query parameter it does not recognise as a + # filter, which yields the unfiltered total dressed up as a filtered count. + # Returning the fleet total alongside makes that failure visible. + if filters: + everything = request("GET", agents + qs({"limit": 1, "offset": 0}), headers) + result["total"] = everything.get("count", 0) + else: + result["total"] = result["count"] + + print(json.dumps(result)) + + +try: + main() +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)