Open-source AI Security Operations Center: alert fusion, LLM-agent triage, MITRE ATT&CK investigation, and a replayable decision ledger for every agent step. Self-hostable, runs with no API keys, MIT licensed. Ships an MCP server for Claude, Cursor and Continue.
Python agentic-aiai-securityalert-triageblue-teamcybersecuritydetection-engineeringincident-responselanggraphllm-agentsmcpmitre-attackmodel-context-protocolpurple-teamsecurity-operationsself-hostedsiemsoarsocthreat-detectionthreat-intelligence
feat: AiSOC v6 capability roadmap — federated search, detection-as-code, hunt-as-code, eval harness, SEO & CI hardening
Beenu Aroraba0ffaaef15e
diff --git a/.github/ISSUE_TEMPLATE/benchmark_submission.yml b/.github/ISSUE_TEMPLATE/benchmark_submission.ymlnew file mode 100644index 000000000..f7f5c58fc--- /dev/null+++ b/.github/ISSUE_TEMPLATE/benchmark_submission.yml@@ -0,0 +1,86 @@+name: Benchmark submission+description: Submit a run of the AiSOC public eval harness for the community scoreboard.+title: "[benchmark] <agent name> @ <commit-sha>"+labels: ["benchmark-submission", "needs-triage"]+body:+ - type: markdown+ attributes:+ value: |+ Use this form to submit a run of the AiSOC public eval harness against the fixed 200-incident dataset.+ The harness, dataset, and grading code are MIT-licensed and fully reproducible. See the full rules at+ [tryaisoc.com/benchmark](https://tryaisoc.com/benchmark) and the methodology in+ [`apps/docs/docs/benchmark.md`](../blob/main/apps/docs/docs/benchmark.md).++ Reviewers will re-run your submission on a clean checkout. Submissions that cannot be reproduced+ will not be merged onto the public leaderboard.+ - type: input+ id: agent_name+ attributes:+ label: Agent name+ description: A short, recognizable name (e.g. "AiSOC main", "team-foo-detector-v2").+ placeholder: e.g. AiSOC main+ validations:+ required: true+ - type: input+ id: agent_url+ attributes:+ label: Agent source URL+ description: Link to the source repo or release. If closed-source, write "closed-source" — your entry will still be accepted, just labeled.+ placeholder: e.g. https://github.com/your-org/your-agent OR closed-source+ validations:+ required: true+ - type: input+ id: commit_sha+ attributes:+ label: AiSOC commit SHA+ description: The commit of the AiSOC repo you ran against (must include `services/agents/tests/eval_data/synthetic_incidents.json` unchanged).+ placeholder: e.g. abc1234+ validations:+ required: true+ - type: dropdown+ id: dataset_modified+ attributes:+ label: Was the dataset modified?+ description: The substrate is fixed — modifying it disqualifies the submission.+ options:+ - "No — I ran against the unmodified 200-incident dataset"+ - "Yes — I added/changed cases (this submission will be rejected)"+ validations:+ required: true+ - type: textarea+ id: command+ attributes:+ label: Command used+ description: The exact command you ran to produce the report.+ placeholder: |+ python3 scripts/run_evals.py --json --out report.json+ render: shell+ validations:+ required: true+ - type: textarea+ id: report_json+ attributes:+ label: Report JSON+ description: |+ Paste the full contents of the generated `report.json` (or attach as a file by dragging it into the comment box after submission).+ Reviewers need every field — per-template macros are not optional.+ render: json+ validations:+ required: true+ - type: textarea+ id: notes+ attributes:+ label: Notes+ description: Anything reviewers should know — hardware, model used, deviations from defaults, etc.+ placeholder: e.g. ran with GPT-4o + temperature 0.0; 64GB M3 Max; 12-minute total runtime+ - type: checkboxes+ id: confirmations+ attributes:+ label: Confirmations+ options:+ - label: I ran the unmodified `scripts/run_evals.py` against the fixed dataset.+ required: true+ - label: I did not template-stuff the substrate self-consistency suites (MITRE / completeness / response).+ required: true+ - label: I understand reviewers will re-run my submission on a clean checkout before merging.+ required: truediff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 5c7524fb3..7dc116247 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -23,11 +23,9 @@ jobs:steps:- uses: actions/checkout@v4- uses: pnpm/action-setup@v4- with:- version: 9- uses: actions/setup-node@v4with:- node-version: '20'+ node-version: '22'cache: pnpmcache-dependency-path: pnpm-lock.yaml- run: pnpm install --frozen-lockfile@@ -53,11 +51,9 @@ jobs:steps:- uses: actions/checkout@v4- uses: pnpm/action-setup@v4- with:- version: 9- uses: actions/setup-node@v4with:- node-version: '20'+ node-version: '22'cache: pnpmcache-dependency-path: pnpm-lock.yaml- run: pnpm install --frozen-lockfile@@ -76,11 +72,9 @@ jobs:steps:- uses: actions/checkout@v4- uses: pnpm/action-setup@v4- with:- version: 9- uses: actions/setup-node@v4with:- node-version: '20'+ node-version: '22'cache: pnpmcache-dependency-path: pnpm-lock.yaml- run: pnpm install --frozen-lockfile@@ -100,11 +94,9 @@ jobs:steps:- uses: actions/checkout@v4- uses: pnpm/action-setup@v4- with:- version: 9- uses: actions/setup-node@v4with:- node-version: '20'+ node-version: '22'cache: pnpmcache-dependency-path: pnpm-lock.yaml- name: Install workspace deps@@ -258,11 +250,9 @@ jobs:steps:- uses: actions/checkout@v4- uses: pnpm/action-setup@v4- with:- version: 9- uses: actions/setup-node@v4with:- node-version: '20'+ node-version: '22'cache: pnpmcache-dependency-path: pnpm-lock.yaml- name: Install workspace deps@@ -364,8 +354,42 @@ jobs:- uses: actions/setup-python@v5with:python-version: '3.12'+ - name: Pull last published baseline from eval-results branch+ # Wave 2 — w2-dac. We fetch `eval/results/latest.json` from the+ # `eval-results` orphan branch (published by the publish step below+ # on main). When present, the eval runner gates a ≥1pp MITRE+ # regression vs. that baseline; missing baseline = no-op.+ if: github.event_name == 'pull_request'+ env:+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}+ run: |+ set -e+ mkdir -p /tmp/eval-baseline+ if git fetch origin eval-results:eval-results 2>/dev/null; then+ git --no-pager show eval-results:eval/results/latest.json \+ > /tmp/eval-baseline/latest.json 2>/dev/null \+ || rm -f /tmp/eval-baseline/latest.json+ fi+ if [ -f /tmp/eval-baseline/latest.json ]; then+ echo "Baseline found at /tmp/eval-baseline/latest.json"+ else+ echo "No baseline yet — first run will publish one."+ fi- name: Run all eval suites- run: python3 scripts/run_evals.py --ci --out eval_report.json+ # On PRs we additionally gate against the published baseline so a+ # detection-as-code merge that drops MITRE accuracy by ≥ 1pp blocks+ # CI (exit code 2). On push to main, `--baseline` is omitted so the+ # publish step below establishes a fresh baseline.+ run: |+ if [ -f /tmp/eval-baseline/latest.json ]; then+ python3 scripts/run_evals.py \+ --ci \+ --baseline /tmp/eval-baseline/latest.json \+ --max-regression-pp 1.0 \+ --out eval_report.json+ else+ python3 scripts/run_evals.py --ci --out eval_report.json+ fi- name: Post job summaryif: always()run: |diff --git a/README.md b/README.mdindex d3077be8c..15e0b04eb 100644--- a/README.md+++ b/README.md@@ -15,6 +15,8 @@ An open-source, self-hostable AI SOC. The agent's prompts, tool calls, and ratio<sub>The demo at <a href="https://tryaisoc.com">tryaisoc.com</a> is a self-hosted instance fronted by a Cloudflare Tunnel — when it's reachable, the stack is running locally on a maintainer's box. It can therefore go offline at any time. To run your own (in 3.5 min, with seeded data), see <a href="#one-shot-demo">One-shot demo</a>; to expose your own instance on your own domain via Cloudflare Tunnel, see <a href="#public-demo-on-your-own-domain">Public demo on your own domain</a>.</sub>+[](https://github.com/beenuar/AiSOC/topics)+</div>---@@ -92,6 +94,7 @@ AiSOC bundles the components a SOC normally pieces together from separate vendor- **Connect data sources in three clicks** — a click-and-connect catalog (Microsoft Entra, Azure Activity, Defender XDR, GCP Cloud Audit, GCP SCC, Microsoft 365 audit, Google Workspace, Cloudflare, GitHub, plus the original CrowdStrike / Splunk / AWS Security Hub / Okta / Microsoft Sentinel set) renders a schema-driven form per connector, runs a live `Test connection` round-trip before save, encrypts every secret with the application-layer `CredentialVault` (Fernet AES-128-CBC + HMAC-SHA256), and starts polling on a per-instance schedule. Walkthrough: [docs/connectors](apps/docs/docs/connectors/index.md). Threat model + key rotation: [docs/operations/credentials](apps/docs/docs/operations/credentials.md).- **Ingest** events from any connector into a Kafka spine.- **Correlate** them in real time with deduplication, ML scoring, and Sigma/YARA detection.+- **Roll up signal onto entities** — Risk-Based Alerting accumulates time-decayed risk points on the user, host, IP, and domain each alert touches, promotes them to entity-incidents at a tunable threshold, and surfaces an entity-centric queue in the alerts UI. Hits the published 2026 KPI bar of ≥ 50:1 alert-to-incident ratio (CI-gated in [`services/fusion/tests/test_entity_risk.py`](services/fusion/tests/test_entity_risk.py)).- **Enrich** every signal with threat intelligence from TAXII 2.1, MISP, OTX, and CISA KEV.- **Reason** about attacks via a LangGraph multi-agent system grounded in MITRE ATT&CK.- **Detect deviations** with UEBA — per-user behavioural baselines and Z-score anomaly scoring.@@ -114,6 +117,7 @@ Everything ships under MIT. Fork it, self-host it, audit it, extend it.- Kafka spine with sub-second ingestion- Bloom-filter dedup on 10M+ IOCs- LightGBM + Isolation Forest scoring+- Risk-Based Alerting entity rollup (≥ 50:1 alert-to-incident, CI-gated)- Live WebSocket feed into the console### AI Copilotdiff --git a/apps/docs/docusaurus.config.ts b/apps/docs/docusaurus.config.tsindex 04b62a1ba..36fd088f5 100644--- a/apps/docs/docusaurus.config.ts+++ b/apps/docs/docusaurus.config.ts@@ -23,6 +23,24 @@ const config: Config = {organizationName: "beenuar",projectName: "AiSOC",+ headTags: [+ {+ tagName: "meta",+ attributes: {+ name: "keywords",+ content:+ "AiSOC, AI SOC, open source SOC, SIEM alternative, MITRE ATT&CK, Sigma, purple team, alert fusion, detection engineering, SOAR, security automation, tryaisoc, self-hosted SOC, threat hunting, incident response, cybersecurity, infosec, LangGraph, MCP server",+ },+ },+ {+ tagName: "meta",+ attributes: {+ property: "og:site_name",+ content: "AiSOC Docs",+ },+ },+ ],+onBrokenLinks: "throw",onBrokenMarkdownLinks: "warn",diff --git a/apps/web/.eslintrc.json b/apps/web/.eslintrc.jsonnew file mode 100644index 000000000..957cd1545--- /dev/null+++ b/apps/web/.eslintrc.json@@ -0,0 +1,3 @@+{+ "extends": ["next/core-web-vitals"]+}diff --git a/apps/web/next.config.js b/apps/web/next.config.jsindex 6248d89fa..9a4b2d3d1 100644--- a/apps/web/next.config.js+++ b/apps/web/next.config.js@@ -13,6 +13,10 @@const REALTIME_HOST = process.env.REALTIME_URL || 'http://localhost:8086';const API_HOST = process.env.API_URL || 'http://localhost:8000';const AGENTS_HOST = process.env.AGENTS_URL || 'http://localhost:8001';+// Fusion service exposes /entity-risk/*, /ml/*, /metrics, /health at root.+// We surface those to the browser under the same-origin namespace+// /api/v1/fusion/* so the bundle stays host-agnostic.+const FUSION_HOST = process.env.FUSION_URL || 'http://localhost:8082';const nextConfig = {reactStrictMode: true,@@ -98,6 +102,14 @@ const nextConfig = {source: '/api/v1/investigations',destination: `${AGENTS_HOST}/api/v1/investigations`,},+ // Fusion service exposes the Risk-Based Alerting (entity rollup) queue+ // and ML scoring endpoints at its own root (no /api/v1 prefix on the+ // service side). Proxy /api/v1/fusion/:path* → fusion's /:path* so the+ // browser only ever sees same-origin URLs.+ {+ source: '/api/v1/fusion/:path*',+ destination: `${FUSION_HOST}/:path*`,+ },// Catch-all for the core API.{source: '/api/v1/:path*',diff --git a/apps/web/public/manifest.json b/apps/web/public/manifest.jsonindex 5efdd91e9..c9ece1772 100644--- a/apps/web/public/manifest.json+++ b/apps/web/public/manifest.json@@ -1,7 +1,7 @@{"name": "AiSOC Responder","short_name": "AiSOC",- "description": "On-call responder PWA for the AiSOC Security Operations Center. Triage alerts, approve agent actions, and manage cases from your phone.",+ "description": "On-call responder PWA for AiSOC — open-source AI SOC. Triage fused alerts, approve agent actions, and manage cases from your phone. tryaisoc.com demo stack.","id": "/responder","start_url": "/responder","scope": "/",@@ -10,7 +10,7 @@"orientation": "portrait-primary","background_color": "#0a0d14","theme_color": "#0a0d14",- "categories": ["productivity", "security", "business"],+ "categories": ["productivity", "utilities", "business"],"lang": "en-US","dir": "ltr","prefer_related_applications": false,diff --git a/apps/web/src/app/(app)/detection/proposals/page.tsx b/apps/web/src/app/(app)/detection/proposals/page.tsxnew file mode 100644index 000000000..5d84e2d53--- /dev/null+++ b/apps/web/src/app/(app)/detection/proposals/page.tsx@@ -0,0 +1,7 @@+import { DetectionProposalsView } from '@/components/detections/DetectionProposalsView';++export const metadata = { title: 'Detection proposals — AiSOC' };++export default function DetectionProposalsPage() {+ return <DetectionProposalsView />;+}diff --git a/apps/web/src/app/(app)/purple-team/page.tsx b/apps/web/src/app/(app)/purple-team/page.tsxindex 6ea8be05d..9530d98aa 100644--- a/apps/web/src/app/(app)/purple-team/page.tsx+++ b/apps/web/src/app/(app)/purple-team/page.tsx@@ -46,6 +46,52 @@ interface CoverageMatrix {summary: CoverageSummary}+// --------------------------------------------------------------------------+// Detection drift (w1-drift) — delta-vs-last-week overlay on the heatmap.+// --------------------------------------------------------------------------+type DriftStatus = 'new' | 'removed' | 'improved' | 'regressed' | 'unchanged'++interface DriftTechnique {+ technique_id: string+ status: DriftStatus+ delta_coverage: number+ delta_detected: number+}++interface DriftSummary {+ current: Partial<CoverageSummary>+ previous: Partial<CoverageSummary>+ delta: {+ delta_total: number+ delta_tested: number+ delta_detected: number+ delta_coverage: number+ }+ regressed: number+ improved: number+ new: number+ removed: number+}++interface SnapshotMeta {+ id: string+ captured_at: string+ trigger: string+ total_techniques: number+ tested_techniques: number+ detected_techniques: number+ overall_coverage: number+}++interface DriftLatestResponse {+ current: SnapshotMeta | null+ previous: SnapshotMeta | null+ drift: {+ techniques: DriftTechnique[]+ summary: DriftSummary+ }+}+interface TabletopSession {id: stringname: string@@ -88,6 +134,28 @@ function coverageColor(c: number): string {return 'bg-gray-200'}+// Visual ring around a technique cell that reflects how it changed since the+// previous snapshot. Kept subtle so the underlying coverage color still reads.+function driftRing(status: DriftStatus | undefined): string {+ switch (status) {+ case 'improved':+ return 'ring-2 ring-emerald-500 ring-offset-1'+ case 'regressed':+ return 'ring-2 ring-red-500 ring-offset-1'+ case 'new':+ return 'ring-2 ring-blue-500 ring-offset-1'+ case 'removed':+ return 'ring-2 ring-amber-500 ring-offset-1 opacity-60'+ default:+ return ''+ }+}++function driftDeltaLabel(d: number, suffix = ''): string {+ if (d === 0) return '±0' + suffix+ return `${d > 0 ? '+' : ''}${d}${suffix}`+}+// --------------------------------------------------------------------------// Components// --------------------------------------------------------------------------@@ -99,28 +167,158 @@ function CoverageHeatmap() {{ refreshInterval: 30000 })+ // Drift snapshot — overlays delta-vs-last-week onto the heatmap and feeds+ // the summary banner. Refreshed less often than coverage since snapshots+ // are weekly by default.+ const { data: drift, mutate: mutateDrift } = useSWR<DriftLatestResponse>(+ `${API}/api/v1/purple-team/drift/latest?tenant_id=${TENANT_ID}`,+ fetcher,+ { refreshInterval: 60000 }+ )++ const [capturing, setCapturing] = useState(false)+ const [captureError, setCaptureError] = useState<string | null>(null)++ async function captureNow() {+ setCapturing(true)+ setCaptureError(null)+ try {+ const res = await fetch(+ `${API}/api/v1/purple-team/drift/snapshot?tenant_id=${TENANT_ID}&trigger=manual`,+ { method: 'POST' }+ )+ if (!res.ok) throw new Error(`HTTP ${res.status}`)+ await mutateDrift()+ } catch (e) {+ setCaptureError(e instanceof Error ? e.message : 'Snapshot failed')+ } finally {+ setCapturing(false)+ }+ }+if (isLoading) return <div className="text-sm text-gray-500 p-4">Loading coverage…</div>if (error || !data) return <div className="text-sm text-red-500 p-4">Failed to load coverage</div>const { summary, tactics, techniques } = data+ // Index drift status by technique_id for O(1) lookup while rendering cells.+ const driftByTid = new Map<string, DriftTechnique>()+ for (const t of drift?.drift.techniques ?? []) {+ driftByTid.set(t.technique_id, t)+ }+ const driftSummary = drift?.drift.summary+ const hasPrevious = Boolean(drift?.previous)+return (<div className="space-y-4">- {/* Summary cards */}+ {/* Summary cards — show absolute values + delta-vs-last-snapshot when available. */}<div className="grid grid-cols-4 gap-3">{[- { label: 'Total Techniques', value: summary.total_techniques },- { label: 'Tested', value: summary.tested_techniques },- { label: 'Detected', value: summary.detected_techniques },- { label: 'Coverage', value: `${(summary.overall_coverage * 100).toFixed(0)}%` },+ {+ label: 'Total Techniques',+ value: summary.total_techniques,+ delta: driftSummary?.delta.delta_total ?? 0,+ },+ {+ label: 'Tested',+ value: summary.tested_techniques,+ delta: driftSummary?.delta.delta_tested ?? 0,+ },+ {+ label: 'Detected',+ value: summary.detected_techniques,+ delta: driftSummary?.delta.delta_detected ?? 0,+ },+ {+ label: 'Coverage',+ value: `${(summary.overall_coverage * 100).toFixed(0)}%`,+ delta: driftSummary+ ? Math.round(driftSummary.delta.delta_coverage * 100)+ : 0,+ deltaSuffix: 'pp',+ },].map((s) => (<div key={s.label} className="bg-white rounded-lg border border-gray-200 p-3 text-center"><div className="text-xl font-bold text-gray-900">{s.value}</div><div className="text-xs text-gray-500 mt-1">{s.label}</div>+ {hasPrevious && (+ <div+ className={`text-[10px] font-medium mt-1 ${+ s.delta > 0+ ? 'text-emerald-600'+ : s.delta < 0+ ? 'text-red-600'+ : 'text-gray-400'+ }`}+ >+ {driftDeltaLabel(s.delta, s.deltaSuffix ?? '')} vs last snapshot+ </div>+ )}</div>))}</div>+ {/* Drift banner — controls + counts of regressions/improvements. */}+ <div className="bg-white rounded-lg border border-gray-200 p-3 flex flex-wrap items-center gap-4">+ <div className="flex-1 min-w-[200px]">+ <div className="text-xs font-semibold text-gray-700">Detection drift</div>+ <div className="text-xs text-gray-500 mt-0.5">+ {drift?.current+ ? `Last snapshot ${new Date(drift.current.captured_at).toLocaleString()} (${drift.current.trigger})`+ : 'No snapshots yet — capture one to start tracking drift week-over-week.'}+ </div>+ </div>+ {driftSummary && hasPrevious && (+ <div className="flex gap-2 text-xs">+ <span className="px-2 py-0.5 rounded bg-blue-100 text-blue-700">+ new {driftSummary.new}+ </span>+ <span className="px-2 py-0.5 rounded bg-emerald-100 text-emerald-700">+ improved {driftSummary.improved}+ </span>+ <span className="px-2 py-0.5 rounded bg-red-100 text-red-700">+ regressed {driftSummary.regressed}+ </span>+ <span className="px-2 py-0.5 rounded bg-amber-100 text-amber-700">+ removed {driftSummary.removed}+ </span>+ </div>+ )}+ <button+ onClick={captureNow}+ disabled={capturing}+ className="px-3 py-1.5 text-xs font-medium bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 disabled:opacity-50"+ >+ {capturing ? 'Capturing…' : 'Capture snapshot'}+ </button>+ {captureError && (+ <span className="text-xs text-red-600">{captureError}</span>+ )}+ </div>++ {/* Drift legend — explains the per-cell ring colors. */}+ {hasPrevious && (+ <div className="flex flex-wrap items-center gap-3 text-[11px] text-gray-600">+ <span className="font-medium">Delta-vs-last-snapshot:</span>+ <span className="inline-flex items-center gap-1">+ <span className="w-3 h-3 rounded ring-2 ring-emerald-500 ring-offset-1" />+ improved+ </span>+ <span className="inline-flex items-center gap-1">+ <span className="w-3 h-3 rounded ring-2 ring-red-500 ring-offset-1" />+ regressed+ </span>+ <span className="inline-flex items-center gap-1">+ <span className="w-3 h-3 rounded ring-2 ring-blue-500 ring-offset-1" />+ new+ </span>+ <span className="inline-flex items-center gap-1">+ <span className="w-3 h-3 rounded ring-2 ring-amber-500 ring-offset-1 opacity-60" />+ removed+ </span>+ </div>+ )}+{/* Heatmap grid */}<div className="bg-white rounded-lg border border-gray-200 overflow-x-auto"><table className="w-full text-xs">@@ -139,28 +337,61 @@ function CoverageHeatmap() {{(() => {const allTechniques = new Set<string>()tactics.forEach((t) => (techniques[t] ?? []).forEach((tc) => allTechniques.add(tc.technique_id)))- return Array.from(allTechniques).sort().map((tid) => (- <tr key={tid} className="border-t border-gray-100">- <td className="px-3 py-1.5 font-mono text-gray-700">{tid}</td>- {tactics.map((tactic) => {- const cell = (techniques[tactic] ?? []).find((tc) => tc.technique_id === tid)- return (- <td key={tactic} className="px-2 py-1.5 text-center">- {cell ? (- <div- className={`inline-flex items-center justify-center w-8 h-5 rounded text-white text-[10px] font-semibold ${coverageColor(cell.coverage)}`}- title={`${cell.test_count} tests, ${cell.pass_count} passed, ${cell.detected} detected`}- >- {(cell.coverage * 100).toFixed(0)}%- </div>- ) : (- <div className="inline-flex items-center justify-center w-8 h-5 rounded bg-gray-100 text-gray-400 text-[10px]">—</div>- )}- </td>- )- })}- </tr>- ))+ // Surface "removed" techniques in the table even when they're+ // gone from the live matrix, so analysts see what dropped off.+ for (const t of drift?.drift.techniques ?? []) {+ if (t.status === 'removed') allTechniques.add(t.technique_id)+ }+ return Array.from(allTechniques).sort().map((tid) => {+ const tDrift = driftByTid.get(tid)+ return (+ <tr key={tid} className="border-t border-gray-100">+ <td className="px-3 py-1.5 font-mono text-gray-700">+ {tid}+ {tDrift && hasPrevious && tDrift.status !== 'unchanged' && (+ <span+ className={`ml-2 text-[9px] uppercase font-semibold tracking-wide ${+ tDrift.status === 'improved'+ ? 'text-emerald-600'+ : tDrift.status === 'regressed'+ ? 'text-red-600'+ : tDrift.status === 'new'+ ? 'text-blue-600'+ : 'text-amber-600'+ }`}+ >+ {tDrift.status}+ </span>+ )}+ </td>+ {tactics.map((tactic) => {+ const cell = (techniques[tactic] ?? []).find((tc) => tc.technique_id === tid)+ const ring = hasPrevious ? driftRing(tDrift?.status) : ''+ const tooltipBase = cell+ ? `${cell.test_count} tests, ${cell.pass_count} passed, ${cell.detected} detected`+ : ''+ const tooltipDelta =+ tDrift && hasPrevious+ ? ` • ${tDrift.status} (Δdetected ${driftDeltaLabel(tDrift.delta_detected)}, Δcoverage ${driftDeltaLabel(Math.round(tDrift.delta_coverage * 100), 'pp')})`+ : ''+ return (+ <td key={tactic} className="px-2 py-1.5 text-center">+ {cell ? (+ <div+ className={`inline-flex items-center justify-center w-8 h-5 rounded text-white text-[10px] font-semibold ${coverageColor(cell.coverage)} ${ring}`}+ title={tooltipBase + tooltipDelta}+ >+ {(cell.coverage * 100).toFixed(0)}%+ </div>+ ) : (+ <div className="inline-flex items-center justify-center w-8 h-5 rounded bg-gray-100 text-gray-400 text-[10px]">—</div>+ )}+ </td>+ )+ })}+ </tr>+ )+ })})()}</tbody></table>diff --git a/apps/web/src/app/benchmark/page.tsx b/apps/web/src/app/benchmark/page.tsxindex f819ec0f6..00fd86995 100644--- a/apps/web/src/app/benchmark/page.tsx+++ b/apps/web/src/app/benchmark/page.tsx@@ -2,51 +2,94 @@ import type { Metadata } from 'next';import Link from 'next/link';import { LandingNav } from '@/components/landing/LandingNav';import { Footer } from '@/components/landing/Footer';-import { BenchmarkResults } from '@/components/benchmark/BenchmarkResults';+import {+ BenchmarkResults,+ fetchLatestEvalReport,+} from '@/components/benchmark/BenchmarkResults';import { ComparisonTable } from '@/components/benchmark/ComparisonTable';+import { KpiBar } from '@/components/benchmark/KpiBar';+import { CommunitySubmissions } from '@/components/benchmark/CommunitySubmissions';export const metadata: Metadata = {- title: 'Public eval harness — AiSOC',+ title: 'Public benchmark scoreboard — AiSOC',description:- 'A reproducible regression harness over the AiSOC substrate. Four CI gates over a 200-incident synthetic dataset (MITRE / completeness / response quality) plus a 1,000-alert noisy stream (alert reduction). One real measurement (alert reduction) and three substrate self-consistency checks. The page documents what each metric measures and what it does not.',+ 'A reproducible regression harness over the AiSOC substrate. Four CI gates over a 200-incident synthetic dataset (MITRE / completeness / response quality) plus a 1,000-alert noisy stream (alert reduction). Per-template macros, per-case means, alert-reduction %, the 2026 KPI bar, and a fixed-dataset community leaderboard. The page documents what each metric measures and what it does not.',alternates: { canonical: '/benchmark' },openGraph: {- title: 'AiSOC public eval harness',+ title: 'AiSOC public benchmark scoreboard',description:- 'A regression-gate harness over the AiSOC substrate. Open dataset, open harness, CI-enforced. The page is explicit that this is not an LLM-agent leaderboard.',+ 'Regression-gate harness over the AiSOC substrate plus a fixed-dataset community leaderboard. Open dataset, open harness, CI-enforced.',type: 'article',},};const REPRODUCE_SNIPPET = `git clone https://github.com/beenuar/AiSOC && cd AiSOC-python3 scripts/run_evals.py`;+python3 scripts/run_evals.py --json --out report.json`;-const EXPECTED_OUTPUT = `============================================================================+function fmtPct(value: number | undefined, digits = 1): string {+ if (typeof value !== 'number') return 'n/a';+ return `${(value * 100).toFixed(digits)}%`;+}++function fmtScore(value: number | undefined, digits = 3): string {+ if (typeof value !== 'number') return 'n/a';+ return value.toFixed(digits);+}++function generatedAtLabel(iso: string | undefined): string {+ if (!iso) return 'unknown';+ try {+ const d = new Date(iso);+ return `${d.toISOString().slice(0, 16).replace('T', ' ')} UTC`;+ } catch {+ return iso;+ }+}++export default async function BenchmarkPage() {+ const report = await fetchLatestEvalReport();+ const ar = report.suites.alert_reduction;+ const mt = report.suites.mitre_accuracy;+ const ic = report.suites.investigation_completeness;+ const rq = report.suites.response_quality;+ const expectedOutput = `============================================================================AiSOC Pillar-1 Eval - 200-incident synthetic benchmark============================================================================- [PASS] mitre_accuracy accuracy 0.970 (target >= 0.80)- [PASS] alert_reduction reduction_ratio 0.753 (target >= 0.70)- [PASS] investigation_completeness mean_keyword_coverage 0.943 (target >= 0.85)- [PASS] response_quality mean_rubric_score 1.000 (target >= 0.80)+ [${mt?.passed ? 'PASS' : 'FAIL'}] mitre_accuracy accuracy ${fmtScore(mt?.value)} (target >= ${fmtScore(mt?.target, 2)})+ [${ar?.passed ? 'PASS' : 'FAIL'}] alert_reduction reduction_ratio ${fmtScore(ar?.value)} (target >= ${fmtScore(ar?.target, 2)})+ [${ic?.passed ? 'PASS' : 'FAIL'}] investigation_completeness mean_keyword_coverage ${fmtScore(ic?.value)} (target >= ${fmtScore(ic?.target, 2)})+ [${rq?.passed ? 'PASS' : 'FAIL'}] response_quality mean_rubric_score ${fmtScore(rq?.value)} (target >= ${fmtScore(rq?.target, 2)})============================================================================- ALL GATES PASSED`;+ ${report.all_passed ? 'ALL GATES PASSED' : 'ONE OR MORE GATES FAILED'}`;-export default function BenchmarkPage() {return (<main className="relative min-h-screen overflow-x-hidden bg-surface-base text-white"><LandingNav /><section className="relative px-6 pt-32 pb-20"><div className="mx-auto max-w-4xl">- <div className="mb-3 flex items-center gap-2">+ <div className="mb-3 flex flex-wrap items-center gap-2"><span className="inline-flex items-center gap-1.5 rounded-full border border-emerald-500/20 bg-emerald-500/10 px-3 py-1 text-xs font-medium text-emerald-300"><span className="h-1.5 w-1.5 rounded-full bg-emerald-400" />Reproducible</span>- <span className="text-xs text-gray-500">Runs on every PR targeting main / develop</span>+ {report._stale ? (+ <span className="inline-flex items-center gap-1.5 rounded-full border border-amber-500/30 bg-amber-500/10 px-3 py-1 text-xs font-medium text-amber-200">+ <span className="h-1.5 w-1.5 rounded-full bg-amber-400" />+ Snapshot fallback+ </span>+ ) : (+ <span className="inline-flex items-center gap-1.5 rounded-full border border-brand-500/30 bg-brand-500/10 px-3 py-1 text-xs font-medium text-brand-300">+ <span className="h-1.5 w-1.5 rounded-full bg-brand-400" />+ Live from main+ </span>+ )}+ <span className="text-xs text-gray-500">+ Last run {generatedAtLabel(report.generated_at)} · refreshes every push+ </span></div><h1 className="text-4xl font-bold tracking-tight md:text-5xl">- Public eval harness+ Public benchmark scoreboard</h1><p className="mt-4 max-w-3xl text-lg text-gray-400">A deterministic regression harness over the AiSOC substrate —@@ -56,7 +99,10 @@ export default function BenchmarkPage() {DB-backed dedup and ML scoring), the report and responsetemplates, and the offline judges that grade them. The dataset,the harness, and the CI gate are in the repo. The numbers on this- page reproduce in roughly 25 ms on a laptop.+ page are pulled from{' '}+ <code className="text-gray-300">eval/results/latest.json</code> on+ the <code className="text-gray-300">eval-results</code> branch+ and refresh on every push to <code className="text-gray-300">main</code>.</p><div className="mt-5 max-w-3xl rounded-lg border border-amber-500/20 bg-amber-500/[0.04] p-4 text-sm text-amber-100/80">@@ -121,17 +167,26 @@ export default function BenchmarkPage() {</div></section>+ <section className="px-6 pb-20">+ <div className="mx-auto max-w-5xl">+ <KpiBar report={report} />+ </div>+ </section>+<section className="px-6 pb-20"><div className="mx-auto max-w-5xl"><h2 className="text-2xl font-semibold tracking-tight">Latest results</h2><p className="mt-2 max-w-3xl text-sm text-gray-400">Four metrics, four CI gates. A regression on any gate blocks the- build. The numbers below come from the most recent successful run- on <code className="text-gray-300">main</code>. Each card describes- what the metric measures and what it does not.+ build. Each card shows the per-case mean and, where applicable, the+ per-template macro — an equal-weight average across 55+ distinct incident templates that surfaces a single weak template+ the per-case mean would mask. Numbers come from{' '}+ <code className="text-gray-300">latest.json</code> on the most+ recent successful run on <code className="text-gray-300">main</code>.</p><div className="mt-8">- <BenchmarkResults />+ <BenchmarkResults report={report} /></div></div></section>@@ -145,7 +200,7 @@ export default function BenchmarkPage() {<div className="rounded-lg border border-emerald-500/20 bg-emerald-500/[0.03] p-5"><div className="flex flex-wrap items-center gap-2"><h3 className="text-base font-semibold text-white">- Alert reduction (75.3%)+ Alert reduction ({fmtPct(ar?.value)})</h3><span className="rounded-full border border-emerald-500/30 bg-emerald-500/10 px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wider text-emerald-200">Real measurement@@ -169,7 +224,7 @@ export default function BenchmarkPage() {<div className="rounded-lg border border-amber-500/20 bg-amber-500/[0.03] p-5"><div className="flex flex-wrap items-center gap-2"><h3 className="text-base font-semibold text-white">- MITRE tactic accuracy (97.0%)+ MITRE tactic accuracy ({fmtPct(mt?.value)})</h3><span className="rounded-full border border-amber-500/30 bg-amber-500/10 px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wider text-amber-200">Substrate self-consistency@@ -189,7 +244,7 @@ export default function BenchmarkPage() {<div className="rounded-lg border border-amber-500/20 bg-amber-500/[0.03] p-5"><div className="flex flex-wrap items-center gap-2"><h3 className="text-base font-semibold text-white">- Investigation completeness (94.3%)+ Investigation completeness ({fmtPct(ic?.value)})</h3><span className="rounded-full border border-amber-500/30 bg-amber-500/10 px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wider text-amber-200">Substrate self-consistency@@ -209,7 +264,7 @@ export default function BenchmarkPage() {<div className="rounded-lg border border-amber-500/20 bg-amber-500/[0.03] p-5"><div className="flex flex-wrap items-center gap-2"><h3 className="text-base font-semibold text-white">- Response-plan quality (1.000)+ Response-plan quality ({fmtScore(rq?.value)})</h3><span className="rounded-full border border-amber-500/30 bg-amber-500/10 px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wider text-amber-200">Substrate self-consistency@@ -258,7 +313,7 @@ export default function BenchmarkPage() {</pre><p className="mt-5 text-sm text-gray-400">Expected output:</p><pre className="mt-2 overflow-x-auto rounded-lg border border-white/5 bg-black/40 p-4 text-xs leading-relaxed text-gray-300">- <code>{EXPECTED_OUTPUT}</code>+ <code>{expectedOutput}</code></pre><p className="mt-5 text-sm text-gray-400">For machine-readable output, pass <code className="text-gray-300">--json</code>{' '}@@ -327,6 +382,12 @@ export default function BenchmarkPage() {</div></section>+ <section className="px-6 pb-20">+ <div className="mx-auto max-w-5xl">+ <CommunitySubmissions />+ </div>+ </section>+<section className="px-6 pb-24"><div className="mx-auto max-w-4xl rounded-2xl border border-brand-500/20 bg-surface-card p-8 text-center"><h2 className="text-2xl font-semibold tracking-tight">diff --git a/apps/web/src/app/layout.tsx b/apps/web/src/app/layout.tsxindex df427e39f..39f36ae61 100644--- a/apps/web/src/app/layout.tsx+++ b/apps/web/src/app/layout.tsx@@ -3,6 +3,7 @@ import { Inter, JetBrains_Mono } from 'next/font/google';import { Toaster } from 'react-hot-toast';import './globals.css';import { PwaBootstrap } from '@/components/pwa/PwaBootstrap';+import { DISCOVERY_KEYWORDS, getPublicSiteUrl } from '@/lib/site';const inter = Inter({subsets: ['latin'],@@ -16,40 +17,48 @@ const jetbrainsMono = JetBrains_Mono({display: 'swap',});+const siteUrl = getPublicSiteUrl();+export const metadata: Metadata = {+ metadataBase: new URL(siteUrl),+ applicationName: 'AiSOC',title: {- default: 'AiSOC — AI Security Operations Center',+ default: 'AiSOC — Open-Source AI Security Operations Center',template: '%s | AiSOC',},description:- 'Open-source AI-powered Security Operations Center. Real-time threat detection, autonomous investigation, MITRE ATT&CK-aware response — under MIT.',- keywords: [- 'AiSOC',- 'SOC',- 'SIEM',- 'security operations',- 'AI security',- 'threat detection',- 'MITRE ATT&CK',- 'open source',- 'SOAR',- 'XDR',- ],- authors: [{ name: 'AiSOC contributors', url: 'https://github.com/beenuar/AiSOC' }],- creator: 'AiSOC contributors',- metadataBase: new URL('https://aisoc.dev'),+ 'AiSOC is a free, self-hostable AI-powered Security Operations Center (SOC). Real-time threat detection, alert fusion, purple-team exercises, MITRE ATT&CK-aware autonomous investigation, and detection-as-code — MIT-licensed and community-driven.',+ keywords: [...DISCOVERY_KEYWORDS],+ authors: [{ name: 'AiSOC Community', url: 'https://github.com/beenuar/AiSOC' }],+ creator: 'AiSOC Community',+ publisher: 'AiSOC',+ category: 'cybersecurity',+ classification: 'Security Software',openGraph: {- title: 'AiSOC — AI Security Operations Center',+ title: 'AiSOC — Free, Open-Source AI Security Operations Center',description:- 'Open-source AI-powered SOC. Real-time threat detection, autonomous investigation, MITRE ATT&CK-aware response.',+ 'Self-hostable AI SOC with real-time threat detection, alert fusion, purple-team drills, MITRE ATT&CK investigation, and detection-as-code. MIT-licensed. Try the live demo at tryaisoc.com.',type: 'website',siteName: 'AiSOC',+ url: siteUrl,+ locale: 'en_US',+ images: [+ {+ url: '/og-image.svg',+ width: 1200,+ height: 630,+ alt: 'AiSOC — open-source AI SOC platform for security operations teams',+ type: 'image/svg+xml',+ },+ ],},twitter: {card: 'summary_large_image',- title: 'AiSOC — AI Security Operations Center',+ title: 'AiSOC — Free Open-Source AI SOC Platform',description:- 'Open-source AI-powered SOC. Real-time threat detection, autonomous investigation, MITRE ATT&CK-aware response.',+ 'AI-powered SOC: threat detection, alert fusion, purple team, MITRE ATT&CK mapping, detection-as-code, and eval harness in CI. Self-host for free — tryaisoc.com.',+ site: '@aisoc_dev',+ creator: '@aisoc_dev',},icons: {icon: [@@ -64,7 +73,8 @@ export const metadata: Metadata = {title: 'AiSOC',statusBarStyle: 'black-translucent',},- robots: { index: true, follow: true },+ robots: { index: true, follow: true, googleBot: { index: true, follow: true } },+ alternates: { canonical: siteUrl },};export const viewport: Viewport = {@@ -73,6 +83,72 @@ export const viewport: Viewport = {initialScale: 1,};+const jsonLd = {+ '@context': 'https://schema.org',+ '@graph': [+ {+ '@type': 'Organization',+ name: 'AiSOC',+ url: siteUrl,+ logo: `${siteUrl}/favicon.svg`,+ description:+ 'Community-driven, MIT-licensed AI security operations platform with a public demo and self-host path.',+ sameAs: [+ 'https://github.com/beenuar/AiSOC',+ 'https://tryaisoc.com',+ ],+ contactPoint: {+ '@type': 'ContactPoint',+ contactType: 'technical support',+ url: 'https://github.com/beenuar/AiSOC/issues',+ },+ },+ {+ '@type': 'SoftwareApplication',+ name: 'AiSOC',+ alternateName: ['AI SOC', 'AiSOC Platform', 'Open Source SOC'],+ applicationCategory: 'SecurityApplication',+ applicationSubCategory: 'Security Operations Center',+ operatingSystem: 'Linux, macOS, Docker',+ license: 'https://opensource.org/licenses/MIT',+ offers: {+ '@type': 'Offer',+ price: '0',+ priceCurrency: 'USD',+ description: 'Free, open-source, self-hostable',+ },+ url: siteUrl,+ downloadUrl: 'https://github.com/beenuar/AiSOC',+ installUrl: 'https://github.com/beenuar/AiSOC#quick-start',+ releaseNotes: 'https://github.com/beenuar/AiSOC/releases',+ featureList: [+ 'Real-time threat detection and alert fusion',+ 'AI-assisted alert triage and investigation',+ 'MITRE ATT&CK mapping and coverage analysis',+ 'Purple team simulation and detection validation',+ 'Detection-as-code with Sigma rule support',+ 'Connectors for Splunk, Sentinel, CrowdStrike, Elastic',+ 'SLA tracking and compliance reporting',+ 'Hunt-as-code threat hunting engine',+ 'MSSP multi-tenant support',+ 'Self-hosted deployment with Docker Compose',+ ],+ screenshot: `${siteUrl}/og-image.svg`,+ },+ {+ '@type': 'WebSite',+ name: 'AiSOC',+ url: siteUrl,+ description: 'Open-source AI-powered Security Operations Center — tryaisoc.com',+ potentialAction: {+ '@type': 'SearchAction',+ target: `${siteUrl}/search?q={search_term_string}`,+ 'query-input': 'required name=search_term_string',+ },+ },+ ],+};+export default function RootLayout({children,}: {@@ -81,6 +157,11 @@ export default function RootLayout({return (<html lang="en" className={`${inter.variable} ${jetbrainsMono.variable}`}><body className="bg-[#0a0d14] text-gray-100 antialiased">+ <script+ type="application/ld+json"+ // eslint-disable-next-line react/no-danger -- JSON-LD for SEO crawlers+ dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }}+ /><PwaBootstrap />{children}<Toasterdiff --git a/apps/web/src/app/page.tsx b/apps/web/src/app/page.tsxindex 7af4a0bdd..eb77fd1c0 100644--- a/apps/web/src/app/page.tsx+++ b/apps/web/src/app/page.tsx@@ -6,18 +6,29 @@ import { Architecture } from '@/components/landing/Architecture';import { MitreStrip } from '@/components/landing/MitreStrip';import { OpenSource } from '@/components/landing/OpenSource';import { Footer } from '@/components/landing/Footer';+import { DISCOVERY_KEYWORDS, getPublicSiteUrl } from '@/lib/site';export const metadata: Metadata = {- title: 'AiSOC — Open-source AI Security Operations Center',+ title: 'AiSOC — Free Open-Source AI Security Operations Center | Self-Hosted SOC',description:- 'Real-time detection, autonomous triage, and MITRE ATT&CK-aware investigation in one MIT-licensed platform. Self-hosted, extensible, free forever.',- alternates: { canonical: '/' },+ 'AiSOC is a free, MIT-licensed AI-powered SOC platform. Features: real-time threat detection, alert fusion, MITRE ATT&CK investigation, purple-team simulations, detection-as-code, and eval-gated agentic triage. Self-host or try the live demo at tryaisoc.com.',+ keywords: [...DISCOVERY_KEYWORDS],+ alternates: { canonical: getPublicSiteUrl() },openGraph: {- title: 'AiSOC — Open-source AI Security Operations Center',+ title: 'AiSOC — Free Open-Source AI Security Operations Center',description:- 'Real-time detection, autonomous triage, and MITRE ATT&CK-aware investigation. MIT licensed. Community-built.',- images: ['/og-image.svg'],+ 'Self-hostable AI SOC: threat detection, alert fusion, MITRE ATT&CK mapping, purple-team drills, and detection-as-code. MIT licensed, community-driven. Try tryaisoc.com.',+ url: getPublicSiteUrl(),+ images: [{ url: '/og-image.svg', width: 1200, height: 630, alt: 'AiSOC platform dashboard' }],type: 'website',+ siteName: 'AiSOC',+ },+ twitter: {+ card: 'summary_large_image',+ title: 'AiSOC — Free Open-Source AI SOC Platform',+ description:+ 'AI-powered SOC: threat detection, alert fusion, purple team, MITRE ATT&CK, detection-as-code. Self-host free — tryaisoc.com.',+ site: '@aisoc_dev',},};diff --git a/apps/web/src/app/robots.ts b/apps/web/src/app/robots.tsnew file mode 100644index 000000000..3ed78bf80--- /dev/null+++ b/apps/web/src/app/robots.ts@@ -0,0 +1,22 @@+import type { MetadataRoute } from "next";++import { getPublicSiteUrl } from "../lib/site";++export default function robots(): MetadataRoute.Robots {+ const base = getPublicSiteUrl();+ return {+ rules: [+ {+ userAgent: "*",+ allow: "/",+ disallow: ["/api/", "/_next/", "/dashboard/", "/cases/"],+ },+ {+ userAgent: "Googlebot",+ allow: "/",+ },+ ],+ sitemap: `${base}/sitemap.xml`,+ host: base,+ };+}diff --git a/apps/web/src/app/sitemap.ts b/apps/web/src/app/sitemap.tsnew file mode 100644index 000000000..e93a35dc3--- /dev/null+++ b/apps/web/src/app/sitemap.ts@@ -0,0 +1,33 @@+import type { MetadataRoute } from "next";++import { getPublicSiteUrl } from "../lib/site";++export default function sitemap(): MetadataRoute.Sitemap {+ const base = getPublicSiteUrl();+ const now = new Date();++ const highPriority = ["/", "/benchmark"];+ const mediumPriority = ["/purple-team", "/responder", "/why-open-source"];+ const lowPriority = ["/login", "/signup", "/detection", "/threat-intel"];++ return [+ ...highPriority.map((path) => ({+ url: `${base}${path}`,+ lastModified: now,+ changeFrequency: "weekly" as const,+ priority: path === "/" ? 1 : 0.9,+ })),+ ...mediumPriority.map((path) => ({+ url: `${base}${path}`,+ lastModified: now,+ changeFrequency: "monthly" as const,+ priority: 0.7,+ })),+ ...lowPriority.map((path) => ({+ url: `${base}${path}`,+ lastModified: now,+ changeFrequency: "monthly" as const,+ priority: 0.5,+ })),+ ];+}diff --git a/apps/web/src/components/alerts/AlertDetailView.tsx b/apps/web/src/components/alerts/AlertDetailView.tsxindex 628773806..47fe52eaa 100644--- a/apps/web/src/components/alerts/AlertDetailView.tsx+++ b/apps/web/src/components/alerts/AlertDetailView.tsx@@ -3,7 +3,15 @@import { useState } from 'react';import useSWR from 'swr';import Link from 'next/link';-import { alertsApi, agentsApi, type Alert, type AgentInvestigation } from '@/lib/api';+import {+ alertsApi,+ agentsApi,+ ledgerApi,+ type Alert,+ type AgentInvestigation,+ type ConfidenceFactor,+ type ConfidenceLabel,+} from '@/lib/api';import { format } from 'date-fns';import { clsx } from 'clsx';import { ContextualActions } from '@/components/copilot/ContextualActions';@@ -26,6 +34,27 @@ const STATUS_CONFIG = {false_positive: { label: 'False Positive', badge: 'bg-gray-500/10 text-gray-400 ring-gray-500/20' },} as const;+const CONFIDENCE_CONFIG: Record<ConfidenceLabel, { label: string; badge: string; dot: string; description: string }> = {+ high: {+ label: 'High Confidence',+ badge: 'bg-emerald-500/10 text-emerald-400 ring-emerald-500/20',+ dot: 'bg-emerald-500',+ description: 'Multiple corroborating signals; low risk of false positive.',+ },+ medium: {+ label: 'Medium Confidence',+ badge: 'bg-amber-500/10 text-amber-400 ring-amber-500/20',+ dot: 'bg-amber-500',+ description: 'Mixed signals; review supporting evidence before action.',+ },+ low: {+ label: 'Low Confidence',+ badge: 'bg-slate-500/10 text-slate-300 ring-slate-500/20',+ dot: 'bg-slate-400',+ description: 'Weak or partial signal; likely needs analyst validation.',+ },+};+// Mock alert for developmentconst MOCK_ALERT: Alert = {id: 'alert-1',@@ -51,6 +80,53 @@ const MOCK_ALERT: Alert = {assignee: '[email protected]',createdAt: new Date(Date.now() - 3600000).toISOString(),updatedAt: new Date(Date.now() - 1800000).toISOString(),+ confidenceLabel: 'high',+ confidenceScore: 0.86,+ confidenceRationale: [+ {+ factor: 'severity',+ label: 'Critical severity from source',+ value: 1.0,+ contribution: 0.20,+ weight: 0.20,+ },+ {+ factor: 'mitre_coverage',+ label: '3 MITRE techniques mapped (T1059.001, T1027, T1071)',+ value: 1.0,+ contribution: 0.18,+ weight: 0.18,+ },+ {+ factor: 'threat_intel',+ label: 'IOC matched against known C2 infrastructure',+ value: 1.0,+ contribution: 0.20,+ weight: 0.20,+ },+ {+ factor: 'ml_score',+ label: 'Anomaly score 0.94 (UEBA baseline deviation)',+ value: 0.94,+ contribution: 0.14,+ weight: 0.15,+ },+ {+ factor: 'upstream_risk',+ label: 'Affected user is in elevated-risk cohort',+ value: 0.78,+ contribution: 0.08,+ weight: 0.10,+ },+ {+ factor: 'ioc_density',+ label: '3 distinct malicious IOCs in single event',+ value: 0.85,+ contribution: 0.06,+ weight: 0.07,+ },+ ],+ ledgerRunId: 'run-mock-c2-beacon-investigation',};// ─── Sections ─────────────────────────────────────────────────────────────────@@ -93,6 +169,171 @@ function IOCBadge({ type, value, malicious }: { type: string; value: string; mal);}+// ─── Detection Confidence ─────────────────────────────────────────────────────++function ConfidenceChip({ label, score }: { label: ConfidenceLabel; score?: number }) {+ const cfg = CONFIDENCE_CONFIG[label];+ const pct = typeof score === 'number' ? Math.round(score * 100) : null;+ return (+ <span+ className={clsx(+ 'inline-flex items-center gap-1.5 px-2.5 py-1 text-xs font-medium rounded ring-1 ring-inset',+ cfg.badge,+ )}+ title={cfg.description}+ >+ <span className={clsx('w-2 h-2 rounded-full', cfg.dot)} />+ {cfg.label}+ {pct !== null && <span className="opacity-70 font-mono">· {pct}%</span>}+ </span>+ );+}++function ConfidenceFactorBar({ factor }: { factor: ConfidenceFactor }) {+ const pct = Math.max(0, Math.min(1, factor.contribution / Math.max(factor.weight, 0.001)));+ const widthPct = Math.round(pct * 100);+ return (+ <div>+ <div className="flex items-baseline justify-between gap-3 mb-1">+ <span className="text-sm text-gray-200">{factor.label}</span>+ <span className="text-xs font-mono text-gray-500 shrink-0">+ +{factor.contribution.toFixed(2)} / {factor.weight.toFixed(2)}+ </span>+ </div>+ <div className="h-1.5 bg-gray-800 rounded overflow-hidden">+ <div+ className="h-full bg-emerald-500/70"+ style={{ width: `${widthPct}%` }}+ aria-hidden="true"+ />+ </div>+ <div className="text-[10px] text-gray-600 uppercase tracking-wider mt-1 font-mono">+ {factor.factor}+ </div>+ </div>+ );+}++function ConfidenceExplainability({+ label,+ score,+ rationale,+ ledgerRunId,+}: {+ label: ConfidenceLabel;+ score?: number;+ rationale: ConfidenceFactor[];+ ledgerRunId?: string;+}) {+ const cfg = CONFIDENCE_CONFIG[label];+ const sortedRationale = [...rationale].sort((a, b) => b.contribution - a.contribution);++ return (+ <Section title="Detection Confidence">+ <div className="space-y-4">+ <div className="flex items-start gap-3">+ <span className={clsx('w-2.5 h-2.5 rounded-full mt-1.5 shrink-0', cfg.dot)} />+ <div className="flex-1">+ <div className="flex items-baseline gap-3">+ <span className="text-sm font-semibold text-gray-100">{cfg.label}</span>+ {typeof score === 'number' && (+ <span className="text-xs font-mono text-gray-500">+ score {score.toFixed(2)} ({Math.round(score * 100)}%)+ </span>+ )}+ </div>+ <p className="text-xs text-gray-500 mt-0.5">{cfg.description}</p>+ </div>+ </div>++ {sortedRationale.length > 0 && (+ <div className="space-y-3 pt-2 border-t border-gray-800/60">+ <p className="text-xs font-medium text-gray-400">+ Why this score+ </p>+ <div className="space-y-3">+ {sortedRationale.map((factor) => (+ <ConfidenceFactorBar key={factor.factor} factor={factor} />+ ))}+ </div>+ </div>+ )}++ {ledgerRunId && (+ <div className="pt-3 border-t border-gray-800/60">+ <LedgerEvidenceChain runId={ledgerRunId} />+ </div>+ )}+ </div>+ </Section>+ );+}++function LedgerEvidenceChain({ runId }: { runId: string }) {+ const { data, error, isLoading } = useSWR(+ ['ledger-events', runId],+ () => ledgerApi.listEvents(runId, { limit: 8 }),+ );++ return (+ <div className="space-y-3">+ <div className="flex items-center justify-between">+ <p className="text-xs font-medium text-gray-400">Investigation Ledger evidence chain</p>+ <Link+ href={`/investigations/${runId}`}+ className="text-xs text-blue-400 hover:text-blue-300"+ >+ Open full ledger →+ </Link>+ </div>++ {isLoading && (+ <p className="text-xs text-gray-600">Loading evidence chain…</p>+ )}++ {error && !data && (+ <p className="text-xs text-gray-500">+ Evidence chain not yet available for this alert.+ </p>+ )}++ {data && data.items.length === 0 && (+ <p className="text-xs text-gray-500">+ No ledger events recorded yet — start an investigation to populate the chain.+ </p>+ )}++ {data && data.items.length > 0 && (+ <ol className="space-y-2">+ {data.items.map((event) => (+ <li key={event.id} className="flex gap-3">+ <div className="flex flex-col items-center shrink-0 pt-1">+ <span className="w-1.5 h-1.5 bg-blue-500 rounded-full" />+ </div>+ <div className="flex-1 min-w-0">+ <div className="flex items-baseline gap-2">+ <span className="text-[10px] font-mono text-gray-600 shrink-0">+ #{event.seq}+ </span>+ <span className="text-xs font-mono text-blue-400 shrink-0">+ {event.kind}+ </span>+ <span className="text-xs text-gray-200 truncate">+ {event.summary}+ </span>+ </div>+ <div className="text-[10px] text-gray-600 mt-0.5">+ {event.agent} · {format(new Date(event.ts), 'HH:mm:ss')}+ </div>+ </div>+ </li>+ ))}+ </ol>+ )}+ </div>+ );+}+// ─── AI Investigation Panel ───────────────────────────────────────────────────function AIInvestigation({ alertId }: { alertId: string }) {@@ -285,7 +526,7 @@ export function AlertDetailView({ alertId }: { alertId: string }) {{/* Header */}<div className="flex items-start justify-between gap-4"><div>- <div className="flex items-center gap-3 mb-1">+ <div className="flex items-center gap-3 mb-1 flex-wrap"><span className={clsx('inline-flex items-center gap-1.5 px-2.5 py-1 text-xs font-medium rounded ring-1 ring-inset', sevCfg.badge)}><span className={clsx('w-2 h-2 rounded-full', sevCfg.dot)} />{sevCfg.label}@@ -293,6 +534,12 @@ export function AlertDetailView({ alertId }: { alertId: string }) {<span className={clsx('inline-flex px-2.5 py-1 text-xs font-medium rounded ring-1 ring-inset', stsCfg.badge)}>{stsCfg.label}</span>+ {alert.confidenceLabel && (+ <ConfidenceChip+ label={alert.confidenceLabel}+ score={alert.confidenceScore}+ />+ )}<span className="text-xs text-gray-500">Risk Score: <span className="text-white font-bold">{alert.riskScore}</span></span></div><h1 className="text-lg font-semibold text-gray-100">{alert.title}</h1>@@ -366,6 +613,15 @@ export function AlertDetailView({ alertId }: { alertId: string }) {<p className="text-sm text-gray-300 leading-relaxed">{alert.description}</p></Section>+ {alert.confidenceLabel && (+ <ConfidenceExplainability+ label={alert.confidenceLabel}+ score={alert.confidenceScore}+ rationale={alert.confidenceRationale ?? []}+ ledgerRunId={alert.ledgerRunId}+ />+ )}+<Section title="Details"><div className="space-y-3"><Field label="Source" value={alert.source} />diff --git a/apps/web/src/components/alerts/AlertsView.tsx b/apps/web/src/components/alerts/AlertsView.tsxindex 6667cb031..f7ddb36fe 100644--- a/apps/web/src/components/alerts/AlertsView.tsx+++ b/apps/web/src/components/alerts/AlertsView.tsx@@ -3,9 +3,17 @@import { useState, useCallback } from 'react';import useSWR from 'swr';import Link from 'next/link';-import { alertsApi, type Alert, type AlertFilters } from '@/lib/api';+import { alertsApi, type Alert, type AlertFilters, type ConfidenceLabel } from '@/lib/api';import { clsx } from 'clsx';import { format, formatDistanceToNow } from 'date-fns';+import { EntityRiskQueue } from './EntityRiskQueue';++// Wave 1 of the AiSOC v6 capability roadmap. The "entities" tab renders the+// rolled-up Risk-Based Alerting queue — alerts contribute time-decayed risk+// points to the entities they touch, and the queue surfaces those entities+// (not the raw alerts) to the analyst. The "alerts" tab keeps the legacy+// alert-centric grid for tenants that prefer it or have RBA disabled.+type ViewMode = 'entities' | 'alerts';// ─── Config ───────────────────────────────────────────────────────────────────@@ -31,6 +39,8 @@ const MOCK_ALERTS: Alert[] = Array.from({ length: 25 }, (_, i): Alert => {const sev = (['critical', 'high', 'high', 'medium', 'medium', 'medium', 'low', 'info'] as const)[i % 8];const src = ['CrowdStrike', 'Splunk', 'AWS Security Hub', 'Okta', 'Microsoft Sentinel'][i % 5];const status = (['new', 'investigating', 'new', 'resolved', 'false_positive'] as const)[i % 5];+ const conf = (['high', 'high', 'medium', 'medium', 'medium', 'low'] as const)[i % 6];+ const confScore = conf === 'high' ? 0.78 + (i % 5) * 0.03 : conf === 'medium' ? 0.45 + (i % 5) * 0.03 : 0.18 + (i % 5) * 0.03;return {id: `ALT-${String(1000 + i).padStart(4, '0')}`,title: [@@ -57,9 +67,32 @@ const MOCK_ALERTS: Alert[] = Array.from({ length: 25 }, (_, i): Alert => {iocs: [],mitreAttack: i % 3 === 0 ? [{ tactic: 'Execution', technique: 'PowerShell', techniqueId: 'T1059.001' }] : [],riskScore: Math.floor(Math.random() * 100),+ confidenceLabel: conf,+ confidenceScore: Number(confScore.toFixed(2)),};});+// Wave 1 — Detection confidence chip rendered inline in the alert grid so an+// analyst can spot low-confidence alerts at a glance without clicking through.+// Click-through still goes to AlertDetailView for the full evidence chain.+const CONFIDENCE_ROW_CONFIG: Record<ConfidenceLabel, { label: string; cls: string }> = {+ high: { label: 'HIGH', cls: 'text-emerald-400 bg-emerald-500/10 border-emerald-500/20' },+ medium: { label: 'MED', cls: 'text-yellow-400 bg-yellow-500/10 border-yellow-500/20' },+ low: { label: 'LOW', cls: 'text-gray-400 bg-gray-500/10 border-gray-500/20' },+};++function ConfidencePill({ label }: { label: ConfidenceLabel }) {+ const cfg = CONFIDENCE_ROW_CONFIG[label];+ return (+ <span+ className={clsx('text-[10px] font-mono font-medium px-1.5 py-0.5 rounded border shrink-0', cfg.cls)}+ title={`Detection confidence: ${cfg.label}`}+ >+ {cfg.label}+ </span>+ );+}+// ─── Sub-components ───────────────────────────────────────────────────────────function SeverityDot({ severity }: { severity: string }) {@@ -167,6 +200,7 @@ function AlertRow({ alert }: { alert: Alert }) {</div><div className="flex items-center gap-2 shrink-0">+ {alert.confidenceLabel && <ConfidencePill label={alert.confidenceLabel} />}<SeverityBadge severity={alert.severity} /><StatusBadge status={alert.status} /><span className="text-xs text-gray-600 w-24 text-right">@@ -182,6 +216,10 @@ function AlertRow({ alert }: { alert: Alert }) {export function AlertsView() {const [filters, setFilters] = useState<AlertFilters>({ page: 1, pageSize: 25 });const [selectedIds] = useState(new Set<string>());+ // Default to the entity-centric queue — that's the whole point of Wave 1's+ // RBA work. Analysts can flip back to the raw alert grid for legacy+ // workflows or when triaging a specific alert ID.+ const [viewMode, setViewMode] = useState<ViewMode>('entities');const { data, error, isLoading } = useSWR(['alerts', filters],@@ -214,13 +252,97 @@ export function AlertsView() {<div className="flex items-center justify-between"><div><h1 className="text-xl font-semibold text-gray-100">Alerts</h1>- <p className="text-sm text-gray-500 mt-0.5">Real-time security event monitoring and triage</p>+ <p className="text-sm text-gray-500 mt-0.5">+ {viewMode === 'entities'+ ? 'Risk-Based Alerting · entity-centric triage queue'+ : 'Real-time security event monitoring and triage'}+ </p>+ </div>+ <div className="flex items-center gap-2">+ <div+ role="tablist"+ aria-label="View mode"+ className="inline-flex items-center bg-gray-900/60 border border-gray-800/60 rounded-lg p-0.5"+ >+ <button+ type="button"+ role="tab"+ aria-selected={viewMode === 'entities'}+ onClick={() => setViewMode('entities')}+ className={clsx(+ 'text-xs px-3 py-1.5 rounded-md transition-colors',+ viewMode === 'entities'+ ? 'bg-blue-600 text-white'+ : 'text-gray-400 hover:text-gray-200',+ )}+ >+ Entities+ </button>+ <button+ type="button"+ role="tab"+ aria-selected={viewMode === 'alerts'}+ onClick={() => setViewMode('alerts')}+ className={clsx(+ 'text-xs px-3 py-1.5 rounded-md transition-colors',+ viewMode === 'alerts'+ ? 'bg-gray-700 text-gray-100'+ : 'text-gray-400 hover:text-gray-200',+ )}+ >+ Alerts+ </button>+ </div>+ <button className="bg-blue-600 hover:bg-blue-500 text-white text-sm px-4 py-2 rounded-lg transition-colors">+ + Create Alert+ </button></div>- <button className="bg-blue-600 hover:bg-blue-500 text-white text-sm px-4 py-2 rounded-lg transition-colors">- + Create Alert- </button></div>+ {viewMode === 'entities' ? (+ <EntityRiskQueue />+ ) : (+ <AlertsTable+ alerts={alerts}+ total={total}+ critCount={critCount}+ highCount={highCount}+ newCount={newCount}+ filters={filters}+ isLoading={isLoading}+ error={error}+ onFilterChange={handleFilterChange}+ />+ )}+ </div>+ );+}++// ─── Legacy alert-centric grid (extracted for the view-mode toggle) ──────────++function AlertsTable({+ alerts,+ total,+ critCount,+ highCount,+ newCount,+ filters,+ isLoading,+ error,+ onFilterChange,+}: {+ alerts: Alert[];+ total: number;+ critCount: number;+ highCount: number;+ newCount: number;+ filters: AlertFilters;+ isLoading: boolean;+ error: unknown;+ onFilterChange: (f: AlertFilters) => void;+}) {+ return (+ <div className="space-y-4">{/* Stats strip */}<div className="grid grid-cols-4 gap-3">{[@@ -236,7 +358,7 @@ export function AlertsView() {))}</div>- <FiltersBar filters={filters} onChange={handleFilterChange} total={total} />+ <FiltersBar filters={filters} onChange={onFilterChange} total={total} />{/* Table */}<div className="bg-gray-900/60 border border-gray-800/60 rounded-xl overflow-hidden">@@ -273,7 +395,7 @@ export function AlertsView() {<span>Showing {alerts.length} of {total} alerts</span><div className="flex items-center gap-1"><button- onClick={() => handleFilterChange({ ...filters, page: Math.max(1, (filters.page || 1) - 1) })}+ onClick={() => onFilterChange({ ...filters, page: Math.max(1, (filters.page || 1) - 1) })}disabled={(filters.page || 1) <= 1}className="px-2 py-1 rounded bg-gray-800 hover:bg-gray-700 disabled:opacity-40 disabled:cursor-not-allowed">@@ -281,7 +403,7 @@ export function AlertsView() {</button><span className="px-2">Page {filters.page || 1}</span><button- onClick={() => handleFilterChange({ ...filters, page: (filters.page || 1) + 1 })}+ onClick={() => onFilterChange({ ...filters, page: (filters.page || 1) + 1 })}disabled={alerts.length < (filters.pageSize || 25)}className="px-2 py-1 rounded bg-gray-800 hover:bg-gray-700 disabled:opacity-40 disabled:cursor-not-allowed">diff --git a/apps/web/src/components/alerts/EntityRiskQueue.tsx b/apps/web/src/components/alerts/EntityRiskQueue.tsxnew file mode 100644index 000000000..70fd0227c--- /dev/null+++ b/apps/web/src/components/alerts/EntityRiskQueue.tsx@@ -0,0 +1,547 @@+'use client';++/**+ * Entity-centric Risk-Based Alerting (RBA) queue.+ *+ * Wave 1 of the AiSOC v6 capability roadmap. Renders the rolled-up entity+ * queue produced by the fusion service's EntityRiskEngine. Each row is a+ * *user / host / ip / domain* with a time-decayed score, contributing alerts,+ * and a severity histogram — not a raw alert. Goal: surface ≤ 1 entity per+ * promotion-worthy cluster of alerts so the analyst opens "the user+ * fox.beach" rather than 47 separate alert rows.+ */++import { useState } from 'react';+import useSWR from 'swr';+import { clsx } from 'clsx';+import { formatDistanceToNow } from 'date-fns';+import {+ entityRiskApi,+ type EntityRiskRecord,+ type EntityRiskStats,+ type EntityType,+} from '@/lib/api';++// ─── Visual config ───────────────────────────────────────────────────────────++const ENTITY_TYPE_CONFIG: Record<+ EntityType,+ { label: string; icon: string; tint: string }+> = {+ user: { label: 'User', icon: '👤', tint: 'text-purple-300' },+ host: { label: 'Host', icon: '🖥️', tint: 'text-cyan-300' },+ ip: { label: 'IP', icon: '🌐', tint: 'text-blue-300' },+ domain: { label: 'Domain', icon: '🔗', tint: 'text-emerald-300' },+};++const SEVERITY_DOT: Record<string, string> = {+ critical: 'bg-red-500',+ high: 'bg-orange-500',+ medium: 'bg-yellow-500',+ low: 'bg-blue-500',+ info: 'bg-gray-500',+};++// ─── Helpers ─────────────────────────────────────────────────────────────────++function bandFor(score: number, threshold: number): {+ label: string;+ text: string;+ bg: string;+ bar: string;+} {+ // Bands are anchored on the configured promotion threshold so the queue+ // visually reflects the operator's tuning, not magic numbers.+ if (score >= threshold) {+ return {+ label: 'Critical',+ text: 'text-red-300',+ bg: 'bg-red-500/10 border-red-500/30',+ bar: 'bg-red-500',+ };+ }+ if (score >= threshold * 0.66) {+ return {+ label: 'High',+ text: 'text-orange-300',+ bg: 'bg-orange-500/10 border-orange-500/30',+ bar: 'bg-orange-500',+ };+ }+ if (score >= threshold * 0.33) {+ return {+ label: 'Medium',+ text: 'text-yellow-300',+ bg: 'bg-yellow-500/10 border-yellow-500/30',+ bar: 'bg-yellow-500',+ };+ }+ return {+ label: 'Low',+ text: 'text-blue-300',+ bg: 'bg-blue-500/10 border-blue-500/30',+ bar: 'bg-blue-500',+ };+}++// ─── Sub-components ──────────────────────────────────────────────────────────++function RatioStat({+ alertCount,+ incidentCount,+}: {+ alertCount: number;+ incidentCount: number;+}) {+ // Alert-to-incident ratio is the published 2026 KPI bar (≥ 50:1). We always+ // surface it here because it's the single number that measures whether RBA+ // is actually delivering — collapsing N alerts into 1 entity-incident.+ const ratio =+ incidentCount > 0+ ? alertCount / incidentCount+ : alertCount > 0+ ? Number.POSITIVE_INFINITY+ : 0;+ const meets = ratio >= 50;+ const display = !Number.isFinite(ratio)+ ? `${alertCount}:0`+ : ratio === 0+ ? '0:0'+ : `${ratio.toFixed(1)}:1`;+ return (+ <div className="bg-gray-900/60 border border-gray-800/60 rounded-xl px-4 py-3">+ <p className="text-xs text-gray-500">Alert → Incident</p>+ <p+ className={clsx(+ 'text-2xl font-bold mt-1',+ meets ? 'text-green-400' : 'text-yellow-400',+ )}+ >+ {display}+ </p>+ <p className="text-[10px] text-gray-600 mt-0.5">+ 2026 bar ≥ 50:1 {meets ? '✓' : '↑'}+ </p>+ </div>+ );+}++function SeverityHistogram({+ histogram,+}: {+ histogram: Record<string, number>;+}) {+ const order: Array<keyof typeof SEVERITY_DOT> = [+ 'critical',+ 'high',+ 'medium',+ 'low',+ 'info',+ ];+ return (+ <div className="flex items-center gap-2">+ {order.map((sev) => {+ const count = histogram[sev] ?? 0;+ if (count === 0) return null;+ return (+ <span+ key={sev}+ className="flex items-center gap-1 text-[11px] text-gray-400"+ title={`${count} ${sev}`}+ >+ <span+ className={clsx('w-1.5 h-1.5 rounded-full', SEVERITY_DOT[sev])}+ />+ {count}+ </span>+ );+ })}+ </div>+ );+}++function ScoreBar({+ score,+ threshold,+}: {+ score: number;+ threshold: number;+}) {+ const band = bandFor(score, threshold);+ // Cap the rendered fill at 1.5× threshold so very-high entities don't visually+ // saturate at the same width as merely-high ones.+ const max = threshold * 1.5;+ const pct = Math.min(100, (score / max) * 100);+ return (+ <div className="flex items-center gap-2 w-32 shrink-0">+ <div className="flex-1 h-1.5 bg-gray-800 rounded-full overflow-hidden">+ <div+ className={clsx('h-full rounded-full', band.bar)}+ style={{ width: `${pct}%` }}+ />+ </div>+ <span className={clsx('text-xs font-mono shrink-0', band.text)}>+ {Math.round(score)}+ </span>+ </div>+ );+}++function EntityRow({+ record,+ onSelect,+}: {+ record: EntityRiskRecord;+ onSelect: () => void;+}) {+ const cfg = ENTITY_TYPE_CONFIG[record.entity_type] ?? ENTITY_TYPE_CONFIG.user;+ const band = bandFor(record.score, record.threshold);+ return (+ <button+ type="button"+ onClick={onSelect}+ className="w-full flex items-center gap-4 px-4 py-3 hover:bg-gray-800/20 transition-colors border-b border-gray-800/40 last:border-0 text-left"+ >+ <span className="text-base shrink-0" aria-hidden>+ {cfg.icon}+ </span>++ <div className="flex-1 min-w-0">+ <div className="flex items-center gap-2">+ <span className={clsx('text-xs uppercase tracking-wider', cfg.tint)}>+ {cfg.label}+ </span>+ <span className="text-sm text-gray-200 truncate font-medium">+ {record.entity_value}+ </span>+ {record.promoted && (+ <span className="text-[10px] uppercase tracking-wider px-1.5 py-0.5 rounded bg-red-500/15 text-red-300 border border-red-500/30 shrink-0">+ Promoted+ </span>+ )}+ </div>+ <div className="flex items-center gap-3 mt-1">+ <span className="text-xs text-gray-500">+ {record.alert_count} alert{record.alert_count === 1 ? '' : 's'}+ </span>+ <span className="text-gray-700">·</span>+ <SeverityHistogram histogram={record.severity_histogram} />+ <span className="text-gray-700">·</span>+ <span className="text-xs text-gray-500">+ last seen{' '}+ {formatDistanceToNow(new Date(record.last_seen), {+ addSuffix: true,+ })}+ </span>+ </div>+ </div>++ <ScoreBar score={record.score} threshold={record.threshold} />++ <span+ className={clsx(+ 'text-[10px] uppercase tracking-wider px-2 py-0.5 rounded border shrink-0 w-20 text-center',+ band.text,+ band.bg,+ )}+ >+ {band.label}+ </span>+ </button>+ );+}++function EntityDetailDrawer({+ entity,+ onClose,+}: {+ entity: EntityRiskRecord;+ onClose: () => void;+}) {+ const cfg = ENTITY_TYPE_CONFIG[entity.entity_type] ?? ENTITY_TYPE_CONFIG.user;+ // Pull a fresh detail record so contributions are up-to-date when the drawer+ // opens — falls back to the row data on error.+ const { data } = useSWR(+ ['entity-risk-detail', entity.entity_type, entity.entity_value],+ () => entityRiskApi.get(entity.entity_type, entity.entity_value),+ { fallbackData: entity, refreshInterval: 30000 },+ );+ const record = data ?? entity;+ const band = bandFor(record.score, record.threshold);++ return (+ <div className="fixed inset-0 z-50 flex">+ <div+ className="flex-1 bg-black/60"+ onClick={onClose}+ aria-hidden="true"+ />+ <aside className="w-[480px] max-w-[90vw] bg-gray-950 border-l border-gray-800 overflow-y-auto">+ <header className="px-5 py-4 border-b border-gray-800 flex items-start justify-between gap-3 sticky top-0 bg-gray-950 z-10">+ <div className="min-w-0">+ <div className="flex items-center gap-2">+ <span className="text-base" aria-hidden>+ {cfg.icon}+ </span>+ <span+ className={clsx(+ 'text-xs uppercase tracking-wider',+ cfg.tint,+ )}+ >+ {cfg.label}+ </span>+ </div>+ <h2 className="text-lg text-gray-100 font-medium truncate mt-1">+ {record.entity_value}+ </h2>+ </div>+ <button+ onClick={onClose}+ className="text-gray-500 hover:text-gray-300 text-xl leading-none px-2"+ aria-label="Close"+ >+ ×+ </button>+ </header>++ <div className="px-5 py-4 space-y-4">+ <div className="grid grid-cols-2 gap-3">+ <div className={clsx('rounded-xl px-3 py-2.5 border', band.bg)}>+ <p className="text-[10px] uppercase tracking-wider text-gray-500">+ Risk score+ </p>+ <p className={clsx('text-2xl font-bold', band.text)}>+ {Math.round(record.score)}+ </p>+ <p className="text-[10px] text-gray-500 mt-0.5">+ threshold {Math.round(record.threshold)}+ </p>+ </div>+ <div className="rounded-xl px-3 py-2.5 border border-gray-800/60 bg-gray-900/60">+ <p className="text-[10px] uppercase tracking-wider text-gray-500">+ Alerts (window)+ </p>+ <p className="text-2xl font-bold text-gray-200">+ {record.alert_count}+ </p>+ <p className="text-[10px] text-gray-500 mt-0.5">+ first seen{' '}+ {formatDistanceToNow(new Date(record.first_seen), {+ addSuffix: true,+ })}+ </p>+ </div>+ </div>++ {record.promoted && record.promoted_incident_id && (+ <div className="rounded-xl px-3 py-2.5 border border-red-500/30 bg-red-500/10">+ <p className="text-[10px] uppercase tracking-wider text-red-300">+ Promoted to incident+ </p>+ <p className="text-sm font-mono text-red-200 mt-1 break-all">+ {record.promoted_incident_id}+ </p>+ </div>+ )}++ <div>+ <h3 className="text-xs uppercase tracking-wider text-gray-500 mb-2">+ Contributing alerts+ </h3>+ {record.contributions.length === 0 ? (+ <p className="text-sm text-gray-600">+ No contributions in the current decay window.+ </p>+ ) : (+ <ol className="space-y-1.5">+ {record.contributions.map((c) => (+ <li+ key={c.alert_id}+ className="flex items-start gap-2 text-sm border border-gray-800/60 bg-gray-900/40 rounded-lg px-3 py-2"+ >+ <span+ className={clsx(+ 'w-1.5 h-1.5 rounded-full mt-1.5 shrink-0',+ SEVERITY_DOT[c.severity] ?? SEVERITY_DOT.info,+ )}+ />+ <div className="flex-1 min-w-0">+ <div className="flex items-center gap-2">+ <span className="text-gray-200 truncate">+ {c.title ?? c.alert_id}+ </span>+ <span className="text-[10px] text-gray-500 shrink-0">+ +{Math.round(c.raw_points)}+ </span>+ </div>+ <div className="flex items-center gap-2 mt-0.5 text-[11px] text-gray-500">+ {c.source && <span>{c.source}</span>}+ {c.source && <span className="text-gray-700">·</span>}+ <span>+ {formatDistanceToNow(new Date(c.observed_at), {+ addSuffix: true,+ })}+ </span>+ </div>+ </div>+ </li>+ ))}+ </ol>+ )}+ </div>+ </div>+ </aside>+ </div>+ );+}++// ─── Main view ───────────────────────────────────────────────────────────────++export function EntityRiskQueue() {+ const [promotedOnly, setPromotedOnly] = useState(false);+ const [selected, setSelected] = useState<EntityRiskRecord | null>(null);++ const { data: queue, error: queueError, isLoading: queueLoading } = useSWR(+ ['entity-risk-queue', promotedOnly],+ () => entityRiskApi.queue({ limit: 50, promotedOnly }),+ { refreshInterval: 30000 },+ );+ const { data: stats } = useSWR<EntityRiskStats>(+ 'entity-risk-stats',+ () => entityRiskApi.stats(),+ { refreshInterval: 30000 },+ );++ const entities = queue?.entities ?? [];+ // Fall back to the queue's threshold (from the engine config) when the+ // stats endpoint is still loading — keeps the score bars stable.+ const threshold = stats?.threshold ?? queue?.threshold ?? 80;+ const promotedCount = stats?.promoted ?? entities.filter((e) => e.promoted).length;+ const total = stats?.total ?? entities.length;+ const alertCount = stats?.alert_count ?? entities.reduce((sum, e) => sum + e.alert_count, 0);++ const fusionUnavailable =+ queueError instanceof Error && /503|404|fetch/i.test(queueError.message);++ return (+ <div className="space-y-4">+ {/* Stats strip — anchored on the 2026 KPI bar */}+ <div className="grid grid-cols-4 gap-3">+ <div className="bg-gray-900/60 border border-gray-800/60 rounded-xl px-4 py-3">+ <p className="text-xs text-gray-500">Active entities</p>+ <p className="text-2xl font-bold mt-1 text-gray-200">{total}</p>+ <p className="text-[10px] text-gray-600 mt-0.5">+ threshold {Math.round(threshold)} pts+ </p>+ </div>+ <div className="bg-gray-900/60 border border-gray-800/60 rounded-xl px-4 py-3">+ <p className="text-xs text-gray-500">Promoted</p>+ <p className="text-2xl font-bold mt-1 text-red-400">+ {promotedCount}+ </p>+ <p className="text-[10px] text-gray-600 mt-0.5">+ entity-incidents+ </p>+ </div>+ <div className="bg-gray-900/60 border border-gray-800/60 rounded-xl px-4 py-3">+ <p className="text-xs text-gray-500">Contributing alerts</p>+ <p className="text-2xl font-bold mt-1 text-gray-200">{alertCount}</p>+ <p className="text-[10px] text-gray-600 mt-0.5">+ current decay window+ </p>+ </div>+ <RatioStat alertCount={alertCount} incidentCount={promotedCount} />+ </div>++ {/* Filters */}+ <div className="flex items-center gap-3 flex-wrap py-3 px-4 bg-gray-900/40 border border-gray-800/60 rounded-xl">+ <div className="flex items-center gap-1">+ <button+ onClick={() => setPromotedOnly(false)}+ className={clsx(+ 'text-xs px-2.5 py-1 rounded-lg transition-colors',+ !promotedOnly+ ? 'bg-blue-600 text-white'+ : 'text-gray-500 hover:text-gray-300 hover:bg-gray-800/60',+ )}+ >+ All entities+ </button>+ <button+ onClick={() => setPromotedOnly(true)}+ className={clsx(+ 'text-xs px-2.5 py-1 rounded-lg transition-colors',+ promotedOnly+ ? 'bg-red-600 text-white'+ : 'text-gray-500 hover:text-gray-300 hover:bg-gray-800/60',+ )}+ >+ Promoted only+ </button>+ </div>+ <span className="ml-auto text-xs text-gray-600">+ {entities.length} shown+ </span>+ </div>++ {/* Queue */}+ <div className="bg-gray-900/60 border border-gray-800/60 rounded-xl overflow-hidden">+ <div className="flex items-center px-4 py-2 border-b border-gray-800/60 bg-gray-900/80 gap-4">+ <span className="text-xs text-gray-500 flex-1">ENTITY</span>+ <span className="text-xs text-gray-500 w-32">RISK</span>+ <span className="text-xs text-gray-500 w-20 text-center">BAND</span>+ </div>++ {queueLoading ? (+ <div className="flex items-center justify-center h-32">+ <div className="w-6 h-6 border-2 border-blue-500 border-t-transparent rounded-full animate-spin" />+ </div>+ ) : fusionUnavailable ? (+ <div className="flex flex-col items-center justify-center h-40 text-gray-500 text-sm gap-1 px-6 text-center">+ <p className="text-gray-400">+ Risk-Based Alerting is offline or disabled+ </p>+ <p className="text-xs text-gray-600">+ Set <code className="text-gray-400">AISOC_FEATURE_RBA=true</code>{' '}+ and ensure the fusion service (port 8082) is reachable. Entities+ roll up automatically as alerts are observed.+ </p>+ </div>+ ) : queueError ? (+ <div className="flex items-center justify-center h-32 text-red-400 text-sm">+ Failed to load entity queue+ </div>+ ) : entities.length === 0 ? (+ <div className="flex flex-col items-center justify-center h-32 text-gray-500 gap-1">+ <p className="text-sm">+ {promotedOnly+ ? 'No entities have crossed the promotion threshold yet.'+ : 'No entities are currently being tracked.'}+ </p>+ <p className="text-[11px] text-gray-600">+ Decay window: 24h · half-life: 4h+ </p>+ </div>+ ) : (+ <div>+ {entities.map((record) => (+ <EntityRow+ key={`${record.entity_type}:${record.entity_value}`}+ record={record}+ onSelect={() => setSelected(record)}+ />+ ))}+ </div>+ )}+ </div>++ {selected && (+ <EntityDetailDrawer+ entity={selected}+ onClose={() => setSelected(null)}+ />+ )}+ </div>+ );+}diff --git a/apps/web/src/components/benchmark/BenchmarkResults.tsx b/apps/web/src/components/benchmark/BenchmarkResults.tsxindex 4b6329f28..050ac76e9 100644--- a/apps/web/src/components/benchmark/BenchmarkResults.tsx+++ b/apps/web/src/components/benchmark/BenchmarkResults.tsx@@ -2,121 +2,197 @@ import clsx from 'clsx';type Kind = 'measurement' | 'self-consistency';-interface SuiteRow {- id: string;- name: string;+interface PerTemplateBlock {metric: string;value: number;- display: string;target: number;- targetDisplay: string;- /** What this number represents in plain English. */- blurb: string;- /**- * Whether this suite measures real behavior (e.g. fusion logic) or merely- * the internal consistency of the substrate (template + judge agree on- * each other). The card uses this to label the gate honestly.- */- kind: Kind;- /** corpus / sub-metrics surfaced beneath the headline number */- details: { label: string; value: string }[];+ passed: boolean;+ template_count: number;+ failing_templates: string[];+}++interface SuiteBlock {+ metric: string;+ value: number;+ target: number;+ passed: boolean;+ duration_ms?: number;+ details?: Record<string, unknown>;+ per_template?: PerTemplateBlock;+}++export interface EvalReport {+ generated_at: string;+ dataset: string;+ suites: Record<string, SuiteBlock>;+ telemetry?: {+ present?: boolean;+ events?: number;+ sources?: Record<string, number>;+ incidents_with_telemetry?: number;+ path?: string;+ };+ all_passed: boolean;+ /** Source URL we actually fetched, for the "verify yourself" link. */+ _source?: string;+ /** Set when the live fetch failed and we fell back to the snapshot below. */+ _stale?: boolean;}/**- * Manual snapshot of a recent run on `main`. The numbers are hand-copied- * from `eval_report.json` produced by `scripts/run_evals.py --out- * eval_report.json` against the deterministic dataset. The audit trail —- * one report per main-branch commit — lives on the `eval-results` branch- * at `eval/results/<sha>.json` and `eval/results/latest.json`, published- * automatically by the `p1-eval` job in `.github/workflows/ci.yml`. There- * is no build-time fetch wired up here, though, so this file can drift- * between a substrate change and a marketing-page edit. The pass/fail- * gates in `services/agents/tests/test_*.py` are the source of truth: if- * the gates pass, the headline "≥ target" claim still holds even if these- * exact percentages lag a commit or two.+ * Snapshot fallback used when the live fetch from the `eval-results` branch+ * fails (e.g. the branch hasn't been initialized yet, or the build runs+ * offline). Numbers are hand-copied from a recent `scripts/run_evals.py`+ * run on `main`. The pass/fail gates in `services/agents/tests/test_*.py`+ * are the source of truth — if they pass, the headline "≥ target" claim+ * still holds even if these exact percentages lag a commit or two.+ */+const SNAPSHOT_REPORT: EvalReport = {+ generated_at: '2026-05-06T04:32:09.258436+00:00',+ dataset: 'synthetic_incidents.json (200 cases, deterministic)',+ all_passed: true,+ suites: {+ mitre_accuracy: {+ metric: 'accuracy',+ value: 0.97,+ target: 0.8,+ passed: true,+ details: { incidents: 200, correct: 194, f1: 0.7712 },+ per_template: {+ metric: 'macro_accuracy',+ value: 0.9636,+ target: 0.8,+ passed: true,+ template_count: 55,+ failing_templates: ['outlook-auto-forward-rule', 'compromised-ci-runner'],+ },+ },+ alert_reduction: {+ metric: 'reduction_ratio',+ value: 0.753,+ target: 0.7,+ passed: true,+ details: {+ alerts_in: 1000,+ incidents_out: 247,+ storm_incidents: 16,+ },+ },+ investigation_completeness: {+ metric: 'mean_keyword_coverage',+ value: 0.9425,+ target: 0.85,+ passed: true,+ details: { incidents: 200, fully_covered: 134, fully_covered_pct: 0.67 },+ per_template: {+ metric: 'macro_completeness',+ value: 0.9429,+ target: 0.8,+ passed: true,+ template_count: 55,+ failing_templates: [],+ },+ },+ response_quality: {+ metric: 'mean_rubric_score',+ value: 1.0,+ target: 0.8,+ passed: true,+ details: { incidents: 200 },+ per_template: {+ metric: 'macro_score',+ value: 1.0,+ target: 0.75,+ passed: true,+ template_count: 55,+ failing_templates: [],+ },+ },+ },+ telemetry: {+ present: true,+ events: 361,+ incidents_with_telemetry: 200,+ path: 'services/agents/tests/eval_data/synthetic_telemetry.jsonl',+ },+};++const LATEST_URL =+ 'https://raw.githubusercontent.com/beenuar/AiSOC/eval-results/eval/results/latest.json';++/**+ * Server-side fetch of the most recent `eval_report.json` published by the+ * `p1-eval` job in `.github/workflows/ci.yml`. The job writes+ * `eval/results/<sha>.json` and `eval/results/latest.json` on the+ * `eval-results` branch on every successful main-branch run.*- * The blurbs deliberately avoid "agent accuracy" framing. The harness is- * deterministic substrate code (no LLM calls), and three of the four metrics- * mostly verify that the substrate is internally consistent (template + judge- * agree on each other). We label that explicitly rather than letting a casual- * reader assume the LangGraph agent is being graded.+ * We use Next.js fetch revalidation so the page stays fresh between pushes+ * without rebuilding the site. On failure we transparently fall back to the+ * hand-copied `SNAPSHOT_REPORT` and flag the response as stale.*/-const SUITES: SuiteRow[] = [- {+export async function fetchLatestEvalReport(): Promise<EvalReport> {+ try {+ const res = await fetch(LATEST_URL, {+ // Re-fetch every 5 minutes; CI publishes on every main-branch push.+ next: { revalidate: 300 },+ });+ if (!res.ok) {+ throw new Error(`status ${res.status}`);+ }+ const data = (await res.json()) as EvalReport;+ return { ...data, _source: LATEST_URL };+ } catch {+ return { ...SNAPSHOT_REPORT, _source: LATEST_URL, _stale: true };+ }+}++interface SuiteCard {+ id: string;+ name: string;+ metricLabel: string;+ blurb: string;+ kind: Kind;+}++const SUITE_META: Record<string, SuiteCard> = {+ alert_reduction: {id: 'alert_reduction',name: 'Alert reduction',- metric: 'Reduction ratio',- value: 0.753,- display: '75.3%',- target: 0.7,- targetDisplay: '≥70%',+ metricLabel: 'Reduction ratio',kind: 'measurement',blurb:"A 1,000-alert noisy stream (duplicates, near-duplicates, rule storms, low-score chatter) is fed into an in-harness re-implementation of the production Tier 1 / 2 / 3 grouping rules — same logic, no DB-backed dedup or ML scorer. The number is whatever the code produces; a regression in the grouping rules moves it.",- details: [- { label: 'Alerts in', value: '1,000' },- { label: 'Incidents out', value: '247' },- { label: 'Storms', value: '16' },- ],},- {+ mitre_accuracy: {id: 'mitre_accuracy',name: 'MITRE tactic accuracy',- metric: 'Tactic accuracy',- value: 0.97,- display: '97.0%',- target: 0.8,- targetDisplay: '≥80%',+ metricLabel: 'Tactic accuracy (per-case)',kind: 'self-consistency',blurb:- 'Each synthetic incident is generated with a labeled tactic and a description written to include keywords the hand-curated extractor recognizes. The 97% mostly checks that dataset and extractor agree — useful as a regression sentinel for the extractor, not a measure of LLM agent accuracy.',- details: [- { label: 'Incidents', value: '200' },- { label: 'Correct', value: '194' },- { label: 'F1 (per-case)', value: '0.78' },- ],+ 'Each synthetic incident is generated with a labeled tactic and a description written to include keywords the hand-curated extractor recognizes. The headline number mostly checks that dataset and extractor agree — useful as a regression sentinel for the extractor, not a measure of LLM agent accuracy.',},- {+ investigation_completeness: {id: 'investigation_completeness',name: 'Investigation completeness',- metric: 'Mean keyword coverage',- value: 0.943,- display: '94.3%',- target: 0.85,- targetDisplay: '≥85%',+ metricLabel: 'Mean keyword coverage',kind: 'self-consistency',blurb:"The simulator wraps each incident's description in a Markdown report; the judge then looks for evidence keywords drawn from that same description. Close to a string-copy tautology — it confirms the report template includes the description and the judge can find keywords inside it. Catches template breakage, not LLM quality.",- details: [- { label: 'Incidents', value: '200' },- { label: 'Fully covered', value: '134 (67%)' },- { label: 'Judge', value: 'Offline keyword' },- ],},- {+ response_quality: {id: 'response_quality',name: 'Response-plan quality',- metric: 'Mean rubric score',- value: 1.0,- display: '100%',- target: 0.8,- targetDisplay: '≥80%',+ metricLabel: 'Mean rubric score',kind: 'self-consistency',blurb:- "The synthesizer embeds the expected MITRE techniques and first evidence keyword directly into the templated plan, then a 5-criterion rubric checks for them. By construction the score is ~1.000. Catches a broken templating pipeline; it is not a grade of LLM-written plans.",- details: [- { label: 'Incidents', value: '200' },- { label: 'Criteria', value: '5 (all hit by template)' },- { label: 'Judge', value: 'Offline keyword' },- ],+ 'The synthesizer embeds the expected MITRE techniques and first evidence keyword directly into the templated plan, then a 5-criterion rubric checks for them. By construction the score is ~1.000. Catches a broken templating pipeline; it is not a grade of LLM-written plans.',},-];+};const KIND_LABEL: Record<Kind, { label: string; classes: string }> = {measurement: {label: 'Real measurement',- classes:- 'border-emerald-500/30 bg-emerald-500/10 text-emerald-200',+ classes: 'border-emerald-500/30 bg-emerald-500/10 text-emerald-200',},'self-consistency': {label: 'Substrate self-consistency',@@ -124,25 +200,82 @@ const KIND_LABEL: Record<Kind, { label: string; classes: string }> = {},};-export function BenchmarkResults() {+function formatPercent(value: number): string {+ return `${(value * 100).toFixed(1)}%`;+}++function formatTarget(value: number): string {+ return `≥${(value * 100).toFixed(0)}%`;+}++function suiteDetailRows(+ id: string,+ suite: SuiteBlock,+): { label: string; value: string }[] {+ const d = suite.details ?? {};+ const rows: { label: string; value: string }[] = [];+ if (id === 'alert_reduction') {+ if (typeof d.alerts_in === 'number') rows.push({ label: 'Alerts in', value: String(d.alerts_in) });+ if (typeof d.incidents_out === 'number')+ rows.push({ label: 'Incidents out', value: String(d.incidents_out) });+ if (typeof d.storm_incidents === 'number')+ rows.push({ label: 'Storms', value: String(d.storm_incidents) });+ } else if (id === 'mitre_accuracy') {+ if (typeof d.incidents === 'number') rows.push({ label: 'Incidents', value: String(d.incidents) });+ if (typeof d.correct === 'number') rows.push({ label: 'Correct', value: String(d.correct) });+ if (typeof d.f1 === 'number') rows.push({ label: 'F1 (per-case)', value: d.f1.toFixed(2) });+ } else if (id === 'investigation_completeness') {+ if (typeof d.incidents === 'number') rows.push({ label: 'Incidents', value: String(d.incidents) });+ if (typeof d.fully_covered === 'number' && typeof d.fully_covered_pct === 'number') {+ rows.push({+ label: 'Fully covered',+ value: `${d.fully_covered} (${(d.fully_covered_pct * 100).toFixed(0)}%)`,+ });+ }+ rows.push({ label: 'Judge', value: 'Offline keyword' });+ } else if (id === 'response_quality') {+ if (typeof d.incidents === 'number') rows.push({ label: 'Incidents', value: String(d.incidents) });+ rows.push({ label: 'Criteria', value: '5 (all hit by template)' });+ rows.push({ label: 'Judge', value: 'Offline keyword' });+ }+ return rows;+}++interface BenchmarkResultsProps {+ report: EvalReport;+}++export function BenchmarkResults({ report }: BenchmarkResultsProps) {+ const orderedIds: string[] = [+ 'alert_reduction',+ 'mitre_accuracy',+ 'investigation_completeness',+ 'response_quality',+ ];+return (<div className="grid gap-4 md:grid-cols-2">- {SUITES.map((suite) => {- const passed = suite.value >= suite.target;+ {orderedIds.map((id) => {+ const suite = report.suites[id];+ const meta = SUITE_META[id];+ if (!suite || !meta) return null;+ const passed = suite.passed;const headroom = ((suite.value - suite.target) * 100).toFixed(1);- const kind = KIND_LABEL[suite.kind];+ const kind = KIND_LABEL[meta.kind];+ const details = suiteDetailRows(id, suite);+ const perTemplate = suite.per_template;return (<div- key={suite.id}+ key={id}className="group relative overflow-hidden rounded-xl border border-white/10 bg-white/[0.02] p-6 transition-colors hover:border-white/20"><div className="flex items-start justify-between gap-4"><div><p className="text-xs uppercase tracking-wider text-gray-500">- {suite.metric}+ {meta.metricLabel}</p><h3 className="mt-1 text-base font-semibold text-white">- {suite.name}+ {meta.name}</h3></div><span@@ -165,10 +298,10 @@ export function BenchmarkResults() {<div className="mt-5 flex items-baseline gap-2"><span className="font-mono text-4xl font-semibold tabular-nums text-white">- {suite.display}+ {formatPercent(suite.value)}</span><span className="text-xs text-gray-500">- target {suite.targetDisplay}+ target {formatTarget(suite.target)}</span></div><div className="mt-1 text-xs text-gray-500">@@ -185,19 +318,54 @@ export function BenchmarkResults() {</span><p className="mt-3 text-sm leading-relaxed text-gray-400">- {suite.blurb}+ {meta.blurb}</p>- <div className="mt-5 flex flex-wrap gap-x-6 gap-y-2 border-t border-white/5 pt-4 text-xs">- {suite.details.map((d) => (- <div key={d.label}>- <dt className="text-gray-500">{d.label}</dt>- <dd className="mt-0.5 font-mono tabular-nums text-gray-200">- {d.value}- </dd>+ {perTemplate && (+ <div className="mt-4 rounded-lg border border-white/5 bg-black/20 p-3">+ <div className="flex items-center justify-between gap-3">+ <div>+ <p className="text-[10px] font-semibold uppercase tracking-wider text-gray-500">+ Per-template macro+ </p>+ <p className="mt-0.5 text-xs text-gray-400">+ Equal-weight average across {perTemplate.template_count} distinct+ incident templates — surfaces a single weak template that the+ per-case mean would mask.+ </p>+ </div>+ <div className="text-right">+ <span className="font-mono text-base font-semibold tabular-nums text-white">+ {formatPercent(perTemplate.value)}+ </span>+ <p className="mt-0.5 text-[10px] text-gray-500">+ target {formatTarget(perTemplate.target)}+ </p>+ </div></div>- ))}- </div>+ {perTemplate.failing_templates.length > 0 && (+ <p className="mt-2 text-[11px] text-amber-300/80">+ Regressions:{' '}+ <span className="font-mono">+ {perTemplate.failing_templates.join(', ')}+ </span>+ </p>+ )}+ </div>+ )}++ {details.length > 0 && (+ <div className="mt-5 flex flex-wrap gap-x-6 gap-y-2 border-t border-white/5 pt-4 text-xs">+ {details.map((d) => (+ <div key={d.label}>+ <dt className="text-gray-500">{d.label}</dt>+ <dd className="mt-0.5 font-mono tabular-nums text-gray-200">+ {d.value}+ </dd>+ </div>+ ))}+ </div>+ )}</div>);})}diff --git a/apps/web/src/components/benchmark/CommunitySubmissions.tsx b/apps/web/src/components/benchmark/CommunitySubmissions.tsxnew file mode 100644index 000000000..da412467f--- /dev/null+++ b/apps/web/src/components/benchmark/CommunitySubmissions.tsx@@ -0,0 +1,95 @@+/**+ * Community submission section. The harness is MIT and reproducible, so+ * any third party can run `python3 scripts/run_evals.py --json --out report.json`+ * against the same fixed dataset and submit their numbers. Submissions go+ * through a structured GitHub issue template+ * (`.github/ISSUE_TEMPLATE/benchmark_submission.yml`); accepted entries are+ * rendered here.+ *+ * Server component — no live fetch yet (the leaderboard starts empty and+ * fills up as submissions are accepted). Future work: a JSON manifest at+ * `eval/community/index.json` on the `eval-results` branch, fetched the+ * same way the latest report is.+ */+const SUBMISSION_URL =+ 'https://github.com/beenuar/AiSOC/issues/new?template=benchmark_submission.yml';++const RULES: { title: string; body: string }[] = [+ {+ title: 'Same fixed dataset',+ body: 'Run against the deterministic 200-incident dataset at services/agents/tests/eval_data/synthetic_incidents.json on the commit you submit. No private fixtures.',+ },+ {+ title: 'Same harness',+ body: 'Run scripts/run_evals.py --json --out report.json with no flags that disable gates. Attach the full report.json so per-template macros are auditable.',+ },+ {+ title: 'Open agent or label as closed',+ body: 'If your agent code is open, link it. If it is closed, the entry is still accepted but is labeled "closed-source" so reviewers know they cannot reproduce internals.',+ },+ {+ title: 'No template-stuffing',+ body: 'The three substrate self-consistency suites (MITRE, completeness, response) are gameable by stuffing keywords into reports. Submissions caught doing this are rejected; the alert-reduction measurement is not gameable in the same way.',+ },+];++export function CommunitySubmissions() {+ return (+ <div className="rounded-2xl border border-white/10 bg-white/[0.02] p-8">+ <div className="flex flex-wrap items-start justify-between gap-4">+ <div>+ <h3 className="text-xl font-semibold tracking-tight text-white">+ Community submissions+ </h3>+ <p className="mt-2 max-w-2xl text-sm text-gray-400">+ The dataset and the harness are MIT and reproducible. Any third+ party — another open-source project, a vendor, or an+ internal team — can run the same suite against the same+ 200 incidents and submit a result. Accepted entries appear here.+ </p>+ </div>+ <a+ href={SUBMISSION_URL}+ target="_blank"+ rel="noreferrer"+ className="inline-flex items-center gap-2 rounded-md bg-brand-500 px-4 py-2 text-sm font-semibold text-white transition hover:bg-brand-400"+ >+ Submit a run+ <svg+ viewBox="0 0 20 20"+ className="h-3.5 w-3.5"+ fill="currentColor"+ aria-hidden="true"+ >+ <path d="M5.22 14.78a.75.75 0 001.06 0l7.22-7.22v3.69a.75.75 0 001.5 0v-5.5a.75.75 0 00-.75-.75h-5.5a.75.75 0 000 1.5h3.69L5.22 13.72a.75.75 0 000 1.06z" />+ </svg>+ </a>+ </div>++ <h4 className="mt-8 text-sm font-semibold text-white">Submission rules</h4>+ <dl className="mt-3 grid gap-4 sm:grid-cols-2">+ {RULES.map((r) => (+ <div+ key={r.title}+ className="rounded-lg border border-white/5 bg-black/20 p-4"+ >+ <dt className="text-sm font-semibold text-gray-200">{r.title}</dt>+ <dd className="mt-1 text-xs leading-relaxed text-gray-400">+ {r.body}+ </dd>+ </div>+ ))}+ </dl>++ <div className="mt-8 rounded-lg border border-dashed border-white/10 bg-black/20 p-6 text-center">+ <p className="text-sm text-gray-400">+ No accepted community submissions yet.+ </p>+ <p className="mt-1 text-xs text-gray-500">+ The leaderboard fills up as runs are merged. AiSOC's own numbers+ appear in the cards above.+ </p>+ </div>+ </div>+ );+}diff --git a/apps/web/src/components/benchmark/KpiBar.tsx b/apps/web/src/components/benchmark/KpiBar.tsxnew file mode 100644index 000000000..b757cc1a0--- /dev/null+++ b/apps/web/src/components/benchmark/KpiBar.tsx@@ -0,0 +1,168 @@+import clsx from 'clsx';+import type { EvalReport } from './BenchmarkResults';++/**+ * 2026 published KPI bar — the buyer-side scoring rubric AiSOC commits to.+ * Mirrors `DEFAULT_KPI_BAR_TARGETS` in `services/api/app/services/sla.py`+ * and the four metrics surfaced in the in-app SLA dashboard+ * (`apps/web/src/components/sla/SLADashboard.tsx`).+ *+ * MTTD/MTTR are tenant-runtime metrics, surfaced inside the product rather+ * than on the public scoreboard. The four metrics below are the ones we can+ * report from the open synthetic harness without needing a live tenant.+ */+interface KpiTarget {+ id: string;+ label: string;+ target: string;+ /**+ * Live observed number from the eval report when available, else "n/a".+ */+ observed?: string;+ observedPasses?: boolean;+ blurb: string;+}++function fmtPct(value: number): string {+ return `${(value * 100).toFixed(1)}%`;+}++function buildTargets(report: EvalReport): KpiTarget[] {+ const alertReduction = report.suites.alert_reduction;+ const mitre = report.suites.mitre_accuracy;++ // Alert-to-incident ratio is derived from the alert-reduction suite:+ // 1,000 fabricated alerts compress to N incidents → ratio = 1000 / N.+ const alertsIn = (alertReduction?.details?.alerts_in as number | undefined) ?? 1000;+ const incidentsOut = alertReduction?.details?.incidents_out as number | undefined;+ const ratio = incidentsOut && incidentsOut > 0 ? alertsIn / incidentsOut : undefined;+ const ratioObserved = ratio ? `${ratio.toFixed(1)}:1` : undefined;+ const ratioPasses = typeof ratio === 'number' ? ratio >= 50 : undefined;++ // MITRE technique tagging: per-template macro is the closest published+ // proxy on the open harness. The in-tenant SLA dashboard uses the live+ // `mitre_technique_tagging_min_pct` from `tenant_sla_summary`.+ const macro = mitre?.per_template;+ const macroValue = macro?.value;+ const macroPasses = typeof macroValue === 'number' ? macroValue >= 0.85 : undefined;++ return [+ {+ id: 'fp_rate',+ label: 'False-positive rate',+ target: '≤ 5%',+ blurb:+ "A live tenant metric from `services/api`'s SLA service — surfaced in the in-app SLA dashboard, not on the public harness. The harness can't measure FP rate against synthetic data.",+ },+ {+ id: 'a2i_ratio',+ label: 'Alert-to-incident ratio',+ target: '≥ 50:1',+ observed: ratioObserved,+ observedPasses: ratioPasses,+ blurb:+ 'Derived from the alert-reduction suite: a 1,000-alert noisy stream is fed through the in-harness fusion grouping, and the ratio is 1,000 ÷ incidents_out.',+ },+ {+ id: 'mitre_t',+ label: 'MITRE technique tagging',+ target: '≥ 85%',+ observed: typeof macroValue === 'number' ? fmtPct(macroValue) : undefined,+ observedPasses: macroPasses,+ blurb:+ 'Per-template macro accuracy across 55 incident templates is the closest open-harness proxy. In-tenant data uses the live ECS technique-tag rate.',+ },+ {+ id: 'mitre_st',+ label: 'MITRE sub-technique tagging',+ target: '≥ 60%',+ blurb:+ 'Live tenant metric. The synthetic harness labels at the tactic level; sub-technique coverage is reported from live detection content in the in-app SLA dashboard.',+ },+ ];+}++interface KpiBarProps {+ report: EvalReport;+}++export function KpiBar({ report }: KpiBarProps) {+ const targets = buildTargets(report);+ return (+ <div className="rounded-2xl border border-white/10 bg-white/[0.02] p-6">+ <div className="flex flex-wrap items-baseline justify-between gap-3">+ <div>+ <h3 className="text-lg font-semibold tracking-tight text-white">+ 2026 published KPI bar+ </h3>+ <p className="mt-1 max-w-2xl text-sm text-gray-400">+ The four buyer-side targets AiSOC commits to. The two derivable+ from the open harness are checked live below; the other two are+ tenant-runtime metrics surfaced in the in-app SLA dashboard.+ </p>+ </div>+ <a+ href="https://github.com/beenuar/AiSOC/blob/main/services/api/app/services/sla.py"+ target="_blank"+ rel="noreferrer"+ className="text-xs text-gray-500 underline decoration-dotted hover:text-gray-300"+ >+ Source: services/api/app/services/sla.py+ </a>+ </div>+ <dl className="mt-5 grid gap-3 sm:grid-cols-2 lg:grid-cols-4">+ {targets.map((t) => {+ const hasLive = typeof t.observed === 'string';+ const passes = t.observedPasses;+ return (+ <div+ key={t.id}+ className="rounded-lg border border-white/5 bg-black/20 p-4"+ >+ <dt className="text-[11px] font-semibold uppercase tracking-wider text-gray-500">+ {t.label}+ </dt>+ <dd className="mt-1 flex items-baseline gap-2">+ <span className="font-mono text-xl font-semibold tabular-nums text-white">+ {t.target}+ </span>+ {hasLive && (+ <span+ className={clsx(+ 'inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[10px] font-semibold',+ passes === false+ ? 'border-rose-500/30 bg-rose-500/10 text-rose-300'+ : passes+ ? 'border-emerald-500/30 bg-emerald-500/10 text-emerald-300'+ : 'border-white/10 bg-white/[0.03] text-gray-400',+ )}+ >+ <span+ className={clsx(+ 'h-1.5 w-1.5 rounded-full',+ passes === false+ ? 'bg-rose-400'+ : passes+ ? 'bg-emerald-400'+ : 'bg-gray-400',+ )}+ />+ Live: {t.observed}+ </span>+ )}+ {!hasLive && (+ <span className="text-[10px] uppercase tracking-wider text-gray-600">+ in-app+ </span>+ )}+ </dd>+ <p className="mt-2 text-xs leading-relaxed text-gray-500">+ {t.blurb}+ </p>+ </div>+ );+ })}+ </dl>+ </div>+ );+}diff --git a/apps/web/src/components/cases/CasesView.tsx b/apps/web/src/components/cases/CasesView.tsxindex b2f17aa77..214ff0ca7 100644--- a/apps/web/src/components/cases/CasesView.tsx+++ b/apps/web/src/components/cases/CasesView.tsx@@ -41,9 +41,13 @@ const SEVERITY_CONFIG = {low: { label: 'Low', className: 'text-blue-400 bg-blue-500/10 border-blue-500/20' },};-const STATUS_CONFIG = {+const STATUS_CONFIG: Record<+ Case['status'],+ { label: string; className: string; dot: string }+> = {open: { label: 'Open', className: 'text-gray-300 bg-gray-700/50 border-gray-600/50', dot: 'bg-gray-400' },in_progress: { label: 'In Progress', className: 'text-blue-300 bg-blue-500/10 border-blue-500/20', dot: 'bg-blue-400 animate-pulse' },+ pending: { label: 'Pending', className: 'text-amber-300 bg-amber-500/10 border-amber-500/20', dot: 'bg-amber-400' },resolved: { label: 'Resolved', className: 'text-green-300 bg-green-500/10 border-green-500/20', dot: 'bg-green-400' },closed: { label: 'Closed', className: 'text-gray-500 bg-gray-800/50 border-gray-700/50', dot: 'bg-gray-600' },};@@ -113,7 +117,14 @@ export function CasesView() {const { data: casesData, isLoading } = useSWR(['cases', statusFilter, severityFilter],() => casesApi.list({ status: statusFilter !== 'all' ? statusFilter : undefined }),- { fallbackData: { cases: MOCK_CASES, total: MOCK_CASES.length } }+ {+ fallbackData: {+ cases: MOCK_CASES,+ total: MOCK_CASES.length,+ page: 1,+ pageSize: MOCK_CASES.length,+ },+ });const cases = (casesData?.cases || []).filter((c) => {diff --git a/apps/web/src/components/compliance/SOC2View.tsx b/apps/web/src/components/compliance/SOC2View.tsxindex ae5dd55bc..4826c55b9 100644--- a/apps/web/src/components/compliance/SOC2View.tsx+++ b/apps/web/src/components/compliance/SOC2View.tsx@@ -273,7 +273,7 @@ export function SOC2View() {</h4>{item.evidence.length === 0 ? (<p className="text-sm text-gray-400 italic">- No evidence collected yet. Click "Collect Evidence" to auto-gather.+ No evidence collected yet. Click “Collect Evidence” to auto-gather.</p>) : (<div className="space-y-2">diff --git a/apps/web/src/components/detections/DetectionProposalsView.tsx b/apps/web/src/components/detections/DetectionProposalsView.tsxnew file mode 100644index 000000000..0f0e549f6--- /dev/null+++ b/apps/web/src/components/detections/DetectionProposalsView.tsx@@ -0,0 +1,265 @@+'use client';++// Wave 2 — w2-dac. Lightweight queue for the detection-as-code lifecycle:+// propose → review (comment / attach eval report) → eval-gated → promote.+// Backend at /api/v1/detection-proposals enforces the ≥ 1pp MITRE+// regression gate against the active baseline; this UI is a thin operator+// surface for that pipeline.++import { useState } from 'react';+import Link from 'next/link';+import useSWR from 'swr';+import { clsx } from 'clsx';+import { formatDistanceToNow } from 'date-fns';+import toast from 'react-hot-toast';+import {+ detectionProposalsApi,+ type DetectionProposal,+ type DetectionProposalStatus,+} from '@/lib/api';+import { Skeleton } from '@/components/ui/Skeleton';+import { ErrorState } from '@/components/ui/ErrorState';+import { EmptyState } from '@/components/ui/EmptyState';++const STATUS_COPY: Record<+ DetectionProposalStatus,+ { label: string; tone: string }+> = {+ proposed: { label: 'Proposed', tone: 'bg-gray-700/40 text-gray-200' },+ in_review: { label: 'In review', tone: 'bg-blue-500/20 text-blue-200' },+ eval_passed: {+ label: 'Eval passed',+ tone: 'bg-emerald-500/20 text-emerald-200',+ },+ eval_failed: { label: 'Eval failed', tone: 'bg-red-500/20 text-red-200' },+ approved: { label: 'Approved', tone: 'bg-emerald-500/20 text-emerald-200' },+ rejected: { label: 'Rejected', tone: 'bg-red-500/20 text-red-200' },+ promoted: { label: 'Promoted', tone: 'bg-violet-500/20 text-violet-200' },+};++function fmtPct(n?: number): string {+ if (n === undefined || n === null || Number.isNaN(n)) return '—';+ return `${(n * 100).toFixed(1)}%`;+}++export function DetectionProposalsView() {+ const [filter, setFilter] = useState<DetectionProposalStatus | 'all'>('all');++ const { data, error, isLoading, mutate } = useSWR(+ ['detection-proposals', filter],+ () =>+ detectionProposalsApi.list(+ filter === 'all' ? undefined : { status: filter },+ ),+ );++ const proposals = data ?? [];++ const decide = async (+ p: DetectionProposal,+ decision: 'approve' | 'reject',+ ) => {+ try {+ await detectionProposalsApi.decide(p.id, { decision });+ toast.success(decision === 'approve' ? 'Approved' : 'Rejected');+ mutate();+ } catch (err) {+ console.warn(`Decide ${decision} failed`, err);+ toast.error(`Could not ${decision} proposal`);+ }+ };++ const promote = async (p: DetectionProposal) => {+ try {+ await detectionProposalsApi.promote(p.id);+ toast.success('Promoted to active rule');+ mutate();+ } catch (err) {+ console.warn('Promote failed', err);+ toast.error('Promote blocked — check eval gate');+ }+ };++ return (+ <div className="space-y-5">+ <div className="flex flex-col gap-3 lg:flex-row lg:items-end lg:justify-between">+ <div>+ <h1 className="text-2xl font-semibold text-gray-100">+ Detection proposals+ </h1>+ <p className="mt-1 max-w-2xl text-sm text-gray-500">+ Detection-as-code lifecycle. Every proposal is graded by{' '}+ <code className="rounded bg-gray-800 px-1 py-0.5 text-xs text-gray-300">+ run_evals.py+ </code>{' '}+ and a ≥ 1pp MITRE accuracy regression vs. the active baseline+ blocks promotion to a live rule.+ </p>+ </div>+ <div className="flex items-center gap-2">+ <Link+ href="/detection"+ className="rounded-md border border-gray-800 px-3 py-2 text-sm text-gray-300 hover:bg-gray-800"+ >+ ← Active rules+ </Link>+ </div>+ </div>++ <div className="flex flex-wrap gap-2">+ {(['all', ...(Object.keys(STATUS_COPY) as DetectionProposalStatus[])] as Array<+ DetectionProposalStatus | 'all'+ >).map((opt) => (+ <button+ key={opt}+ onClick={() => setFilter(opt)}+ className={clsx(+ 'rounded-md border px-3 py-1.5 text-xs transition-colors',+ filter === opt+ ? 'border-blue-500/40 bg-blue-500/10 text-blue-200'+ : 'border-gray-800 text-gray-400 hover:bg-gray-800/50',+ )}+ >+ {opt === 'all' ? 'All' : STATUS_COPY[opt].label}+ </button>+ ))}+ </div>++ {isLoading ? (+ <div className="space-y-3">+ {[0, 1, 2].map((i) => (+ <Skeleton key={i} className="h-28 w-full" />+ ))}+ </div>+ ) : error ? (+ <ErrorState+ title="Couldn't load proposals"+ description="The detection-as-code service didn't respond."+ error={error}+ onRetry={() => mutate()}+ />+ ) : proposals.length === 0 ? (+ <EmptyState+ title="No proposals yet"+ description="Proposals appear here as soon as someone POSTs to /api/v1/detection-proposals or imports a detection from the catalog with the eval gate enabled."+ />+ ) : (+ <ul className="space-y-3">+ {proposals.map((p) => (+ <li+ key={p.id}+ className="rounded-lg border border-gray-800 bg-gray-900/40 p-4"+ >+ <div className="flex flex-wrap items-start justify-between gap-3">+ <div className="min-w-0 flex-1">+ <div className="flex flex-wrap items-center gap-2">+ <span+ className={clsx(+ 'rounded px-2 py-0.5 text-[11px] font-medium uppercase tracking-wide',+ STATUS_COPY[p.status].tone,+ )}+ >+ {STATUS_COPY[p.status].label}+ </span>+ <h3 className="truncate text-base font-medium text-gray-100">+ {p.name}+ </h3>+ <span className="text-xs text-gray-500">+ {p.rule_language.toUpperCase()} · {p.severity}+ </span>+ </div>+ {p.description && (+ <p className="mt-1 text-sm text-gray-400">+ {p.description}+ </p>+ )}+ <div className="mt-2 flex flex-wrap items-center gap-3 text-xs text-gray-500">+ <span>+ Updated{' '}+ {formatDistanceToNow(new Date(p.updated_at), {+ addSuffix: true,+ })}+ </span>+ {p.mitre_techniques?.length > 0 && (+ <span>MITRE: {p.mitre_techniques.join(', ')}</span>+ )}+ </div>+ {p.eval_result && 'candidate' in p.eval_result && (+ <div className="mt-3 grid grid-cols-2 gap-3 rounded-md border border-gray-800 bg-gray-950/60 p-3 text-xs sm:grid-cols-4">+ <div>+ <div className="text-gray-500">Candidate MITRE</div>+ <div className="font-mono text-gray-200">+ {fmtPct(p.eval_result.candidate?.mitre_accuracy)}+ </div>+ </div>+ <div>+ <div className="text-gray-500">Baseline MITRE</div>+ <div className="font-mono text-gray-200">+ {fmtPct(p.eval_result.baseline?.mitre_accuracy)}+ </div>+ </div>+ <div>+ <div className="text-gray-500">Regression</div>+ <div+ className={clsx(+ 'font-mono',+ p.eval_result.regressed+ ? 'text-red-300'+ : 'text-emerald-300',+ )}+ >+ {p.eval_result.drop_pp !== undefined+ ? `${(p.eval_result.drop_pp * 100).toFixed(2)}pp`+ : '—'}+ </div>+ </div>+ <div>+ <div className="text-gray-500">Gate</div>+ <div+ className={clsx(+ 'font-medium',+ p.eval_result.passed+ ? 'text-emerald-300'+ : 'text-red-300',+ )}+ >+ {p.eval_result.passed ? 'PASS' : 'FAIL'}+ </div>+ </div>+ </div>+ )}+ </div>+ <div className="flex shrink-0 flex-col gap-2">+ {p.status === 'eval_passed' || p.status === 'in_review' ? (+ <>+ <button+ onClick={() => decide(p, 'approve')}+ className="rounded-md bg-emerald-500/20 px-3 py-1.5 text-xs font-medium text-emerald-200 hover:bg-emerald-500/30"+ >+ Approve+ </button>+ <button+ onClick={() => decide(p, 'reject')}+ className="rounded-md border border-red-500/40 px-3 py-1.5 text-xs text-red-300 hover:bg-red-500/10"+ >+ Reject+ </button>+ </>+ ) : null}+ {p.status === 'approved' && (+ <button+ onClick={() => promote(p)}+ className="rounded-md bg-violet-500/20 px-3 py-1.5 text-xs font-medium text-violet-200 hover:bg-violet-500/30"+ >+ Promote → Active+ </button>+ )}+ </div>+ </div>+ </li>+ ))}+ </ul>+ )}+ </div>+ );+}diff --git a/apps/web/src/components/detections/DetectionsView.tsx b/apps/web/src/components/detections/DetectionsView.tsxindex 2ccbb9ff9..b859b00ef 100644--- a/apps/web/src/components/detections/DetectionsView.tsx+++ b/apps/web/src/components/detections/DetectionsView.tsx@@ -214,21 +214,29 @@ export function DetectionsView() {triggered.</p></div>- <Link- href="/detection/new"- className="inline-flex items-center justify-center gap-2 rounded-md bg-blue-500 px-4 py-2 text-sm font-medium text-white shadow-sm transition-colors hover:bg-blue-600"- >- <svg- className="h-4 w-4"- viewBox="0 0 24 24"- fill="none"- stroke="currentColor"- strokeWidth={2}+ <div className="flex items-center gap-2">+ <Link+ href="/detection/proposals"+ className="inline-flex items-center justify-center gap-2 rounded-md border border-gray-800 px-3 py-2 text-sm text-gray-300 hover:bg-gray-800">- <path d="M12 5v14M5 12h14" strokeLinecap="round" />- </svg>- New rule- </Link>+ Proposals+ </Link>+ <Link+ href="/detection/new"+ className="inline-flex items-center justify-center gap-2 rounded-md bg-blue-500 px-4 py-2 text-sm font-medium text-white shadow-sm transition-colors hover:bg-blue-600"+ >+ <svg+ className="h-4 w-4"+ viewBox="0 0 24 24"+ fill="none"+ stroke="currentColor"+ strokeWidth={2}+ >+ <path d="M12 5v14M5 12h14" strokeLinecap="round" />+ </svg>+ New rule+ </Link>+ </div></div>{/* Demo banner */}diff --git a/apps/web/src/components/detections/RuleEditor.tsx b/apps/web/src/components/detections/RuleEditor.tsxindex 4e7231d08..7c250226e 100644--- a/apps/web/src/components/detections/RuleEditor.tsx+++ b/apps/web/src/components/detections/RuleEditor.tsx@@ -459,7 +459,7 @@ export function RuleEditor({ mode, ruleId }: RuleEditorProps) {<div className="h-56 overflow-y-auto px-4 py-3 text-sm">{!testResult ? (<div className="flex h-full items-center justify-center text-xs text-gray-600">- Click "Run test" to evaluate the rule.+ Click “Run test” to evaluate the rule.</div>) : testResult.matches > 0 ? (<div className="space-y-2">@@ -709,6 +709,8 @@ function severityActive(sev: AlertSeverity): string {return 'bg-yellow-500/15 text-yellow-300 ring-yellow-500/40';case 'low':return 'bg-blue-500/15 text-blue-300 ring-blue-500/40';+ case 'info':+ return 'bg-slate-500/15 text-slate-300 ring-slate-500/40';}}diff --git a/apps/web/src/components/landing/Hero.tsx b/apps/web/src/components/landing/Hero.tsxindex 651dfdc3d..736938e54 100644--- a/apps/web/src/components/landing/Hero.tsx+++ b/apps/web/src/components/landing/Hero.tsx@@ -30,12 +30,13 @@ export function Hero() {<p className="mt-6 max-w-xl text-lg leading-relaxed text-gray-300 md:text-xl">Agent prompts, tool calls, and decisions are recorded in an investigation- ledger and replayable per case. The substrate underneath is gated by a- 200-incident eval harness that runs on every PR targeting{' '}+ ledger and replayable per case. Alert fusion, entity risk rollups, and purple-team+ drills ship in-repo alongside connectors and detection-as-code. The stack is gated+ by a 200-incident eval harness on every PR to{' '}<code className="rounded bg-white/[0.06] px-1 py-0.5 font-mono text-base">main</code>{' '}/{' '}<code className="rounded bg-white/[0.06] px-1 py-0.5 font-mono text-base">develop</code>.- MIT-licensed and self-hostable.+ MIT-licensed and self-hostable — tryaisoc.com is the always-on demo.</p><div className="mt-8 flex flex-wrap items-center gap-3">diff --git a/apps/web/src/components/marketplace/MarketplaceView.test.tsx b/apps/web/src/components/marketplace/MarketplaceView.test.tsxindex 5768bfefc..83dcfd6ef 100644--- a/apps/web/src/components/marketplace/MarketplaceView.test.tsx+++ b/apps/web/src/components/marketplace/MarketplaceView.test.tsx@@ -73,7 +73,10 @@ describe('MarketplaceView install flow', () => {});it('POSTs to /api/v1/marketplace/install when the user clicks Install', async () => {- const fetchMock = vi.fn(async () => new Response(JSON.stringify({ ok: true }), { status: 200 }));+ const fetchMock = vi.fn(+ async (): Promise<Response> =>+ new Response(JSON.stringify({ ok: true }), { status: 200 }),+ );vi.stubGlobal('fetch', fetchMock);render(<MarketplaceView />);@@ -92,9 +95,10 @@ describe('MarketplaceView install flow', () => {});// Body must include the item type+id, not arbitrary data.- const call = fetchMock.mock.calls.find((c) => c[0] === '/api/v1/marketplace/install');+ const calls = fetchMock.mock.calls as unknown as [string, RequestInit][];+ const call = calls.find((c) => c[0] === '/api/v1/marketplace/install');expect(call).toBeTruthy();- const body = JSON.parse((call as [string, RequestInit])[1].body as string);+ const body = JSON.parse(String(call![1]?.body));expect(body).toEqual({ type: 'plugin', id: 'cloudflare-waf' });// After a successful POST the optimistic toggle flips to the per-card@@ -104,8 +108,9 @@ describe('MarketplaceView install flow', () => {});it('rolls back the optimistic install toggle when the API returns 500', async () => {- const fetchMock = vi.fn(async () =>- new Response(JSON.stringify({ detail: 'boom' }), { status: 500 }),+ const fetchMock = vi.fn(+ async (): Promise<Response> =>+ new Response(JSON.stringify({ detail: 'boom' }), { status: 500 }),);vi.stubGlobal('fetch', fetchMock);diff --git a/apps/web/src/components/sla/SLADashboard.tsx b/apps/web/src/components/sla/SLADashboard.tsxindex e66100f05..3d1997944 100644--- a/apps/web/src/components/sla/SLADashboard.tsx+++ b/apps/web/src/components/sla/SLADashboard.tsx@@ -17,6 +17,31 @@ interface SeverityMetrics {mttc_target: number | null;}+interface KpiBarPayload {+ targets: {+ false_positive_rate_max_pct: number;+ alert_to_incident_ratio_min: number;+ mitre_technique_tagging_min_pct: number;+ mitre_subtechnique_tagging_min_pct: number;+ };+ observed: {+ total_alerts: number;+ false_positives: number;+ false_positive_rate_pct: number;+ distinct_cases: number;+ alert_to_incident_ratio: number;+ mitre_technique_tagging_pct: number;+ mitre_subtechnique_tagging_pct: number;+ };+ breaches: {+ false_positive_rate: boolean;+ alert_to_incident_ratio: boolean;+ mitre_technique_tagging: boolean;+ mitre_subtechnique_tagging: boolean;+ };+ breach_count: number;+}+interface SLAMetrics {period_days: number;computed_at: string;@@ -29,6 +54,7 @@ interface SLAMetrics {mttc_avg: number | null;};per_severity: Record<string, SeverityMetrics>;+ kpi_bar: KpiBarPayload | null;}interface SLAConfig {@@ -142,9 +168,243 @@ function EditConfigModal({);}+type KpiBarTargets = KpiBarPayload['targets'];++function EditKpiBarModal({+ targets,+ onClose,+ onSaved,+}: {+ targets: KpiBarTargets;+ onClose: () => void;+ onSaved: () => void;+}) {+ const [fpMax, setFpMax] = useState(targets.false_positive_rate_max_pct);+ const [ratioMin, setRatioMin] = useState(targets.alert_to_incident_ratio_min);+ const [mitreMin, setMitreMin] = useState(targets.mitre_technique_tagging_min_pct);+ const [subMin, setSubMin] = useState(targets.mitre_subtechnique_tagging_min_pct);+ const [saving, setSaving] = useState(false);+ const [err, setErr] = useState<string | null>(null);++ const save = async () => {+ setErr(null);+ setSaving(true);+ try {+ const res = await fetch('/api/v1/sla/kpi-targets', {+ method: 'PUT',+ headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify({+ false_positive_rate_max_pct: fpMax,+ alert_to_incident_ratio_min: ratioMin,+ mitre_technique_tagging_min_pct: mitreMin,+ mitre_subtechnique_tagging_min_pct: subMin,+ }),+ });+ if (!res.ok) {+ const j = await res.json().catch(() => ({}));+ setErr((j as { detail?: string }).detail ?? `HTTP ${res.status}`);+ setSaving(false);+ return;+ }+ onSaved();+ onClose();+ } finally {+ setSaving(false);+ }+ };++ return (+ <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60">+ <div className="w-full max-w-md space-y-4 rounded-xl border border-gray-700 bg-gray-900 p-6">+ <h3 className="text-lg font-semibold text-white">2026 KPI bar targets</h3>+ <p className="text-xs text-gray-500">+ Published defaults apply until you override. Metrics use the same look-back as SLA metrics.+ </p>+ {[+ {+ label: 'False positive rate (max %)',+ val: fpMax,+ set: setFpMax,+ min: 0,+ max: 100,+ step: 0.5,+ },+ {+ label: 'Alert-to-incident ratio (min)',+ val: ratioMin,+ set: setRatioMin,+ min: 1,+ max: 500,+ step: 1,+ },+ {+ label: 'MITRE technique tagging (min %)',+ val: mitreMin,+ set: setMitreMin,+ min: 0,+ max: 100,+ step: 1,+ },+ {+ label: 'MITRE sub-technique tagging (min %)',+ val: subMin,+ set: setSubMin,+ min: 0,+ max: 100,+ step: 1,+ },+ ].map(({ label, val, set, min, max, step }) => (+ <div key={label}>+ <label className="mb-1 block text-xs text-gray-400">{label}</label>+ <input+ type="number"+ min={min}+ max={max}+ step={step}+ value={val}+ onChange={(e) => set(Number(e.target.value))}+ className="w-full rounded border border-gray-600 bg-gray-800 px-3 py-1.5 text-sm text-white"+ />+ </div>+ ))}+ {err && <p className="text-sm text-red-400">{err}</p>}+ <div className="flex gap-2 pt-2">+ <button+ type="button"+ onClick={save}+ disabled={saving}+ className="flex-1 rounded bg-blue-600 px-3 py-2 text-sm font-medium text-white hover:bg-blue-500 disabled:opacity-50"+ >+ {saving ? 'Saving…' : 'Save'}+ </button>+ <button+ type="button"+ onClick={onClose}+ className="flex-1 rounded bg-gray-700 px-3 py-2 text-sm text-white hover:bg-gray-600"+ >+ Cancel+ </button>+ </div>+ </div>+ </div>+ );+}++function KpiBarSection({+ kpi,+ days,+ onEditTargets,+}: {+ kpi: KpiBarPayload;+ days: number;+ onEditTargets: () => void;+}) {+ const { targets, observed, breaches, breach_count } = kpi;++ const rows: {+ key: string;+ label: string;+ observed: string;+ target: string;+ breach: boolean;+ }[] = [+ {+ key: 'fp',+ label: 'False positive rate',+ observed: `${observed.false_positive_rate_pct}% (${observed.false_positives} / ${observed.total_alerts})`,+ target: `≤ ${targets.false_positive_rate_max_pct}%`,+ breach: breaches.false_positive_rate,+ },+ {+ key: 'ratio',+ label: 'Alert-to-incident ratio',+ observed:+ observed.distinct_cases > 0+ ? `${observed.alert_to_incident_ratio}:1`+ : `${observed.total_alerts} alerts, no linked cases`,+ target: `≥ ${targets.alert_to_incident_ratio_min}:1 when cases exist`,+ breach: breaches.alert_to_incident_ratio,+ },+ {+ key: 'mitre',+ label: 'MITRE technique coverage',+ observed: `${observed.mitre_technique_tagging_pct}%`,+ target: `≥ ${targets.mitre_technique_tagging_min_pct}%`,+ breach: breaches.mitre_technique_tagging,+ },+ {+ key: 'sub',+ label: 'MITRE sub-technique coverage',+ observed: `${observed.mitre_subtechnique_tagging_pct}%`,+ target: `≥ ${targets.mitre_subtechnique_tagging_min_pct}%`,+ breach: breaches.mitre_subtechnique_tagging,+ },+ ];++ return (+ <div className="rounded-xl border border-violet-500/25 bg-violet-950/20 p-5">+ <div className="mb-4 flex flex-wrap items-center justify-between gap-2">+ <div>+ <h2 className="text-lg font-semibold text-white">2026 KPI bar</h2>+ <p className="text-xs text-gray-500">+ Operational quality vs tenant targets (last {days} days)+ </p>+ </div>+ <div className="flex items-center gap-3">+ <span+ className={+ breach_count > 0+ ? 'rounded-full border border-red-500/40 bg-red-500/10 px-3 py-1 text-xs font-medium text-red-300'+ : 'rounded-full border border-emerald-500/30 bg-emerald-500/10 px-3 py-1 text-xs font-medium text-emerald-300'+ }+ >+ {breach_count === 0 ? 'All KPIs met' : `${breach_count} breach${breach_count === 1 ? '' : 'es'}`}+ </span>+ <button+ type="button"+ onClick={onEditTargets}+ className="text-xs text-violet-300 hover:text-violet-200"+ >+ Edit targets+ </button>+ </div>+ </div>+ <div className="overflow-x-auto">+ <table className="w-full min-w-[520px] text-left text-sm">+ <thead>+ <tr className="border-b border-gray-700 text-gray-500">+ <th className="py-2 pr-4 font-medium">Metric</th>+ <th className="py-2 pr-4 font-medium">Observed</th>+ <th className="py-2 pr-4 font-medium">Target</th>+ <th className="py-2 font-medium">Status</th>+ </tr>+ </thead>+ <tbody>+ {rows.map((r) => (+ <tr key={r.key} className="border-b border-gray-800/80">+ <td className="py-2.5 pr-4 text-gray-200">{r.label}</td>+ <td className="py-2.5 pr-4 text-white">{r.observed}</td>+ <td className="py-2.5 pr-4 text-gray-400">{r.target}</td>+ <td className="py-2.5">+ {r.breach ? (+ <span className="text-red-400">Breach</span>+ ) : (+ <span className="text-emerald-400">OK</span>+ )}+ </td>+ </tr>+ ))}+ </tbody>+ </table>+ </div>+ </div>+ );+}+export function SLADashboard() {const [days, setDays] = useState(30);const [editConfig, setEditConfig] = useState<SLAConfig | null>(null);+ const [editKpiTargets, setEditKpiTargets] = useState<KpiBarTargets | null>(null);const { data: metrics, isLoading: metricsLoading } = useSWR<SLAMetrics>(`/api/v1/sla/metrics?days=${days}`,@@ -205,6 +465,14 @@ export function SLADashboard() {</div>)}+ {metrics?.kpi_bar && (+ <KpiBarSection+ kpi={metrics.kpi_bar}+ days={days}+ onEditTargets={() => setEditKpiTargets(metrics.kpi_bar!.targets)}+ />+ )}+{/* Per-severity breakdown */}{metricsLoading && (<p className="text-gray-400 text-sm">Loading metrics…</p>@@ -288,6 +556,17 @@ export function SLADashboard() {}}/>)}++ {editKpiTargets && (+ <EditKpiBarModal+ targets={editKpiTargets}+ onClose={() => setEditKpiTargets(null)}+ onSaved={() => {+ mutate('/api/v1/sla/kpi-targets');+ mutate(`/api/v1/sla/metrics?days=${days}`);+ }}+ />+ )}</div>);}diff --git a/apps/web/src/components/threat-intel/ThreatIntelView.tsx b/apps/web/src/components/threat-intel/ThreatIntelView.tsxindex 43620bbfc..52e71215d 100644--- a/apps/web/src/components/threat-intel/ThreatIntelView.tsx+++ b/apps/web/src/components/threat-intel/ThreatIntelView.tsx@@ -1,7 +1,12 @@'use client';import { useState } from 'react';-import { threatIntelApi, type ThreatIndicator } from '@/lib/api';+import {+ threatIntelApi,+ type AlertSeverity,+ type IndicatorType,+ type ThreatIndicator,+} from '@/lib/api';import { clsx } from 'clsx';import { format } from 'date-fns';@@ -79,7 +84,7 @@ const MOCK_INDICATORS: ThreatIndicator[] = [// ─── Type badges ──────────────────────────────────────────────────────────────-const TYPE_CONFIG: Record<string, { label: string; color: string }> = {+const TYPE_CONFIG: Record<IndicatorType, { label: string; color: string }> = {ip: { label: 'IP', color: 'text-purple-400 bg-purple-500/10 border-purple-500/20' },domain: { label: 'Domain', color: 'text-blue-400 bg-blue-500/10 border-blue-500/20' },hash: { label: 'Hash', color: 'text-yellow-400 bg-yellow-500/10 border-yellow-500/20' },@@ -87,11 +92,12 @@ const TYPE_CONFIG: Record<string, { label: string; color: string }> = {email: { label: 'Email', color: 'text-green-400 bg-green-500/10 border-green-500/20' },};-const SEVERITY_CONFIG = {+const SEVERITY_CONFIG: Record<AlertSeverity, string> = {critical: 'text-red-400 bg-red-500/10 border-red-500/20',high: 'text-orange-400 bg-orange-500/10 border-orange-500/20',medium: 'text-yellow-400 bg-yellow-500/10 border-yellow-500/20',low: 'text-blue-400 bg-blue-500/10 border-blue-500/20',+ info: 'text-slate-400 bg-slate-500/10 border-slate-500/20',};// ─── Lookup Form ──────────────────────────────────────────────────────────────@@ -151,9 +157,11 @@ function LookupForm() {<span className="text-red-400 font-medium text-sm">Malicious indicator</span><span className="text-xs text-gray-500">Confidence: {result.confidence}%</span></div>- <p className="text-xs text-gray-400">{result.description}</p>+ {result.description ? (+ <p className="text-xs text-gray-400">{result.description}</p>+ ) : null}<div className="flex flex-wrap gap-1">- {result.tags.map((t) => (+ {(result.tags ?? []).map((t) => (<span key={t} className="text-xs bg-gray-800 text-gray-400 px-1.5 py-0.5 rounded">{t}</span>))}</div>@@ -179,7 +187,7 @@ function IOCRow({ ioc }: { ioc: ThreatIndicator }) {<div className="flex-1 min-w-0"><p className="text-sm font-mono text-gray-300 truncate">{ioc.value}</p>- <p className="text-xs text-gray-600 mt-0.5 truncate">{ioc.description}</p>+ <p className="text-xs text-gray-600 mt-0.5 truncate">{ioc.description ?? ''}</p></div><span className={clsx('text-xs font-medium px-2 py-0.5 rounded border shrink-0', SEVERITY_CONFIG[ioc.severity])}>@@ -197,7 +205,9 @@ function IOCRow({ ioc }: { ioc: ThreatIndicator }) {</span></div><p className="text-xs text-gray-600 mt-0.5">- {format(new Date(ioc.lastSeen), 'MMM dd HH:mm')}+ {ioc.lastSeen || ioc.firstSeen+ ? format(new Date(ioc.lastSeen ?? ioc.firstSeen ?? 0), 'MMM dd HH:mm')+ : '—'}</p></div>@@ -220,8 +230,13 @@ export function ThreatIntelView() {const indicators = MOCK_INDICATORS.filter((ioc) => {if (typeFilter !== 'all' && ioc.type !== typeFilter) return false;- if (search && !ioc.value.toLowerCase().includes(search.toLowerCase()) &&- !ioc.description.toLowerCase().includes(search.toLowerCase())) return false;+ if (+ search &&+ !ioc.value.toLowerCase().includes(search.toLowerCase()) &&+ !(ioc.description ?? '').toLowerCase().includes(search.toLowerCase())+ ) {+ return false;+ }return true;});diff --git a/apps/web/src/cytoscape-fcose.d.ts b/apps/web/src/cytoscape-fcose.d.tsnew file mode 100644index 000000000..2250f5b89--- /dev/null+++ b/apps/web/src/cytoscape-fcose.d.ts@@ -0,0 +1,6 @@+declare module 'cytoscape-fcose' {+ import type cytoscape from 'cytoscape';++ const fcose: cytoscape.Ext;+ export default fcose;+}diff --git a/apps/web/src/lib/api.ts b/apps/web/src/lib/api.tsindex 1f9d4bdf9..7edd35e3e 100644--- a/apps/web/src/lib/api.ts+++ b/apps/web/src/lib/api.ts@@ -175,6 +175,16 @@ export interface AlertIOC {malicious?: boolean;}+export type ConfidenceLabel = 'high' | 'medium' | 'low';++export interface ConfidenceFactor {+ factor: string;+ label: string;+ value: number;+ contribution: number;+ weight: number;+}+export interface Alert {id: string;title: string;@@ -194,6 +204,10 @@ export interface Alert {createdAt: string;updatedAt: string;resolvedAt?: string;+ confidenceLabel?: ConfidenceLabel;+ confidenceScore?: number;+ confidenceRationale?: ConfidenceFactor[];+ ledgerRunId?: string;}export interface AlertsResponse {@@ -252,6 +266,122 @@ export const alertsApi = {}>(`/api/v1/alerts/${id}/timeline`),};+// ─── Risk-Based Alerting (entity rollup) ─────────────────────────────────────+//+// Wave 1 of the AiSOC v6 capability roadmap: alerts contribute time-decayed+// risk *points* onto the entities they touch (user / host / src_ip / domain).+// Once an entity crosses ``rba_promotion_threshold`` it becomes the primary+// unit of triage in the UI — so the analyst opens "the user fox.beach" with+// 47 contributing alerts attached, not 47 separate alert rows. The endpoints+// live on the fusion service (port 8082) and are proxied same-origin via+// next.config.js → ``/api/v1/fusion/*``.++export type EntityType = 'user' | 'host' | 'ip' | 'domain';++/** A single alert that contributed risk to an entity. */+export interface EntityRiskContribution {+ alert_id: string;+ severity: AlertSeverity;+ /** Points contributed *at the moment of observation* — not decayed. */+ raw_points: number;+ /** ISO-8601 timestamp the alert was observed. */+ observed_at: string;+ title?: string | null;+ source?: string | null;+}++/** A rolled-up entity with its current decayed risk score. */+export interface EntityRiskRecord {+ tenant_id: string;+ entity_type: EntityType;+ entity_value: string;+ /** Time-decayed score (0 → ∞ in theory, capped in practice by the engine). */+ score: number;+ /** Same as ``score`` rounded — convenience for the UI's badge. */+ display_score: number;+ /** Promotion threshold the engine was configured with at observation time. */+ threshold: number;+ /** True if ``score`` has crossed ``threshold`` at least once. */+ promoted: boolean;+ /** ID of the incident the entity was promoted into, if any. */+ promoted_incident_id?: string | null;+ /** ISO-8601 timestamp of the last contributing alert. */+ last_seen: string;+ /** ISO-8601 timestamp the entity first picked up any risk. */+ first_seen: string;+ /** Top contributing alerts, newest first, capped to ~25. */+ contributions: EntityRiskContribution[];+ /** Count by severity over the decay window — drives the queue badge. */+ severity_histogram: Record<AlertSeverity, number>;+ /** Convenience: total alert count in the decay window. */+ alert_count: number;+}++export interface EntityRiskQueueResponse {+ tenant_id: string;+ threshold: number;+ entities: EntityRiskRecord[];+}++export interface EntityRiskStats {+ tenant_id: string;+ /** Promotion threshold (mirrored from the engine). */+ threshold: number;+ /** Total active entities in the window. */+ total: number;+ /** Entities currently at or above ``threshold``. */+ promoted: number;+ /** Banded counts for the queue header chips. */+ bands: {+ critical: number;+ high: number;+ medium: number;+ low: number;+ };+ /** Total alerts contributing across all entities in the window. */+ alert_count: number;+ /** Convenience: alert-to-incident ratio observed in the current window. */+ alert_to_incident_ratio?: number | null;+}++/**+ * Path namespace served by the fusion service. Goes through Next.js+ * rewrites (`/api/v1/fusion/*` → ``${FUSION_HOST}/*``) so the bundle+ * stays same-origin.+ */+const FUSION_PATH = '/api/v1/fusion';++export const entityRiskApi = {+ /** Top-N entities by current decayed risk score. */+ queue: (params: {+ tenantId?: string;+ limit?: number;+ promotedOnly?: boolean;+ } = {}) =>+ request<EntityRiskQueueResponse>(`${FUSION_PATH}/entity-risk/queue`, {+ params: {+ tenant_id: params.tenantId ?? TENANT_ID,+ limit: params.limit ?? 25,+ promoted_only: params.promotedOnly ? 'true' : undefined,+ },+ }),++ /** Tenant-scoped queue stats for dashboards (banding, totals, threshold). */+ stats: (tenantId?: string) =>+ request<EntityRiskStats>(`${FUSION_PATH}/entity-risk/stats`, {+ params: { tenant_id: tenantId ?? TENANT_ID },+ }),++ /** Full risk record for a single entity (drawer detail). */+ get: (entityType: EntityType, entityValue: string, tenantId?: string) => {+ const pathType = entityType === 'ip' ? 'src_ip' : entityType;+ return request<EntityRiskRecord>(+ `${FUSION_PATH}/entity-risk/${pathType}/${encodeURIComponent(entityValue)}`,+ { params: { tenant_id: tenantId ?? TENANT_ID } },+ );+ },+};+// ─── Cases ───────────────────────────────────────────────────────────────────export type CaseStatus =@@ -1079,6 +1209,155 @@ export const detectionApi = {),};+// ─── Detection-as-code proposals (Wave 2 — w2-dac) ──────────────────────────+//+// Mirrors `services/api/app/api/v1/endpoints/detection_proposals.py`. Backed+// by `DetectionRuleProposal` + `DetectionEvalBaseline` tables. The eval+// verdict is computed server-side from a `scripts/run_evals.py` JSON report+// and the most recent active MITRE accuracy baseline; ≥ 1pp regression+// blocks approval / merge.++export type DetectionProposalStatus =+ | 'proposed'+ | 'in_review'+ | 'eval_passed'+ | 'eval_failed'+ | 'approved'+ | 'rejected'+ | 'promoted';++export interface DetectionProposalEvalVerdict {+ ran_at?: string;+ candidate?: { mitre_accuracy?: number; all_passed?: boolean };+ baseline?: { mitre_accuracy?: number };+ drop_pp?: number;+ max_regression_pp?: number;+ regressed?: boolean;+ passed?: boolean;+}++export interface DetectionProposal {+ id: string;+ tenant_id: string | null;+ base_rule_id: string | null;+ promoted_rule_id: string | null;+ name: string;+ description: string | null;+ rule_language: string;+ rule_body: string;+ category: string;+ severity: string;+ confidence: number;+ mitre_tactics: string[];+ mitre_techniques: string[];+ tags: string[];+ status: DetectionProposalStatus;+ eval_result: DetectionProposalEvalVerdict | Record<string, never>;+ review_comments: Array<{+ actor_id: string;+ actor_email?: string;+ comment: string;+ at: string;+ }>;+ proposed_by_id: string | null;+ decided_by_id: string | null;+ decision_comment: string | null;+ decided_at: string | null;+ created_at: string;+ updated_at: string;+}++export interface DetectionEvalBaseline {+ id: string;+ tenant_id: string | null;+ suite: string;+ score: number;+ payload: Record<string, unknown>;+ is_active: boolean;+ recorded_by_id: string | null;+ created_at: string;+}++export const detectionProposalsApi = {+ list: (params?: { status?: DetectionProposalStatus; limit?: number }) => {+ const qs = new URLSearchParams();+ if (params?.status) qs.set('status', params.status);+ if (params?.limit !== undefined) qs.set('limit', String(params.limit));+ const suffix = qs.toString() ? `?${qs.toString()}` : '';+ return request<DetectionProposal[]>(+ `/api/v1/detection-proposals${suffix}`,+ );+ },++ get: (id: string) =>+ request<DetectionProposal>(`/api/v1/detection-proposals/${id}`),++ create: (proposal: {+ name: string;+ description?: string | null;+ rule_language: string;+ rule_body: string;+ category: string;+ severity?: string;+ confidence?: number;+ mitre_tactics?: string[];+ mitre_techniques?: string[];+ tags?: string[];+ base_rule_id?: string | null;+ }) =>+ request<DetectionProposal>('/api/v1/detection-proposals', {+ method: 'POST',+ body: JSON.stringify(proposal),+ }),++ comment: (id: string, comment: string) =>+ request<DetectionProposal>(+ `/api/v1/detection-proposals/${id}/comment`,+ { method: 'POST', body: JSON.stringify({ comment }) },+ ),++ attachEval: (+ id: string,+ body: { eval_report: Record<string, unknown>; max_regression_pp?: number },+ ) =>+ request<DetectionProposal>(`/api/v1/detection-proposals/${id}/eval`, {+ method: 'POST',+ body: JSON.stringify(body),+ }),++ decide: (+ id: string,+ body: { decision: 'approve' | 'reject'; comment?: string | null },+ ) =>+ request<DetectionProposal>(`/api/v1/detection-proposals/${id}/decide`, {+ method: 'POST',+ body: JSON.stringify(body),+ }),++ promote: (id: string) =>+ request<DetectionProposal>(+ `/api/v1/detection-proposals/${id}/promote`,+ { method: 'POST' },+ ),++ listBaselines: (suite?: string) => {+ const suffix = suite ? `?suite=${encodeURIComponent(suite)}` : '';+ return request<DetectionEvalBaseline[]>(+ `/api/v1/detection-proposals/baselines${suffix}`,+ );+ },++ recordBaseline: (body: {+ suite: string;+ score: number;+ payload?: Record<string, unknown>;+ }) =>+ request<DetectionEvalBaseline>(+ '/api/v1/detection-proposals/baselines',+ { method: 'POST', body: JSON.stringify(body) },+ ),+};+// ─── AI Copilot ──────────────────────────────────────────────────────────────export type CopilotRole = 'user' | 'assistant' | 'system';@@ -1565,6 +1844,7 @@ export const realtimeApi = {export default {alerts: alertsApi,+ entityRisk: entityRiskApi,cases: casesApi,metrics: metricsApi,connectors: connectorsApi,@@ -1573,6 +1853,7 @@ export default {hunt: huntApi,graph: graphApi,detection: detectionApi,+ detectionProposals: detectionProposalsApi,copilot: copilotApi,contextual: contextualApi,ledger: ledgerApi,diff --git a/apps/web/src/lib/pwa.ts b/apps/web/src/lib/pwa.tsindex 66d9994b7..1a6531f18 100644--- a/apps/web/src/lib/pwa.ts+++ b/apps/web/src/lib/pwa.ts@@ -144,7 +144,7 @@ export async function subscribeToPush(const sub = await reg.pushManager.subscribe({userVisibleOnly: true,- applicationServerKey: urlBase64ToUint8Array(public_key),+ applicationServerKey: urlBase64ToUint8Array(public_key) as BufferSource,});await registerSubscriptionWithGateway(sub, options.topics);diff --git a/apps/web/src/lib/responder/webauthn.ts b/apps/web/src/lib/responder/webauthn.tsindex 03df12840..99faccb48 100644--- a/apps/web/src/lib/responder/webauthn.ts+++ b/apps/web/src/lib/responder/webauthn.ts@@ -133,12 +133,16 @@ export async function createPasskey(id: cred.id,rawId: bytesToB64url(cred.rawId),type: 'public-key',- authenticatorAttachment: cred.authenticatorAttachment ?? null,+ authenticatorAttachment: (cred.authenticatorAttachment ?? null) as+ | AuthenticatorAttachment+ | null,response: {attestationObject: bytesToB64url(att.attestationObject),clientDataJSON: bytesToB64url(att.clientDataJSON),transports:- typeof att.getTransports === 'function' ? att.getTransports() : [],+ typeof att.getTransports === 'function'+ ? (att.getTransports() as AuthenticatorTransport[])+ : [],},};}@@ -164,7 +168,9 @@ export async function getPasskey(id: cred.id,rawId: bytesToB64url(cred.rawId),type: 'public-key',- authenticatorAttachment: cred.authenticatorAttachment ?? null,+ authenticatorAttachment: (cred.authenticatorAttachment ?? null) as+ | AuthenticatorAttachment+ | null,response: {authenticatorData: bytesToB64url(ass.authenticatorData),clientDataJSON: bytesToB64url(ass.clientDataJSON),diff --git a/apps/web/src/lib/site.ts b/apps/web/src/lib/site.tsnew file mode 100644index 000000000..8b1d82d52--- /dev/null+++ b/apps/web/src/lib/site.ts@@ -0,0 +1,137 @@+/**+ * Canonical public URL for SEO, Open Graph, and sitemap.+ * Set NEXT_PUBLIC_SITE_URL at build/deploy (e.g. https://tryaisoc.com for the live demo).+ */+export function getPublicSiteUrl(): string {+ const raw = process.env.NEXT_PUBLIC_SITE_URL?.trim();+ if (raw) {+ return raw.replace(/\/$/, "");+ }+ return "https://tryaisoc.com";+}++/** Meta keywords for cyber/SOC discovery (tryaisoc.com demo + self-host). */+export const DISCOVERY_KEYWORDS: readonly string[] = [+ // Brand+ "AiSOC",+ "AI SOC",+ "tryaisoc",+ "tryaisoc.com",+ // Core value prop+ "open source SOC",+ "open-source security operations center",+ "self-hosted SOC",+ "free SOC platform",+ "MIT license",+ "SIEM alternative",+ "open source SIEM",+ // Platform capabilities+ "security operations",+ "SOC platform",+ "SOC automation",+ "threat detection",+ "alert triage",+ "alert fusion",+ "alert deduplication",+ "noise reduction",+ "incident response",+ "security automation",+ "SOAR",+ "security orchestration",+ "security operations automation",+ // AI / agentic+ "AI security",+ "AI-powered SOC",+ "security AI",+ "agentic SOC",+ "LLM security",+ "security copilot",+ "generative AI security",+ "LLM threat detection",+ "LangGraph",+ "MCP security",+ "AI agent security",+ "autonomous SOC",+ "GPT security",+ // Detection & hunting+ "detection engineering",+ "detection-as-code",+ "MITRE ATT&CK",+ "Sigma rules",+ "YARA rules",+ "threat hunting",+ "detection validation",+ "eval-driven security",+ "rule validation",+ "ATT&CK mapping",+ // Team concepts+ "purple team",+ "blue team",+ "red team",+ "SOC analyst",+ "security analyst",+ "tier-1 automation",+ "L1 automation",+ // Standards & frameworks+ "SIEM",+ "XDR",+ "EDR",+ "NDR",+ "cloud SIEM",+ "cloud security",+ "cloud security posture",+ "CSPM",+ "UEBA",+ "identity security",+ "zero trust",+ "insider threat",+ "behavioral analytics",+ // Threat intel+ "threat intelligence",+ "CTI",+ "TAXII",+ "MISP",+ "STIX",+ "IOC",+ "indicator of compromise",+ "threat feed",+ // Compliance & reporting+ "SOC 2",+ "compliance monitoring",+ "audit logging",+ "security reporting",+ "MSSP",+ "managed security",+ // DFIR+ "DFIR",+ "digital forensics",+ "incident investigation",+ "forensic timeline",+ "root cause analysis",+ // Integrations+ "Microsoft Sentinel",+ "CrowdStrike",+ "Splunk",+ "Elastic Security",+ "Defender XDR",+ "AWS Security Hub",+ "Google Chronicle",+ "Okta SIEM",+ // Tech stack (devs searching)+ "FastAPI SOC",+ "NextJS security",+ "Python security",+ "Docker security",+ "Kubernetes security",+ "LangGraph security",+ // Community+ "cybersecurity",+ "infosec",+ "DevSecOps",+ "security monitoring",+ "log correlation",+ "security analytics",+ "open security",+ "cybersecurity open source",+ "security community",+];diff --git a/hunts/README.md b/hunts/README.mdnew file mode 100644index 000000000..a0cf6e6d3--- /dev/null+++ b/hunts/README.md@@ -0,0 +1,96 @@+# AiSOC hunts/ — hunt-as-code corpus++This directory holds AiSOC's hunt hypotheses as YAML. Each file describes a+single threat hypothesis the agent layer can run on a schedule, scoring the+target telemetry corpus against a set of expected indicators.++The corpus is part of the same **eval-graded** pipeline as detections and+prompts: every hunt ships with a synthetic positive scenario in+`services/agents/tests/eval_data/synthetic_telemetry.jsonl` and is scored by+`scripts/run_hunt_evals.py` (or as part of `scripts/run_evals.py` when run in+`--all` mode).++## Schema++```yaml+id: hunt-<slug> # stable identifier, must be unique+name: Human readable name+description: |+ One-paragraph description of the hypothesis the hunt is testing.+version: 1.0.0+severity: low | medium | high | critical+category: identity | endpoint | cloud | network | data-exfil | application+tags:+ - mitre.attack.t1078 # MITRE technique IDs welcome+ - threat.<actor> # optional threat actor hint+log_sources: # what telemetry the hunt expects+ - sysmon+ - m365_audit+ - linux_auditd+schedule:+ enabled: true+ interval_minutes: 60 # how often the scheduler should run this+ jitter_seconds: 60 # randomized jitter to avoid herd+hypothesis:+ question: |+ "Did any service account log into a workstation outside business hours+ and immediately enumerate domain groups?"+ indicators:+ - field: source+ equals: windows_security+ - field: EventID+ in: [4624, 4625]+ - field: TargetUserName+ regex: "^svc-.*"+expected:+ # synthetic positive scenario for eval grading+ positive_incident_id: INC-HUNT-001+ positive_template_id: hunt-svc-account-after-hours+ # at least this fraction of indicators must match for the hunt to fire+ min_match_score: 0.8+ # synthetic negative scenario id (a benign event sequence the hunt must NOT fire on)+ negative_incident_id: INC-HUNT-001-NEG+references:+ - https://attack.mitre.org/techniques/T1078/+author: AiSOC+created: '2026-05-05'+modified: '2026-05-05'+```++## Eval grading++Each hunt is scored on:++1. **True positive rate** — does the hunt fire on `expected.positive_incident_id`?+2. **False positive rate** — does the hunt *not* fire on `expected.negative_incident_id`?+3. **Indicator quality** — fraction of declared indicators that actually match+ the synthetic events (the substrate self-consistency check, like the rest+ of the eval harness).++The aggregate "Hunt Coverage" score is the macro-average of true positive rate+across all enabled hunts. CI gates regression by ≥ 1pp, identical to the+detection-as-code gate.++## How the scheduler runs++`services/agents` runs an APScheduler `AsyncIOScheduler` job per enabled hunt.+On each fire the hunt agent:++1. Loads the hunt YAML from disk.+2. Queries the telemetry warehouse (or the synthetic corpus in dev) for events+ matching `hypothesis.indicators`.+3. If `min_match_score` is reached, persists a **hunt finding** as a first-class+ artifact alongside the Investigation Ledger (table `hunt_findings`).+4. Writes a run record to `hunt_runs` regardless of whether the hunt fired.++## Adding a hunt++1. Drop a new YAML into `hunts/`.+2. Add at least one synthetic positive scenario to+ `services/agents/tests/eval_data/synthetic_telemetry.jsonl` with the matching+ `incident_id` and `template_id`.+3. Add a synthetic negative scenario (benign events that match *some* but not+ all indicators).+4. Run `python scripts/run_hunt_evals.py` locally to confirm the hunt scores+ 100% true-positive and 0% false-positive.+5. Open a PR — CI will re-run the hunt evals and gate on regression.diff --git a/hunts/cloud-iam-role-anomalous-assume.yaml b/hunts/cloud-iam-role-anomalous-assume.yamlnew file mode 100644index 000000000..582fe72e3--- /dev/null+++ b/hunts/cloud-iam-role-anomalous-assume.yaml@@ -0,0 +1,49 @@+id: hunt-cloud-iam-role-anomalous-assume+name: Cross-account IAM role assume from a never-before-seen principal+description: |+ AWS sts:AssumeRole or GCP iam.serviceAccounts.getAccessToken from an external+ account or principal that has not previously assumed the role, especially+ when followed by privileged read/list calls in the assumed role's session,+ is a strong indicator of cloud lateral movement (e.g. SCATTERED SPIDER,+ LUCR-3 / Storm-0875).+version: 1.0.0+severity: high+category: cloud+tags:+ - mitre.attack.t1078.004+ - mitre.attack.t1098.001+ - hunt.cloud+ - threat.cloud-lateral+log_sources:+ - cloudtrail+ - gcp_audit+schedule:+ enabled: true+ interval_minutes: 30+ jitter_seconds: 30+hypothesis:+ question: |+ Did sts:AssumeRole (AWS) or iam.serviceAccounts.getAccessToken (GCP)+ succeed from a sourceIPAddress or principal not seen against this role+ in the last 30 days, followed within 5 minutes by privileged List* /+ Get* / Describe* calls?+ indicators:+ - field: source+ in: [cloudtrail, gcp_audit]+ - field: eventName+ in: [AssumeRole, GenerateAccessToken]+ - field: principal_first_seen_against_role+ equals: true+ - field: privileged_calls_within_5min+ gte: 3+expected:+ positive_incident_id: INC-HUNT-004+ positive_template_id: hunt-cloud-iam-role-anomalous-assume+ min_match_score: 0.75+ negative_incident_id: INC-HUNT-004-NEG+references:+ - https://attack.mitre.org/techniques/T1078/004/+ - https://attack.mitre.org/techniques/T1098/001/+author: AiSOC+created: '2026-05-05'+modified: '2026-05-05'diff --git a/hunts/dns-tunneling-large-txt.yaml b/hunts/dns-tunneling-large-txt.yamlnew file mode 100644index 000000000..2eb23d535--- /dev/null+++ b/hunts/dns-tunneling-large-txt.yaml@@ -0,0 +1,47 @@+id: hunt-dns-tunneling-large-txt+name: DNS tunneling via oversized TXT queries+description: |+ Adversaries exfiltrate data and run C2 over DNS by abusing oversized TXT or+ NULL records. This hunt looks for DNS query/response pairs where the+ query name is unusually long (>= 100 chars) or the answer payload contains+ hex/base64-encoded chunks. Triggers when a single host emits more than 50+ such queries in an hour.+version: 1.0.0+severity: high+category: network+tags:+ - mitre.attack.t1071.004+ - mitre.attack.t1572+ - hunt.network+ - threat.c2+log_sources:+ - dns+schedule:+ enabled: true+ interval_minutes: 60+ jitter_seconds: 90+hypothesis:+ question: |+ Did a single source host send more than 50 DNS queries in an hour where+ the query name length exceeds 100 characters or the response is a TXT+ record carrying base64/hex-encoded payload?+ indicators:+ - field: source+ equals: dns+ - field: query_type+ in: [TXT, NULL]+ - field: query_length+ gte: 100+ - field: queries_per_hour+ gte: 50+expected:+ positive_incident_id: INC-HUNT-002+ positive_template_id: hunt-dns-tunneling-large-txt+ min_match_score: 0.75+ negative_incident_id: INC-HUNT-002-NEG+references:+ - https://attack.mitre.org/techniques/T1071/004/+ - https://attack.mitre.org/techniques/T1572/+author: AiSOC+created: '2026-05-05'+modified: '2026-05-05'diff --git a/hunts/lolbin-rundll32-network.yaml b/hunts/lolbin-rundll32-network.yamlnew file mode 100644index 000000000..ac15f6914--- /dev/null+++ b/hunts/lolbin-rundll32-network.yaml@@ -0,0 +1,46 @@+id: hunt-lolbin-rundll32-network+name: rundll32.exe making outbound network connections+description: |+ rundll32.exe is a signed Windows binary frequently abused by adversaries to+ proxy execution of malicious DLLs. Legitimate rundll32 invocations almost+ never make outbound network connections to non-Microsoft IPs; when they do,+ it is a high-fidelity signal of LOLBin abuse (Cobalt Strike, IcedID, Qakbot).+version: 1.0.0+severity: high+category: endpoint+tags:+ - mitre.attack.t1218.011+ - hunt.endpoint+ - threat.lolbin+log_sources:+ - sysmon+schedule:+ enabled: true+ interval_minutes: 30+ jitter_seconds: 30+hypothesis:+ question: |+ Did rundll32.exe (Sysmon EventID 3 — Network connection) initiate an+ outbound connection to a non-RFC1918, non-Microsoft destination?+ indicators:+ - field: source+ equals: sysmon+ - field: EventID+ equals: 3+ - field: Image+ iendswith: "\\rundll32.exe"+ - field: DestinationIp_is_public+ equals: true+ - field: DestinationIp_is_microsoft+ equals: false+expected:+ positive_incident_id: INC-HUNT-005+ positive_template_id: hunt-lolbin-rundll32-network+ min_match_score: 0.85+ negative_incident_id: INC-HUNT-005-NEG+references:+ - https://attack.mitre.org/techniques/T1218/011/+ - https://lolbas-project.github.io/lolbas/Binaries/Rundll32/+author: AiSOC+created: '2026-05-05'+modified: '2026-05-05'diff --git a/hunts/oauth-app-mass-consent.yaml b/hunts/oauth-app-mass-consent.yamlnew file mode 100644index 000000000..fd3960e35--- /dev/null+++ b/hunts/oauth-app-mass-consent.yaml@@ -0,0 +1,47 @@+id: hunt-oauth-app-mass-consent+name: OAuth application mass-consent across users+description: |+ Consent phishing relies on tricking individual users into granting an+ attacker-controlled OAuth app broad mailbox/Drive scopes. When a single new+ ApplicationId is consented to by 5+ users in a 24h window — especially with+ Mail.Read, Files.Read.All, or offline_access — that pattern is almost always+ malicious unless coordinated by IT.+version: 1.0.0+severity: high+category: identity+tags:+ - mitre.attack.t1528+ - hunt.identity+ - threat.consent-phishing+log_sources:+ - m365_audit+schedule:+ enabled: true+ interval_minutes: 360+ jitter_seconds: 120+hypothesis:+ question: |+ Did the same new ApplicationId receive consent from 5 or more distinct+ users in 24 hours, where the consented scopes include Mail.Read,+ Files.Read.All, or offline_access?+ indicators:+ - field: source+ equals: m365_audit+ - field: Workload+ equals: AzureActiveDirectory+ - field: Operation+ equals: "Consent to application."+ - field: ConsentedScopes+ contains_any: ["Mail.Read", "Files.Read.All", "offline_access"]+ - field: distinct_users_per_app_24h+ gte: 5+expected:+ positive_incident_id: INC-HUNT-003+ positive_template_id: hunt-oauth-app-mass-consent+ min_match_score: 0.8+ negative_incident_id: INC-HUNT-003-NEG+references:+ - https://attack.mitre.org/techniques/T1528/+author: AiSOC+created: '2026-05-05'+modified: '2026-05-05'diff --git a/hunts/svc-account-after-hours.yaml b/hunts/svc-account-after-hours.yamlnew file mode 100644index 000000000..cfd029b44--- /dev/null+++ b/hunts/svc-account-after-hours.yaml@@ -0,0 +1,46 @@+id: hunt-svc-account-after-hours+name: Service account interactive logon outside business hours+description: |+ Service accounts (svc-*) should authenticate non-interactively. An interactive+ logon by a svc-* account, especially outside business hours, is a strong+ indicator of credential theft or insider abuse. This hunt looks for+ Windows Security 4624 (logon success) where TargetUserName matches ^svc-.*$+ and LogonType is 2 (Interactive) or 10 (RemoteInteractive).+version: 1.0.0+severity: high+category: identity+tags:+ - mitre.attack.t1078.002+ - mitre.attack.t1078.003+ - hunt.identity+ - threat.insider+log_sources:+ - windows_security+schedule:+ enabled: true+ interval_minutes: 60+ jitter_seconds: 60+hypothesis:+ question: |+ Did any svc-* service account perform an interactive (LogonType 2/10)+ logon, especially outside 08:00–18:00 local time?+ indicators:+ - field: source+ equals: windows_security+ - field: EventID+ in: [4624]+ - field: TargetUserName+ regex: "^svc-.*"+ - field: LogonType+ in: [2, 10]+expected:+ positive_incident_id: INC-HUNT-001+ positive_template_id: hunt-svc-account-after-hours+ min_match_score: 0.8+ negative_incident_id: INC-HUNT-001-NEG+references:+ - https://attack.mitre.org/techniques/T1078/002/+ - https://attack.mitre.org/techniques/T1078/003/+author: AiSOC+created: '2026-05-05'+modified: '2026-05-05'diff --git a/scripts/generate_adversary_incidents.py b/scripts/generate_adversary_incidents.pynew file mode 100644index 000000000..769d07dfd--- /dev/null+++ b/scripts/generate_adversary_incidents.py@@ -0,0 +1,614 @@+#!/usr/bin/env python3+"""+AiSOC AI-vs-AI adversary scenario generator (Wave 2 — w2-aivai).+=================================================================++Takes the deterministic 200-incident benchmark and produces a parallel+"adversary-mutated" dataset that simulates what an attacker-LLM would do+to evade a keyword/regex-based defender: synonym substitution, character+obfuscation, fragmentation, and softening of tactic-betraying language.++The mutator is INTENTIONALLY DETERMINISTIC. We don't want to ship a flaky+CI suite that depends on a live model — so the "attacker LLM" is replaced+with a content-derived hash + a curated mutation grammar. The grammar is+built directly from the defender's `_TACTIC_KEYWORDS` dictionary in+`services/agents/tests/test_mitre_accuracy.py`, so every keyword the+defender knows about gets at least one evasive alternate.++Mutation intensity per incident is bucketed by `sha256(id)`:++ heavy ≈ 45% — every keyword in title+description rewritten+ medium ≈ 35% — only one of the expected tactics is preserved cleanly+ light ≈ 20% — light leetspeak only; defender should still catch++Targeted floor for the resulting eval suite is ~0.55, demonstrating+graceful degradation under adversarial obfuscation rather than the 0.80+defender-friendly floor of `test_mitre_accuracy.py`.++Outputs `services/agents/tests/eval_data/adversary_incidents.json`. Re-runs+are byte-identical given the same input dataset and mutation grammar.++Usage:+ python3 scripts/generate_adversary_incidents.py+ python3 scripts/generate_adversary_incidents.py --report+ python3 scripts/generate_adversary_incidents.py --out PATH+"""+from __future__ import annotations++import argparse+import hashlib+import json+import re+import sys+from pathlib import Path+from typing import Any++_REPO_ROOT = Path(__file__).resolve().parent.parent+_AGENTS_ROOT = _REPO_ROOT / "services" / "agents"+sys.path.insert(0, str(_AGENTS_ROOT))++# Pull the defender's keyword catalogue directly so we never drift from it.+from tests.test_mitre_accuracy import ( # type: ignore # noqa: E402+ _TACTIC_KEYWORDS,+ extract_tactics_from_text,+)++_DEFAULT_INPUT = _AGENTS_ROOT / "tests" / "eval_data" / "synthetic_incidents.json"+_DEFAULT_OUTPUT = _AGENTS_ROOT / "tests" / "eval_data" / "adversary_incidents.json"+++# ---------------------------------------------------------------------------+# Mutation grammar+#+# Each entry rewrites the substring on the LEFT to one of the alternates on+# the right. Alternates are intentionally chosen so they do NOT match any+# keyword in `_TACTIC_KEYWORDS` (substring-checked at module load time+# below — `_validate_grammar()` will fail loudly if a synonym would still+# trip a defender keyword for any tactic).+#+# Substring keys are matched case-insensitively. Multi-word keys are+# preserved literally; single-word keys use word-boundary matching so e.g.+# "macro" doesn't replace "macroeconomics" (not that it appears here, but+# the principle is sound).+# ---------------------------------------------------------------------------+++# Each value is a deterministic alternate the attacker might use. Picked by+# `(incident_id, keyword)` hash so a single incident is internally consistent+# but the dataset as a whole exercises the grammar broadly.+_SYNONYMS: dict[str, tuple[str, ...]] = {+ # TA0001 — Initial Access+ "initial access": ("first foothold", "entry stage", "ingress beachhead"),+ "phishing": ("ruse mail", "deceptive lure", "ph1sh1ng", "fraudulent outreach"),+ "spear-phish": ("targeted lure", "directed bait", "narrow-cast bait"),+ "spear": ("focused lure", "direct lure", "targeted bait"),+ "watering hole": ("co-opted landing site", "doctored portal", "ambush page"),+ "supply chain": ("vendor-pipeline trojan", "build-pipeline poisoning", "third-party-build poisoning"),+ "valid account": ("legitimate-id reuse", "trusted identity reuse", "clean-id reuse"),+ "external remote service": ("internet-reachable gateway", "outward-facing edge daemon", "edge-facing remote daemon"),+ "drive-by": ("auto-load infection", "passive-landing infection", "no-click landing"),+ "usb": ("rem0vable media", "thumb-stick vector", "portable storage stick"),+ "oauth consent": ("3rd-party-app grant", "delegated-grant abuse", "tenant grant abuse"),+ "social engineering": ("operator deception", "human-factor pretexting", "operator manipulation"),+ "social-engineering": ("operator deception", "human-factor pretexting", "operator manipulation"),+ "vpn login": ("corp tunnel sign-in", "remote-access portal entry", "tunnelled sign-in"),+ "new geography": ("unseen origin region", "anomalous origin", "first-time origin"),+ "compromised npm": ("trojanized js-libs release", "doctored js-libs build", "polluted js-libs feed"),+ "container image": ("workload bundle", "runtime workload artifact", "compute workload bundle"),+ "wire transfer": ("ach instruction", "outgoing remittance", "treasury debit instruction"),++ # TA0002 — Execution+ "execution": ("payload delivery step", "binary launch", "code activation"),+ "powershell": ("p0wer$hell", "p\u200bow\u200bersh\u200bell", "PoSh"),+ "cmd.exe": ("command interpreter binary", "cm\u200bd.exe", "shell-host.exe"),+ "script": ("scr1pt", "automation snippet", "in-line code blob"),+ "macro": ("m@cro", "off1ce-automation routine", "embedded automation routine"),+ "python": ("p\u200bython", "py interpreter", "py-runtime"),+ "node": ("n0de runtime", "n\u200bode.js", "j$-runtime daemon"),+ "certutil": ("cert\u200butil", "windows cert tool", "cert-handling lolbin"),+ "wmi": ("management infra channel", "WM\u200bI", "windows-mgmt-fabric"),+ "wmic": ("wm\u200bic", "mgmt-fabric cli", "windows-mgmt-cli"),+ "mshta": ("ms\u200bhta", "mshta lolbin alt", "trusted-host runner"),+ "process hollow": ("memory-cavity injection", "image substitution into target proc", "in-place process swap"),+ "process create": ("spawn syscall", "child-proc launch", "new-proc materialization"),+ "npm": ("n\u200bpm", "j$-pkg manager", "js dependency manager"),+ "post-install": ("install-time hook", "hook stage after pkg add", "pkg-install hook"),+ "container with": ("workload containing", "image carrying", "bundle containing"),+ "docker run": ("orchestrator launch", "runc launch", "containerd run-cmd"),+ "javascript": ("j$ runtime payload", "es-module payload", "browser-side code"),+ "stage-2 payload": ("second-tier dropper", "follow-on artifact", "next-tier blob"),+ "vba": ("v\u200bba", "off1ce-automation language", "doc-embedded autom"),+ "browser exploitation": ("client-side rendering abuse", "html-engine abuse", "DOM-engine abuse"),++ # TA0003 — Persistence+ "persistence": ("re-establish footing", "reboot survival", "long-term foothold"),+ "registry run": ("hkcu autostart key", "winreg autorun stanza", "reg-autostart entry"),+ "scheduled task": ("schtasks job", "taskscheduler entry", "win-periodic job"),+ "startup": ("st@rtup", "boot-time launch slot", "boot autoload"),+ "service": ("d@emon entry", "long-running unit", "background unit"),+ "implant": ("imp1ant", "long-residence agent", "resident dropper"),+ "backdoor": ("b@ckdoor", "covert callback link", "covert reverse access"),+ "rootkit": ("r00tkit", "kernel-resident hider", "stealth kernel module"),+ "firmware": ("f1rmware", "low-level board code", "below-os layer"),+ "uefi": ("ue\u200bfi", "early-boot f1rmware", "platform pre-boot f1rmware"),+ "cron": ("cr0n", "unix periodic job", "unix sched entry"),+ "wmi event": ("wm\u200bi event", "mgmt-fabric stream", "management-event stream"),+ "permanent wmi": ("perm wm\u200bi", "always-on mgmt stream", "indefinite mgmt stream"),+ "office add-in": ("off1ce plugin slot", "productivity-suite extension", "doc-suite extension"),+ "vsto": ("vs\u200bto", "off1ce add-in tooling", "off1ce plugin tooling"),+ "outlook startup": ("mailer load-time slot", "messaging-app boot slot", "mail-client boot slot"),++ # TA0004 — Privilege Escalation+ "privilege escalation": ("rights step-up", "rights uplift", "level-up of identity"),+ "escalation": ("rights step-up", "level-up", "rights uplift"),+ "escalate": ("step up rights", "gain higher rights", "uplift rights"),+ "container escape": ("workload sandbox break", "namespace breakout", "isolation-layer break"),+ "privileged pod": ("p0werful pod", "host-shared workload", "high-cap pod"),+ "bypass": ("circumvent", "go around", "side-step"),+ "elevation": ("rights step-up", "rights uplift", "perm step-up"),+ "sudo": ("su\u200bdo", "root-shim", "uplifted-shim"),+ "uac bypass": ("ua\u200bc circumvention", "consent-prompt sidestep", "security-prompt sidestep"),+ "uac": ("ua\u200bc", "consent prompt", "security prompt"),+ "fodhelper": ("f0dhelper", "trusted helper binary", "feature-on-demand helper"),+ "suid": ("su\u200bid", "setuser bit", "setid-perm bit"),+ "metadata service": ("im\u200bds endpoint", "m\u200betadata svc", "instance-info endpoint"),++ # TA0005 — Defense Evasion+ "defense evasion": ("av-d0dging", "control-skirting", "telemetry-d0dging"),+ "obfuscat": ("scr@mbl", "deob h@rd'n", "morph"),+ "fileless": ("on-disk-less", "no-disk-write", "ram-resident-only"),+ "memory-only": ("ram-resident", "in-mem-only", "no on-disk artifact"),+ "memory only": ("ram resident", "in mem only", "no on-disk artifact"),+ "hollowing": ("h0llowing", "memory-cavity swap", "in-place image swap"),+ "side-load": ("s1de-load", "hijack legit-binary lookup chain", "search-order load t@mpering"),+ "dll": ("d\u200bll", "dynamic library", "loadable code module"),+ "masquerad": ("disguis", "imitat", "sp00f"),+ "encode": ("base64-wrap", "byte-wrap", "transform"),+ "pack": ("p@ck", "c0mpress", "wr@p"),+ "log cleared": ("logs purged", "audit history erased", "telemetry erased"),+ "wevtutil": ("we\u200bvtutil", "win event tool", "win-log cli"),+ "journalctl": ("j0urnalctl", "systemd journal cli", "systemd log cli"),+ "vacuum": ("v@cuum", "c0mpact db", "c0mpress-truncate"),+ "indicator removal": ("evidence cleanup", "trace cleanup", "footprint cleanup"),+ "tampering": ("altering", "modify-on-the-fly", "d0ctoring"),+ "stop defender": ("disable mde-agent", "halt windows av", "kill av-agent"),+ "stop crowdstrike": ("disable cs-falcon", "halt edr-agent", "kill edr-sensor"),+ "stop sysmon": ("disable sysmon-agent", "halt sysmon-collector", "kill sysmon-svc"),+ "secure boot": ("s\u200becure boot", "verified boot chain", "boot integrity"),++ # TA0006 — Credential Access+ "credential": ("cred", "auth-token", "login secret"),+ "brute force": ("repeated guess", "iterative login attempt", "dictionary attack"),+ "brute-force": ("repeated-guess", "iterative-login", "dict-attempt"),+ "kerberoast": ("kerb-ticket abuse", "kerb-ticket roast", "kerb-ticket grind"),+ "dcsync": ("dc-replica-pull abuse", "directory replica abuse", "msrpc replica-pull abuse"),+ "lsass": ("l$ass", "auth subsystem proc", "session-mgmt proc"),+ "minidump": ("mini-d\u200bump", "process snapshot", "proc-snapshot"),+ "dump": ("d\u200bump", "snapshot of proc memory", "proc-mem snapshot"),+ "harvest": ("scrap", "skim", "lift"),+ "password reset": ("pw rotation request", "self-serve cred change", "cred rotation request"),+ "password spray": ("low-and-slow login attempt", "quiet cred probe", "spread-out login attempts"),+ "credential spray": ("cred low-and-slow", "auth-token probe spread", "spread-out cred probe"),+ "saml": ("s@ml", "federation token", "fed-assertion"),+ "oauth": ("0auth", "tenant grant", "delegated grant"),+ "ntlm": ("n\u200btlm", "ms-auth legacy", "challenge-response auth"),+ "mimikatz": ("m1m1katz", "secrets extractor", "auth-secrets puller"),+ "pat": ("p@t", "github-token", "ci-token"),+ "personal access token": ("dev-portal token", "self-issued bearer token", "user-issued api token"),+ "refresh token": ("re-fresh tok\u200ben", "long-lived auth handle", "session-extension token"),+ "imds": ("im\u200bds", "instance metadata svc", "instance-info endpoint"),+ "session token": ("ses\u200bsion token", "auth-cookie", "bearer for active session"),+ "stolen session": ("hijacked sess1on", "co-opted active sess", "session-takeover"),+ "tgs": ("tg\u200bs", "kerb svc ticket", "svc-ticket"),++ # TA0007 — Discovery+ "discovery": ("scout-stage", "look-around stage", "environment-mapping"),+ "enumerat": ("listing-out", "walking the directory", "iterating across"),+ "scan": ("sweep", "probe-pass", "fingerprint-pass"),+ "account discovery": ("user-listing", "principal-listing", "identity-listing"),+ "network share": ("smb mount", "remote folder", "fileshare mount"),+ "recon": ("rec0n", "look-around stage", "environment-mapping"),+ "replication": ("dir-sync abuse", "ad-sync abuse", "directory replica use"),+ "ldap": ("l\u200bdap", "directory protocol", "x.500 query"),+ "bloodhound": ("bl0odhound", "ad-graph mapper", "ad-relationship mapper"),+ "smb share": ("smb mount", "remote folder mount", "fileshare mount"),+ "share enum": ("mount listing", "fileshare listing", "smb-volume listing"),+ "system info": ("host fingerprinting", "host-detail pull", "machine-detail pull"),++ # TA0008 — Lateral Movement+ "lateral movement": ("east-west pivot", "horizontal hop", "side-to-side traversal"),+ "lateral": ("e-w hop", "horizontal", "side-to-side"),+ "rdp": ("r\u200bdp", "remote desktop sess", "ts/mstsc sess"),+ "pass-the-hash": ("hash-replay attack", "auth-hash replay", "secret-hash replay"),+ "pass the hash": ("hash replay attack", "auth hash replay", "secret hash replay"),+ "remote service": ("over-network svc invoke", "ms-rpc remote call", "rpc remote call"),+ "pivoting": ("p1voting", "pivot-host hop", "in-network hop"),+ "ssh": ("s\u200bsh", "secure shell", "openssh session"),+ "smb scan": ("smb sweep", "fileshare probe", "windows-share probe"),+ "wmic /node": ("wm\u200bic /machine", "mgmt-cli /remote", "mgmt-fabric cli /remote"),+ "wmi remote": ("wm\u200bi remote", "mgmt-fabric remote", "remote mgmt-fabric"),++ # TA0009 — Collection+ "collection": ("data-gathering stage", "skim stage", "asset-pull stage"),+ "data from local": ("data lifted from host", "local-host data pull", "on-host data pull"),+ "screenshot": ("screen-capture", "ui snapshot", "display-grab"),+ "keylog": ("keystroke-capture", "input-capture", "kb-monitor"),+ "clipboard": ("paste buffer", "copy-buffer", "clip-store"),+ "bulk download": ("mass pull", "batch fetch", "wholesale fetch"),+ "pii": ("p\u200bii", "personal data", "user identity data"),+ "customer record": ("customer row", "client account row", "subscriber record"),+ "mailbox export": ("inbox extract", "mailstore export", "messaging-store export"),+ "pst": ("p\u200bst", "outlook archive", "mail archive"),+ "private repo": ("internal source repo", "non-public repo", "closed repo"),+ "private repos": ("internal source repos", "non-public repos", "closed repos"),++ # TA0010 — Exfiltration+ "exfiltrat": ("ex-bound transfer", "outbound siphon", "ex-bound siphon"),+ "c2 channel": ("operator channel", "comms-back tunnel", "callback channel"),+ "cloud storage": ("object storage uplink", "blob-store push target", "external bucket"),+ "dns tunnel": ("dns covert tunnel", "udp/53 covert track", "dns covert track"),+ "ftp": ("f\u200btp", "file-xfer protocol", "legacy file-transfer"),+ "upload": ("up\u200bload", "outbound transfer", "push-out"),+ "egress": ("outbound flow", "ex-bound flow", "outward traffic"),+ "google drive": ("g\u200bdrive", "drive-shared bucket", "consumer-cloud drive"),+ "drive upload": ("drive push", "drive transfer", "drive sync-up"),+ "personal drive": ("personal cloud bucket", "consumer cloud bucket", "non-corp drive"),+ "transfer to": ("xfer to", "push to", "ship to"),+ "s3 bucket": ("object-store bucket", "blob-store bucket", "aws object store"),+ "s3://": ("aws://obj/", "object-store-uri", "blob-uri"),+ "data egress": ("outbound data flow", "ex-bound data flow", "data outflow"),++ # TA0011 — Command and Control+ "command and control": ("operator-channel", "callback infra", "ops-channel"),+ "c2": ("c\u200b2", "ops channel", "callback infra"),+ "beacon": ("b\u200beacon", "callback ping", "regular check-in"),+ "c&c": ("c\u200b&c", "ops channel", "callback infra"),+ "dga": ("d\u200bga", "domain-gen algorithm", "algorithmic domains"),+ "domain generation": ("algorithmic domain rotation", "rotating-domain algo", "domain-rotation algo"),+ "dns query": ("d\u200bns query", "name-resolution", "name lookup"),+ "covert channel": ("covert-comms link", "stealthy backchannel", "hidden link"),+ "cobalt strike": ("c0balt strike", "crimson-team toolkit", "red-team-grade dropper"),+ "https beacon": ("tls callback", "https callback", "tls heartbeat"),+ "ja3": ("j@3", "tls fingerprint hash", "tls-handshake fingerprint"),++ # TA0040 — Impact+ "impact": ("damage stage", "harm stage", "ko stage"),+ "ransom": ("ext0rt", "lockout-for-pay", "data-lockout demand"),+ "encrypt": ("scr@mble", "lock-with-key", "cipher-lock"),+ "wipe": ("zero-out", "shred", "scrub"),+ "destroy": ("annihilate", "deletion-pass", "purge"),+ "disrupt": ("d1srupt", "knock-offline", "make-unavailable"),+ "defacement": ("page-graffiti", "site replacement", "homepage swap"),+ "miner": ("c0in-miner", "compute-hijacking process", "cycles-stealing process"),+ "cryptomine": ("c0in-mining", "compute hijack for currency", "cycles for currency"),+ "xmrig": ("xm\u200brig", "monero-grade c0in-tool", "c0in-tool suite"),+ "ddos": ("d\u200bdos", "flood attack", "volumetric flood"),+ "syn flood": ("tcp-half-open flood", "tcp synflood", "tcp half-open swarm"),+ "wire transfer": ("ach payment instruction", "outgoing remittance", "treasury debit instruction"),+ "$250": ("a quarter-million-dollar", "USD250000", "two-fifty-K"),+ "bec": ("b\u200bec", "exec-impersonation fraud", "boss-impersonation fraud"),+}+++# Light obfuscation only — leetspeak, used for the "light" intensity bucket+# so the defender SHOULD still catch most cases there.+_LIGHT_LEET: dict[str, str] = {+ "phishing": "phi$hing",+ "powershell": "powershell", # untouched — light tier+ "execution": "execution", # untouched — light tier+ "credential": "credentia1",+ "exfiltrat": "exfiltrat", # untouched — light tier+}+++# ---------------------------------------------------------------------------+# Grammar validation — refuse to ship if a synonym would itself match a+# defender keyword for a tactic. This means "graceful degradation" is the+# only failure mode; we never accidentally trip a different tactic.+# ---------------------------------------------------------------------------+++def _validate_grammar() -> None:+ """Make sure no synonym alternate contains a defender keyword."""+ flat_keywords: list[str] = []+ for kws in _TACTIC_KEYWORDS.values():+ flat_keywords.extend(k.lower() for k in kws)++ failures: list[str] = []+ for src, alternates in _SYNONYMS.items():+ for alt in alternates:+ low = alt.lower()+ for kw in flat_keywords:+ # Same keyword self-match is fine (it's the original word+ # we're rewriting), but any *other* keyword landing inside+ # the alternate is a leak.+ if kw == src.lower():+ continue+ if kw in low:+ failures.append(+ f"alternate '{alt}' for '{src}' still contains keyword '{kw}'"+ )+ if failures:+ msg = "\n - ".join(failures[:20])+ raise RuntimeError(+ f"Adversary mutator grammar leaks defender keywords:\n - {msg}"+ )+++_validate_grammar()+++# ---------------------------------------------------------------------------+# Mutation engine+# ---------------------------------------------------------------------------+++# Ordered by descending length so multi-word keys are matched before their+# single-word substrings (e.g. "spear-phish" before "spear", "wmi event"+# before "wmi"). This is critical for correctness.+_KEY_ORDER: list[str] = sorted(_SYNONYMS.keys(), key=len, reverse=True)++# Pre-compile case-insensitive regexes per key. We escape the key directly+# (no word boundaries — many keys contain punctuation like "cmd.exe" or+# "s3://" where word boundaries fight us).+_KEY_REGEX: dict[str, re.Pattern[str]] = {+ k: re.compile(re.escape(k), re.IGNORECASE) for k in _KEY_ORDER+}+++def _bucket(incident_id: str) -> str:+ """Pick a mutation intensity bucket deterministically per incident.++ Distribution targets:+ heavy ≈ 45% — every keyword swapped for both expected tactics+ medium ≈ 35% — one tactic preserved cleanly, others mutated+ light ≈ 20% — light leetspeak; defender should still catch++ The 45/35/20 split lands the eval near the ~0.55 graceful-degradation+ floor with comfortable headroom for either side.+ """+ h = int(hashlib.sha256(incident_id.encode()).hexdigest()[:8], 16)+ bucket_pct = h % 100+ if bucket_pct < 45:+ return "heavy"+ if bucket_pct < 80:+ return "medium"+ return "light"+++def _pick_alternate(key: str, incident_id: str) -> str:+ """Pick one of the deterministic alternates for `key`."""+ alts = _SYNONYMS[key]+ h = int(hashlib.sha256(f"{incident_id}|{key}".encode()).hexdigest()[:8], 16)+ return alts[h % len(alts)]+++def _mutate_text_full(text: str, incident_id: str) -> str:+ """Replace every keyword in `text` with its deterministic alternate."""+ out = text+ for key in _KEY_ORDER:+ pattern = _KEY_REGEX[key]+ if pattern.search(out):+ alt = _pick_alternate(key, incident_id)+ out = pattern.sub(alt, out)+ return out+++def _mutate_text_partial(+ text: str, incident_id: str, preserve_tactics: set[str]+) -> str:+ """Mutate keywords EXCEPT those tied to one preserved tactic.++ The defender still has at least one route to detect the incident.+ """+ preserve_keywords = {+ kw.lower()+ for tactic in preserve_tactics+ for kw in _TACTIC_KEYWORDS.get(tactic, [])+ }+ out = text+ for key in _KEY_ORDER:+ if key.lower() in preserve_keywords:+ continue+ pattern = _KEY_REGEX[key]+ if pattern.search(out):+ alt = _pick_alternate(key, incident_id)+ out = pattern.sub(alt, out)+ return out+++def _mutate_text_light(text: str) -> str:+ """Apply light leetspeak that should NOT defeat the defender.++ Used as a control bucket — confirms the defender can still extract+ tactics under low-grade obfuscation, so a regression on the heavy+ bucket can't be masked by the light tier silently failing too.+ """+ out = text+ for src, dst in _LIGHT_LEET.items():+ out = re.sub(re.escape(src), dst, out, flags=re.IGNORECASE)+ return out+++def mutate_incident(incident: dict[str, Any]) -> dict[str, Any]:+ """Return an adversarially-mutated copy of `incident`."""+ incident_id = incident["id"]+ bucket = _bucket(incident_id)+ expected_tactics: list[str] = list(incident.get("expected_tactics", []))++ if bucket == "heavy":+ new_title = _mutate_text_full(incident["title"], incident_id)+ new_description = _mutate_text_full(incident["description"], incident_id)+ elif bucket == "medium":+ if expected_tactics:+ # Preserve the LAST expected tactic deterministically.+ preserve_idx = (+ int(hashlib.sha256(incident_id.encode()).hexdigest()[8:16], 16)+ % len(expected_tactics)+ )+ preserve = {expected_tactics[preserve_idx]}+ else:+ preserve = set()+ new_title = _mutate_text_partial(incident["title"], incident_id, preserve)+ new_description = _mutate_text_partial(+ incident["description"], incident_id, preserve+ )+ else:+ new_title = _mutate_text_light(incident["title"])+ new_description = _mutate_text_light(incident["description"])++ return {+ # Keep the same id space so the eval suite can correlate with the+ # base dataset — that lets us do "which template lost coverage+ # under adversary?" diffs.+ "id": incident_id,+ "template_id": incident.get("template_id"),+ "template_index": incident.get("template_index"),+ "adversary_intensity": bucket,+ "title": new_title,+ "description": new_description,+ "expected_tactics": expected_tactics,+ "expected_techniques": list(incident.get("expected_techniques", [])),+ "severity": incident.get("severity"),+ "response_class": incident.get("response_class"),+ "evidence_keywords": list(incident.get("evidence_keywords", [])),+ "original_title": incident["title"],+ "original_description": incident["description"],+ }+++def mutate_dataset(incidents: list[dict[str, Any]]) -> list[dict[str, Any]]:+ return [mutate_incident(inc) for inc in incidents]+++# ---------------------------------------------------------------------------+# Reporting helpers (used by --report and by the eval suite)+# ---------------------------------------------------------------------------+++def adversary_coverage_report(+ mutated: list[dict[str, Any]],+) -> dict[str, Any]:+ """Summarise how many incidents lost detectable tactics under mutation.++ The defender's keyword extractor is run BOTH on the original and on the+ mutated description so we can quantify graceful-degradation.+ """+ bucket_counts = {"heavy": 0, "medium": 0, "light": 0}+ correct_total = 0+ lost_all_total = 0+ per_tactic_lost: dict[str, int] = {}+ per_template_correct: dict[str, dict[str, int]] = {}++ for inc in mutated:+ bucket_counts[inc["adversary_intensity"]] += 1+ expected = set(inc["expected_tactics"])+ text = f"{inc['title']}\n{inc['description']}"+ predicted = extract_tactics_from_text(text)+ overlap = predicted & expected+ if overlap:+ correct_total += 1+ else:+ lost_all_total += 1++ for t in expected:+ if t not in predicted:+ per_tactic_lost[t] = per_tactic_lost.get(t, 0) + 1++ tpl = inc.get("template_id") or "<unknown>"+ slot = per_template_correct.setdefault(tpl, {"correct": 0, "total": 0})+ slot["total"] += 1+ if overlap:+ slot["correct"] += 1++ n = len(mutated)+ return {+ "incidents": n,+ "buckets": bucket_counts,+ "defender_correct": correct_total,+ "defender_lost_all_tactics": lost_all_total,+ "defender_accuracy": round(correct_total / n, 4) if n else 0.0,+ "per_tactic_lost": dict(sorted(per_tactic_lost.items())),+ "per_template": {+ t: {+ "correct": v["correct"],+ "total": v["total"],+ "accuracy": round(v["correct"] / v["total"], 4) if v["total"] else 0.0,+ }+ for t, v in sorted(per_template_correct.items())+ },+ }+++# ---------------------------------------------------------------------------+# CLI+# ---------------------------------------------------------------------------+++def main() -> None:+ parser = argparse.ArgumentParser(+ description="Generate the adversary-mutated incident dataset (Wave 2 — w2-aivai)."+ )+ parser.add_argument(+ "--input",+ type=Path,+ default=_DEFAULT_INPUT,+ help="Path to base synthetic_incidents.json (default: services/agents/tests/eval_data/synthetic_incidents.json)",+ )+ parser.add_argument(+ "--out",+ type=Path,+ default=_DEFAULT_OUTPUT,+ help="Path to write adversary_incidents.json",+ )+ parser.add_argument(+ "--report",+ action="store_true",+ help="Print a coverage / graceful-degradation report alongside writing the file.",+ )+ args = parser.parse_args()++ if not args.input.exists():+ sys.exit(+ f"input not found: {args.input}. Run scripts/generate_eval_incidents.py first."+ )++ base = json.loads(args.input.read_text())+ mutated = mutate_dataset(base)++ args.out.parent.mkdir(parents=True, exist_ok=True)+ args.out.write_text(json.dumps(mutated, indent=2) + "\n")++ if args.report:+ report = adversary_coverage_report(mutated)+ print()+ print("=" * 78)+ print(" AiSOC AI-vs-AI adversary dataset — graceful-degradation report")+ print("=" * 78)+ print(f" Incidents: {report['incidents']}")+ print(+ f" Bucket split: "+ f"heavy={report['buckets']['heavy']}, "+ f"medium={report['buckets']['medium']}, "+ f"light={report['buckets']['light']}"+ )+ print(+ f" Defender catch rate: {report['defender_correct']}"+ f"/{report['incidents']} = {report['defender_accuracy'] * 100:.1f}%"+ )+ print(+ f" Defender lost-everything: "+ f"{report['defender_lost_all_tactics']} incidents"+ )+ print()+ print(" Tactics most-lost under mutation:")+ for t, n in sorted(+ report["per_tactic_lost"].items(), key=lambda kv: kv[1], reverse=True+ )[:8]:+ print(f" {t}: -{n}")+ print("=" * 78)+ print(f"wrote {len(mutated)} mutated incidents to {args.out}")+++if __name__ == "__main__":+ main()diff --git a/scripts/run_evals.py b/scripts/run_evals.pyindex 047838da9..685fefdb6 100755--- a/scripts/run_evals.py+++ b/scripts/run_evals.py@@ -10,6 +10,8 @@ Suites:2. Alert reduction ratio (services/agents/tests/test_alert_reduction.py)3. Investigation completeness (services/agents/tests/test_investigation_completeness.py)4. Response-plan quality (services/agents/tests/test_response_quality.py)+ 5. Hunt corpus coverage (services/agents/tests/test_hunt_corpus.py)+ 6. AI-vs-AI adversary degradation (services/agents/tests/test_adversary_eval.py)Each substrate suite reports two metrics:@@ -28,10 +30,14 @@ Usage:python3 scripts/run_evals.py --json # JSON to stdoutpython3 scripts/run_evals.py --out path.json # write to a custom pathpython3 scripts/run_evals.py --ci # exit non-zero on regression+ python3 scripts/run_evals.py \+ --baseline eval_baseline.json \+ --max-regression-pp 1.0 # gate against a saved baselineExit codes:0 All gates passed (or --ci not set)1 At least one suite below its target floor (only with --ci)+ 2 MITRE accuracy regressed by ≥ --max-regression-pp vs baseline (w2-dac)"""from __future__ import annotations@@ -58,6 +64,17 @@ from tests.test_investigation_completeness import ( # type: ignorefrom tests.test_response_quality import ( # type: ignoreevaluate_response_quality,)+from tests.test_adversary_eval import ( # type: ignore+ evaluate_adversary_accuracy,+ _OVERALL_FLOOR as _ADVERSARY_OVERALL_FLOOR,+ _LIGHT_BUCKET_FLOOR as _ADVERSARY_LIGHT_FLOOR,+ _HEAVY_BUCKET_CEILING as _ADVERSARY_HEAVY_CEILING,+)+from tests.test_hunt_corpus import ( # type: ignore+ evaluate_hunt_corpus,+ _POSITIVE_FLOOR as _HUNT_POSITIVE_FLOOR,+ _NEGATIVE_CEILING as _HUNT_NEGATIVE_CEILING,+)# Per-suite floors (must match what tests assert)@@ -66,6 +83,8 @@ _TARGETS = {"alert_reduction": 0.70,"investigation_completeness": 0.85,"response_quality": 0.80,+ "hunt_corpus": _HUNT_POSITIVE_FLOOR,+ "adversary_eval": _ADVERSARY_OVERALL_FLOOR,}# Per-template macro floors (kept slightly below per-case floors because each@@ -198,6 +217,97 @@ def _run_response_quality() -> dict:return out+def _run_hunt_corpus() -> dict:+ """Fifth gate (w2-hac): hunt-as-code coverage against the synthetic+ hunt telemetry corpus.++ The hunt corpus is small and hand-authored, so we hold ourselves to+ perfect scenario coverage rather than a percentage floor:++ * every hunt MUST fire on its declared positive scenario (positive+ rate at or above ``_HUNT_POSITIVE_FLOOR``);+ * no hunt may fire on its declared negative scenario (false-positive+ rate at or below ``_HUNT_NEGATIVE_CEILING``);+ * every ``INC-HUNT-*`` event in the telemetry must be referenced by+ at least one hunt YAML — orphan telemetry is a regression.+ """+ t0 = time.perf_counter()+ res = evaluate_hunt_corpus()+ dur = (time.perf_counter() - t0) * 1000++ positive_pass = res.positive_rate >= _HUNT_POSITIVE_FLOOR+ negative_pass = res.false_positive_rate <= _HUNT_NEGATIVE_CEILING+ no_orphans = not res.orphan_incident_ids++ return {+ "metric": "positive_scenario_catch_rate",+ "value": round(res.positive_rate, 4),+ "target": _HUNT_POSITIVE_FLOOR,+ "passed": positive_pass and negative_pass and no_orphans,+ "duration_ms": round(dur, 1),+ "details": {+ "hunts": res.hunts_total,+ "positives_expected": res.positives_expected,+ "positives_caught": res.positives_caught,+ "negatives_expected": res.negatives_expected,+ "false_positives": res.false_positives,+ "false_positive_rate": round(res.false_positive_rate, 4),+ "negative_ceiling": _HUNT_NEGATIVE_CEILING,+ "orphan_incident_ids": res.orphan_incident_ids,+ "misses": res.misses,+ "false_positive_details": res.false_positive_details,+ "positive_pass": positive_pass,+ "negative_pass": negative_pass,+ "no_orphans": no_orphans,+ },+ }+++def _run_adversary() -> dict:+ """Sixth gate (w2-aivai): graceful degradation under attacker-LLM mutation.++ The adversary corpus is generated by ``scripts/generate_adversary_incidents.py``+ and rewrites every defender-known keyword into evasive synonyms, character+ obfuscation, and fragmentation across heavy/medium/light buckets. The gate+ enforces three things at once:++ * overall catch rate stays at or above ``_ADVERSARY_OVERALL_FLOOR`` —+ the substrate must degrade gracefully, not fall off a cliff;+ * the light (control) bucket stays at or above ``_ADVERSARY_LIGHT_FLOOR``+ — leetspeak alone shouldn't break the keyword extractor;+ * the heavy bucket stays *at or below* ``_ADVERSARY_HEAVY_CEILING`` —+ if heavy is catching too much, the dataset isn't actually adversarial+ and the suite has lost its signal.+ """+ t0 = time.perf_counter()+ res = evaluate_adversary_accuracy()+ dur = (time.perf_counter() - t0) * 1000++ light_acc = res.bucket_accuracy("light")+ heavy_acc = res.bucket_accuracy("heavy")+ overall_pass = res.accuracy >= _ADVERSARY_OVERALL_FLOOR+ light_pass = light_acc >= _ADVERSARY_LIGHT_FLOOR+ heavy_pass = heavy_acc <= _ADVERSARY_HEAVY_CEILING++ return {+ "metric": "graceful_degradation_catch_rate",+ "value": round(res.accuracy, 4),+ "target": _ADVERSARY_OVERALL_FLOOR,+ "passed": overall_pass and light_pass and heavy_pass,+ "duration_ms": round(dur, 1),+ "details": {+ "incidents": res.total,+ "correct": res.correct,+ "lost_all_tactics": res.lost_all_tactics,+ "buckets": res.to_summary()["buckets"],+ "light_floor": _ADVERSARY_LIGHT_FLOOR,+ "heavy_ceiling": _ADVERSARY_HEAVY_CEILING,+ "light_pass": light_pass,+ "heavy_pass": heavy_pass,+ },+ }++def _summarise_telemetry() -> dict:"""Summarise the synthetic-telemetry corpus produced alongside the dataset.@@ -247,6 +357,22 @@ def main() -> None:action="store_true",help="Exit non-zero if any suite is below its target floor.",)+ parser.add_argument(+ "--baseline",+ type=Path,+ default=None,+ help=(+ "Compare results against a saved baseline JSON (Wave 2 — w2-dac). "+ "When set, fail with exit code 2 if MITRE accuracy regresses by "+ "≥ --max-regression-pp percentage points."+ ),+ )+ parser.add_argument(+ "--max-regression-pp",+ type=float,+ default=1.0,+ help="Allowed MITRE accuracy regression vs baseline, in percentage points.",+ )args = parser.parse_args()summary: dict = {@@ -257,11 +383,54 @@ def main() -> None:"alert_reduction": _run_alert_reduction(),"investigation_completeness": _run_completeness(),"response_quality": _run_response_quality(),+ "hunt_corpus": _run_hunt_corpus(),+ "adversary_eval": _run_adversary(),},"telemetry": _summarise_telemetry(),}summary["all_passed"] = all(s["passed"] for s in summary["suites"].values())+ regression_failure = False+ if args.baseline is not None:+ if not args.baseline.exists():+ summary["baseline_compare"] = {+ "baseline_path": str(args.baseline),+ "available": False,+ "note": "baseline file not found; treating as no-op",+ }+ else:+ try:+ baseline = json.loads(args.baseline.read_text())+ except json.JSONDecodeError as exc:+ summary["baseline_compare"] = {+ "baseline_path": str(args.baseline),+ "available": False,+ "error": f"invalid baseline JSON: {exc}",+ }+ else:+ deltas: dict[str, dict] = {}+ worst_mitre_drop_pp = 0.0+ for name, suite in summary["suites"].items():+ base_suite = baseline.get("suites", {}).get(name) or {}+ base_value = float(base_suite.get("value", suite["value"]))+ delta_pp = round((suite["value"] - base_value) * 100, 4)+ deltas[name] = {+ "candidate": suite["value"],+ "baseline": base_value,+ "delta_pp": delta_pp,+ }+ if name == "mitre_accuracy" and delta_pp < -worst_mitre_drop_pp:+ worst_mitre_drop_pp = -delta_pp+ regression_failure = worst_mitre_drop_pp >= args.max_regression_pp+ summary["baseline_compare"] = {+ "baseline_path": str(args.baseline),+ "available": True,+ "max_regression_pp": args.max_regression_pp,+ "mitre_drop_pp": round(worst_mitre_drop_pp, 4),+ "regressed": regression_failure,+ "deltas": deltas,+ }+args.out.write_text(json.dumps(summary, indent=2))if args.json:@@ -306,6 +475,14 @@ def main() -> None:print("=" * 78)verdict = "ALL GATES PASSED" if summary["all_passed"] else "REGRESSION DETECTED"print(f" {verdict}")+ cmp = summary.get("baseline_compare")+ if cmp and cmp.get("available"):+ arrow = "DROP" if cmp["regressed"] else "OK"+ print(+ f" Baseline compare: MITRE Δ = "+ f"{cmp['deltas']['mitre_accuracy']['delta_pp']:+.2f} pp "+ f"(allowed drop ≤ {cmp['max_regression_pp']:.2f} pp) [{arrow}]"+ )try:rel = args.out.relative_to(_REPO_ROOT)except ValueError:@@ -313,6 +490,8 @@ def main() -> None:print(f" Report written to: {rel}")print()+ if regression_failure:+ sys.exit(2)sys.exit(0 if (summary["all_passed"] or not args.ci) else 1)diff --git a/services/actions/app/api/router.py b/services/actions/app/api/router.pyindex b0c82b344..a51848dd1 100644--- a/services/actions/app/api/router.py+++ b/services/actions/app/api/router.py@@ -4,15 +4,20 @@ Action Execution Service REST API.from __future__ import annotations+from datetime import UTC, datetimefrom typing import Anyfrom uuid import UUIDimport structlog-from fastapi import APIRouter, HTTPException+from fastapi import APIRouter, HTTPException, Query+from fastapi.responses import HTMLResponse+from app.core.config import get_settingsfrom app.models.action import ActionRequest, ActionStatus, ActionType+from app.security.chatops_token import ChatOpsTokenError, verify_tokenfrom app.services.blast_radius import BlastRadiusGatefrom app.services.executor_registry import EXECUTOR_REGISTRY+from app.services.timeline_client import TimelineClientError, post_timeline_eventlogger = structlog.get_logger()router = APIRouter()@@ -21,6 +26,11 @@ gate = BlastRadiusGate()# In-memory action store (replace with DB in production)_actions: dict[str, dict[str, Any]] = {}+# Replay-protection set: action IDs that have already received a response.+# Single-use enforcement is layered on top of HMAC + expiry. Anything more+# durable belongs in Redis once we move off the in-memory action store.+_chatops_replied: set[str] = set()+@router.post("/actions", response_model=dict)async def submit_action(request: ActionRequest):@@ -121,6 +131,158 @@ async def get_action(action_id: str):return record+_CHOICE_COPY: dict[str, dict[str, str]] = {+ "acknowledge": {+ "headline": "Thanks — recorded as acknowledged.",+ "body": "We've logged that you confirmed this activity. You can close this tab.",+ },+ "deny": {+ "headline": "Thanks — recorded as denied.",+ "body": (+ "We've flagged this as suspicious. A security analyst will follow up shortly. "+ "If you didn't expect this prompt, please contact your security team."+ ),+ },+ "escalate": {+ "headline": "Thanks — escalated to security.",+ "body": "We've routed this to your security team for review.",+ },+}+++def _chatops_response_html(headline: str, body: str, *, ok: bool = True) -> str:+ """Tiny self-contained response page rendered to the user's browser.++ Slack/Teams open the callback URL in a normal browser tab, so we can't+ redirect into the AiSOC console (the user may not have one). A static+ HTML acknowledgement is the smallest UX that confirms the click landed+ without leaking incident details into a URL the user might forward.+ """+ color = "#0a7" if ok else "#a33"+ return (+ "<!doctype html><html lang=\"en\"><head>"+ "<meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">"+ "<title>AiSOC verification</title>"+ "<style>"+ "body{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,sans-serif;"+ "background:#0b1220;color:#e6edf3;margin:0;padding:0;display:flex;min-height:100vh;"+ "align-items:center;justify-content:center}"+ ".card{max-width:480px;background:#111827;border:1px solid #1f2937;border-radius:12px;"+ "padding:32px;box-shadow:0 8px 24px rgba(0,0,0,.4)}"+ f".dot{{width:12px;height:12px;border-radius:50%;background:{color};display:inline-block;margin-right:8px}}"+ "h1{margin:0 0 12px 0;font-size:18px;display:flex;align-items:center}"+ "p{margin:0;color:#9ca3af;line-height:1.5}"+ "</style></head><body>"+ f"<div class=\"card\"><h1><span class=\"dot\"></span>{headline}</h1><p>{body}</p></div>"+ "</body></html>"+ )++[email protected]("/chatops/callback", response_class=HTMLResponse)+async def chatops_callback(token: str = Query(..., min_length=8)):+ """Receive a user's response to a ChatOps verification prompt.++ The token is the HMAC-signed payload minted by+ :class:`app.executors.chatops.ChatOpsVerifyExecutor`. We re-verify+ the signature + expiry, dedupe against ``_chatops_replied``, write a+ ``chatops.verify.responded`` event onto the case timeline, and update+ the in-memory action record so ``GET /actions/{id}`` reflects the+ final status.++ Returns an HTML acknowledgement page so the click lands cleanly in+ Slack/Teams' default browser tab.+ """+ settings = get_settings()+ secret = settings.AISOC_CHATOPS_RESPONSE_SECRET++ try:+ claims = verify_token(token, secret)+ except ChatOpsTokenError as exc:+ reason = str(exc)+ logger.info("ChatOps callback rejected", reason=reason)+ message = {+ "expired": (+ "This verification link has expired. If you still need to respond, "+ "contact your security team."+ ),+ "invalid_signature": "This verification link is invalid.",+ }.get(reason, "This verification link is invalid.")+ return HTMLResponse(+ content=_chatops_response_html("Couldn't record your response", message, ok=False),+ status_code=400,+ )++ action_id_str = str(claims.action_id)+ if action_id_str in _chatops_replied:+ return HTMLResponse(+ content=_chatops_response_html(+ "Response already recorded",+ "We've already logged a response for this prompt. No further action is needed.",+ ),+ status_code=200,+ )++ record = _actions.get(action_id_str)+ # We still record on the timeline even if the in-memory record is gone+ # (e.g. service restart). The case timeline is the durable store —+ # losing the local record shouldn't lose the user's reply.++ timeline_warning: str | None = None+ try:+ await post_timeline_event(+ case_id=claims.case_id,+ event_type="chatops.verify.responded",+ content=(+ f"User {claims.user_ref or 'unknown'} responded "+ f"'{claims.choice}' to the ChatOps verification prompt."+ ),+ metadata={+ "action_id": action_id_str,+ "tenant_id": str(claims.tenant_id),+ "choice": claims.choice,+ "user_ref": claims.user_ref,+ "issued_at": claims.issued_at,+ "responded_at": int(datetime.now(UTC).timestamp()),+ },+ )+ except TimelineClientError as exc:+ timeline_warning = str(exc)+ logger.warning(+ "ChatOps response timeline write failed",+ action_id=action_id_str,+ case_id=str(claims.case_id),+ error=timeline_warning,+ )++ _chatops_replied.add(action_id_str)++ if record is not None:+ record["status"] = ActionStatus.COMPLETED+ record.setdefault("output", {})+ record["output"].update(+ {+ "user_choice": claims.choice,+ "user_ref": claims.user_ref,+ "responded_at": datetime.now(UTC).isoformat(),+ }+ )+ if timeline_warning:+ record["output"]["timeline_warning"] = timeline_warning++ logger.info(+ "ChatOps response recorded",+ action_id=action_id_str,+ case_id=str(claims.case_id),+ choice=claims.choice,+ )++ copy = _CHOICE_COPY.get(claims.choice, _CHOICE_COPY["acknowledge"])+ return HTMLResponse(+ content=_chatops_response_html(copy["headline"], copy["body"]),+ status_code=200,+ )++@router.get("/health")async def health():return {"status": "healthy", "service": "aisoc-actions"}diff --git a/services/actions/app/core/__init__.py b/services/actions/app/core/__init__.pynew file mode 100644index 000000000..54be64791--- /dev/null+++ b/services/actions/app/core/__init__.py@@ -0,0 +1 @@+"""Core utilities for the AiSOC Actions service."""diff --git a/services/actions/app/core/config.py b/services/actions/app/core/config.pynew file mode 100644index 000000000..3ce66272b--- /dev/null+++ b/services/actions/app/core/config.py@@ -0,0 +1,87 @@+"""Application configuration for the AiSOC Actions service.++Loaded once at import time from environment (and optional ``.env``). Two settings+matter for the ChatOps user-verification flow added in Wave 1:++* ``AISOC_CREDENTIAL_KEY`` — the same Fernet key the API + connectors services+ use. We only need it when the action payload itself ships an encrypted+ ``vault:v1:`` token (e.g. a Slack bot token persisted by the click-and-connect+ connector flow). See ``app.security.credential_vault``.+* ``AISOC_API_BASE_URL`` + ``AISOC_API_SERVICE_TOKEN`` — used to call the+ ``services/api`` ``add_timeline_event`` endpoint when a ChatOps response lands.++We deliberately do **not** auto-generate credential keys here. The actions+service is internal infrastructure, so missing config should fail loud, not+silently invent ephemeral keys that would break decryption on restart.+"""++from __future__ import annotations++from functools import lru_cache++from pydantic import Field+from pydantic_settings import BaseSettings, SettingsConfigDict+++class ActionsSettings(BaseSettings):+ model_config = SettingsConfigDict(+ env_file=".env",+ env_file_encoding="utf-8",+ case_sensitive=True,+ extra="ignore",+ )++ AISOC_API_BASE_URL: str = Field(+ default="http://aisoc-api:8000",+ description="Base URL of the services/api FastAPI app, e.g. http://aisoc-api:8000.",+ )+ AISOC_API_SERVICE_TOKEN: str = Field(+ default="",+ description=(+ "API-key token (aisoc_…) used by services/actions to call services/api "+ "endpoints that require cases:write. Mounted as a secret in production."+ ),+ )++ AISOC_CREDENTIAL_KEY: str = Field(+ default="",+ description=(+ "Fernet key shared with services/api + services/connectors. Required "+ "only when an action payload contains a vault:v1: ciphertext."+ ),+ )+ AISOC_CREDENTIAL_KEY_ROTATION_FROM: str = Field(+ default="",+ description="Comma-separated historical Fernet keys for transparent re-decryption.",+ )++ AISOC_FEATURE_CHATOPS_VERIFY: bool = Field(+ default=True,+ description="Master toggle for the Slack/Teams interactive user-verification action.",+ )++ AISOC_CHATOPS_RESPONSE_SECRET: str = Field(+ default="",+ description=(+ "HMAC secret used to sign ChatOps response tokens so we can verify a "+ "callback genuinely came from a message we sent."+ ),+ )++ AISOC_CHATOPS_TIMEOUT_SECONDS: int = Field(+ default=900,+ description="How long a verification prompt stays valid (default 15 min).",+ )++ AISOC_ACTIONS_PUBLIC_URL: str = Field(+ default="http://localhost:8003",+ description=(+ "Externally-reachable base URL of services/actions. Used to build "+ "the callback links embedded in ChatOps verification messages."+ ),+ )+++@lru_cache(maxsize=1)+def get_settings() -> ActionsSettings:+ return ActionsSettings()diff --git a/services/actions/app/executors/chatops.py b/services/actions/app/executors/chatops.pynew file mode 100644index 000000000..671e75035--- /dev/null+++ b/services/actions/app/executors/chatops.py@@ -0,0 +1,244 @@+"""ChatOps user-verification executor.++Wave 1 of the AiSOC v6 capability roadmap. The executor:++1. Mints three HMAC-signed callback tokens — one per choice+ (``acknowledge`` / ``deny`` / ``escalate``) — using+ :mod:`app.security.chatops_token`. Each token carries the action,+ case, tenant, user reference, and an expiry derived from+ ``AISOC_CHATOPS_TIMEOUT_SECONDS``.+2. Builds three callback URLs against ``AISOC_ACTIONS_PUBLIC_URL``.+3. Posts the interactive prompt into the configured transport+ (``slack`` via Block Kit, ``teams`` via Connector Card) using the+ credential-vault-aware helpers in :mod:`app.services.chatops_prompt`.+4. Writes a ``chatops.verify.prompted`` event onto the case timeline so+ analysts see the question was asked, and returns ``ActionStatus.RUNNING``+ to signal that the analyst is now waiting on the user.++The actual user response lands on the callback endpoint (added in+``app/api/router.py``) and produces a second timeline event; this executor+deliberately does not block the request loop on a human reply.++Failure modes:++* Feature flag off — returns ``ActionStatus.FAILED`` with a clear error+ rather than silently no-op'ing, so misconfiguration is visible in tests.+* No webhook configured — same: the action exists to ask a person a+ question, so an unreachable transport is a hard fail.+* Timeline write fails — we log and surface a non-fatal warning on the+ result, but keep the action ``RUNNING`` because the prompt was already+ delivered. Losing the timeline write is recoverable, the prompt is not.+"""++from __future__ import annotations++from datetime import UTC, datetime+from typing import Any++import structlog++from app.core.config import get_settings+from app.executors.base import BaseExecutor+from app.models.action import ActionRequest, ActionResult, ActionStatus, BlastRadius+from app.security.chatops_token import ChatOpsTokenError, mint_token+from app.services.chatops_prompt import (+ ChatOpsButton,+ ChatOpsPromptError,+ send_slack_prompt,+ send_teams_prompt,+)+from app.services.timeline_client import TimelineClientError, post_timeline_event++logger = structlog.get_logger()+++# Stable button order (acknowledge, deny, escalate) — keeps the prompt+# predictable across transports and makes screenshots/tests deterministic.+_CHOICES: tuple[tuple[str, str, str], ...] = (+ ("acknowledge", "Yes, that was me", "primary"),+ ("deny", "No, that wasn't me", "danger"),+ ("escalate", "I'm not sure — escalate", "default"),+)+++def _build_callback_url(+ *,+ base_url: str,+ token: str,+) -> str:+ """Compose the callback URL the user clicks in chat.++ The callback path is mounted by ``app/api/router.py`` and accepts a+ single ``token`` query parameter — see the route handler for the+ matching contract.+ """+ return f"{base_url.rstrip('/')}/api/v1/chatops/callback?token={token}"+++class ChatOpsVerifyExecutor(BaseExecutor):+ """Send an interactive verification prompt to the affected user."""++ async def execute(self, request: ActionRequest) -> ActionResult:+ settings = get_settings()++ if not settings.AISOC_FEATURE_CHATOPS_VERIFY:+ return ActionResult(+ action_id=request.id,+ status=ActionStatus.FAILED,+ blast_radius=BlastRadius.MINIMAL,+ error="ChatOps verification is disabled (AISOC_FEATURE_CHATOPS_VERIFY=False)",+ )++ params: dict[str, Any] = request.parameters or {}+ transport = str(params.get("transport", "slack")).lower()+ webhook_url = params.get("webhook_url") or ""+ bot_token = params.get("bot_token") or None+ channel = params.get("channel") or None+ question = str(+ params.get(+ "question",+ f"AiSOC needs to confirm activity on your account ({request.target}).",+ )+ )+ context = str(+ params.get(+ "context",+ f"Incident `{request.incident_id}` — rationale: {request.rationale or 'n/a'}",+ )+ )+ user_ref = str(params.get("user_ref", request.target))++ if transport not in {"slack", "teams"}:+ return ActionResult(+ action_id=request.id,+ status=ActionStatus.FAILED,+ blast_radius=BlastRadius.MINIMAL,+ error=f"unsupported ChatOps transport: {transport!r}",+ )+ if not webhook_url:+ return ActionResult(+ action_id=request.id,+ status=ActionStatus.FAILED,+ blast_radius=BlastRadius.MINIMAL,+ error="parameters.webhook_url is required for ChatOps verification",+ )++ # Mint one signed callback token per choice. Failures here are+ # configuration errors (missing HMAC secret), surface them up.+ try:+ buttons = [+ ChatOpsButton(+ label=label,+ url=_build_callback_url(+ base_url=settings.AISOC_ACTIONS_PUBLIC_URL,+ token=mint_token(+ action_id=request.id,+ case_id=request.incident_id,+ tenant_id=request.tenant_id,+ choice=choice,+ user_ref=user_ref,+ secret=settings.AISOC_CHATOPS_RESPONSE_SECRET,+ ttl_seconds=settings.AISOC_CHATOPS_TIMEOUT_SECONDS,+ ),+ ),+ style=style,+ )+ for choice, label, style in _CHOICES+ ]+ except ChatOpsTokenError as exc:+ return ActionResult(+ action_id=request.id,+ status=ActionStatus.FAILED,+ blast_radius=BlastRadius.MINIMAL,+ error=f"failed to mint ChatOps token: {exc}",+ )++ # Deliver the prompt. If this fails, the whole action fails — there+ # is no value in marking RUNNING when no one will ever see the+ # question.+ try:+ if transport == "slack":+ delivery = await send_slack_prompt(+ webhook_url=webhook_url,+ question=question,+ context=context,+ buttons=buttons,+ bot_token=bot_token,+ channel=channel,+ )+ else:+ delivery = await send_teams_prompt(+ webhook_url=webhook_url,+ question=question,+ context=context,+ buttons=buttons,+ )+ except ChatOpsPromptError as exc:+ logger.warning(+ "ChatOps prompt delivery failed",+ action_id=str(request.id),+ transport=transport,+ error=str(exc),+ )+ return ActionResult(+ action_id=request.id,+ status=ActionStatus.FAILED,+ blast_radius=BlastRadius.MINIMAL,+ error=str(exc),+ )++ # Best-effort timeline write — see module docstring for why we don't+ # fail the action when this errors.+ timeline_warning: str | None = None+ try:+ await post_timeline_event(+ case_id=request.incident_id,+ event_type="chatops.verify.prompted",+ content=(+ f"ChatOps verification sent to {user_ref} via {transport}. "+ f"Awaiting response (TTL {settings.AISOC_CHATOPS_TIMEOUT_SECONDS}s)."+ ),+ metadata={+ "action_id": str(request.id),+ "tenant_id": str(request.tenant_id),+ "transport": transport,+ "channel": channel,+ "user_ref": user_ref,+ "question": question,+ "expires_in_seconds": settings.AISOC_CHATOPS_TIMEOUT_SECONDS,+ },+ )+ except TimelineClientError as exc:+ timeline_warning = f"timeline prompt-event write failed: {exc}"+ logger.warning(+ "ChatOps timeline write failed",+ action_id=str(request.id),+ case_id=str(request.incident_id),+ error=str(exc),+ )++ logger.info(+ "ChatOps prompt delivered",+ action_id=str(request.id),+ case_id=str(request.incident_id),+ transport=transport,+ channel=channel,+ )++ return ActionResult(+ action_id=request.id,+ status=ActionStatus.RUNNING,+ blast_radius=BlastRadius.MINIMAL,+ output={+ "transport": transport,+ "channel": channel,+ "user_ref": user_ref,+ "delivery": delivery,+ "expires_in_seconds": settings.AISOC_CHATOPS_TIMEOUT_SECONDS,+ **({"timeline_warning": timeline_warning} if timeline_warning else {}),+ },+ executed_at=datetime.now(UTC),+ )+++__all__ = ["ChatOpsVerifyExecutor"]diff --git a/services/actions/app/models/action.py b/services/actions/app/models/action.pyindex 16d386c77..5d3544251 100644--- a/services/actions/app/models/action.py+++ b/services/actions/app/models/action.py@@ -25,6 +25,10 @@ class ActionType(str, Enum):NOTIFY_SLACK = "notify_slack"CREATE_TICKET = "create_ticket"RUN_PLAYBOOK = "run_playbook"+ # Wave 1 — ChatOps user verification: outbound interactive Slack/Teams prompt+ # asking the affected user to confirm or deny an event ("Was this you?").+ # The response is HMAC-validated and routed back into the case timeline.+ CHATOPS_VERIFY = "chatops_verify"class ActionStatus(str, Enum):@@ -60,6 +64,8 @@ ACTION_BLAST_RADIUS: dict[ActionType, BlastRadius] = {ActionType.NOTIFY_SLACK: BlastRadius.MINIMAL,ActionType.CREATE_TICKET: BlastRadius.MINIMAL,ActionType.RUN_PLAYBOOK: BlastRadius.MEDIUM,+ # ChatOps verification asks a user a yes/no question — no infra changes.+ ActionType.CHATOPS_VERIFY: BlastRadius.MINIMAL,}# Actions that require explicit human approvaldiff --git a/services/actions/app/security/__init__.py b/services/actions/app/security/__init__.pynew file mode 100644index 000000000..079d9dd44--- /dev/null+++ b/services/actions/app/security/__init__.py@@ -0,0 +1 @@+"""Security primitives for the AiSOC Actions service."""diff --git a/services/actions/app/security/chatops_token.py b/services/actions/app/security/chatops_token.pynew file mode 100644index 000000000..bbd6ba5ca--- /dev/null+++ b/services/actions/app/security/chatops_token.py@@ -0,0 +1,146 @@+"""HMAC-signed tokens for ChatOps verification callbacks.++The ChatOps verifier posts an interactive message containing one signed+callback URL per choice (e.g. ``acknowledge`` / ``deny`` / ``escalate``).+When the user clicks, the callback endpoint validates that:++* the token was actually minted by us (HMAC over the payload),+* the token has not expired (``exp`` field, default 15 min),+* the token has not been replayed (single-use enforcement is the caller's+ job — we hand back the parsed claims, including ``action_id``, so an+ in-memory or Redis-backed used-token set can dedupe).++Wire format is intentionally tiny: ``<b64url(payload)>.<hex(hmac_sha256)>``.+That keeps URLs short enough for Slack/Teams attachments and lets us avoid+adding a JWT library (``cryptography`` + stdlib is plenty here).+"""++from __future__ import annotations++import base64+import hashlib+import hmac+import json+import time+from dataclasses import dataclass+from typing import Final+from uuid import UUID++_TOKEN_VERSION: Final[str] = "v1"+++class ChatOpsTokenError(ValueError):+ """Raised when a callback token fails to validate.++ Surfaces a coarse reason ('expired', 'invalid_signature', 'malformed')+ so the callback endpoint can return a stable user-facing message+ without leaking which check failed.+ """+++@dataclass(frozen=True)+class ChatOpsTokenClaims:+ action_id: UUID+ case_id: UUID+ tenant_id: UUID+ choice: str+ user_ref: str+ issued_at: int+ expires_at: int+++def _b64url_encode(raw: bytes) -> str:+ return base64.urlsafe_b64encode(raw).rstrip(b"=").decode("ascii")+++def _b64url_decode(s: str) -> bytes:+ pad = "=" * (-len(s) % 4)+ return base64.urlsafe_b64decode(s + pad)+++def _sign(payload_b64: str, secret: str) -> str:+ mac = hmac.new(secret.encode("utf-8"), payload_b64.encode("ascii"), hashlib.sha256)+ return mac.hexdigest()+++def mint_token(+ *,+ action_id: UUID,+ case_id: UUID,+ tenant_id: UUID,+ choice: str,+ user_ref: str,+ secret: str,+ ttl_seconds: int,+) -> str:+ """Produce a signed callback token.++ ``user_ref`` is whatever stable identifier the executor wants to record+ on the timeline (email, sub, employee ID). It is not used for auth — the+ signature alone authenticates the click — but it lets the callback log+ the right principal without trusting a query-string field.+ """+ if not secret:+ raise ChatOpsTokenError("AISOC_CHATOPS_RESPONSE_SECRET is required to mint tokens")+ if choice not in {"acknowledge", "deny", "escalate"}:+ raise ChatOpsTokenError(f"unsupported choice: {choice!r}")++ now = int(time.time())+ body = {+ "v": _TOKEN_VERSION,+ "aid": str(action_id),+ "cid": str(case_id),+ "tid": str(tenant_id),+ "ch": choice,+ "ur": user_ref,+ "iat": now,+ "exp": now + max(int(ttl_seconds), 1),+ }+ payload_b64 = _b64url_encode(json.dumps(body, separators=(",", ":"), sort_keys=True).encode("utf-8"))+ sig = _sign(payload_b64, secret)+ return f"{payload_b64}.{sig}"+++def verify_token(token: str, secret: str, *, now: int | None = None) -> ChatOpsTokenClaims:+ """Validate signature + expiry and return parsed claims.++ Constant-time signature compare via ``hmac.compare_digest``. Caller is+ responsible for replay protection — re-using ``action_id`` should be+ rejected once a response has already been recorded against it.+ """+ if not secret:+ raise ChatOpsTokenError("AISOC_CHATOPS_RESPONSE_SECRET is required to verify tokens")+ if not isinstance(token, str) or token.count(".") != 1:+ raise ChatOpsTokenError("malformed")++ payload_b64, sig = token.split(".", 1)+ expected = _sign(payload_b64, secret)+ if not hmac.compare_digest(expected, sig):+ raise ChatOpsTokenError("invalid_signature")++ try:+ body = json.loads(_b64url_decode(payload_b64))+ except (ValueError, json.JSONDecodeError) as exc:+ raise ChatOpsTokenError("malformed") from exc++ if body.get("v") != _TOKEN_VERSION:+ raise ChatOpsTokenError("malformed")++ try:+ claims = ChatOpsTokenClaims(+ action_id=UUID(body["aid"]),+ case_id=UUID(body["cid"]),+ tenant_id=UUID(body["tid"]),+ choice=str(body["ch"]),+ user_ref=str(body.get("ur", "")),+ issued_at=int(body["iat"]),+ expires_at=int(body["exp"]),+ )+ except (KeyError, ValueError) as exc:+ raise ChatOpsTokenError("malformed") from exc++ current = int(now if now is not None else time.time())+ if current >= claims.expires_at:+ raise ChatOpsTokenError("expired")++ return claimsdiff --git a/services/actions/app/security/credential_vault.py b/services/actions/app/security/credential_vault.pynew file mode 100644index 000000000..80b894aea--- /dev/null+++ b/services/actions/app/security/credential_vault.py@@ -0,0 +1,144 @@+"""Vendored credential vault for the actions microservice.++Mirrors ``services/connectors/app/security/credential_vault.py`` byte-for-byte+on the cipher prefix and Fernet wire format so a token written by the API+service decrypts cleanly here. This service only needs the vault when an+action payload carries a Slack / Teams bot token persisted by the+click-and-connect connector flow.++We intentionally do not auto-generate ephemeral keys: actions is internal+infrastructure, so a missing key must fail loud.+"""++from __future__ import annotations++import logging+from collections.abc import Mapping+from threading import Lock+from typing import Any, Final++from cryptography.fernet import Fernet, InvalidToken, MultiFernet++from app.core.config import get_settings++logger = logging.getLogger("aisoc.actions.credential_vault")++# Tag every value we write so we can distinguish ciphertext from legacy+# plaintext on the decrypt path. Must match the API service's prefix byte-for-byte.+_CIPHER_PREFIX: Final[str] = "vault:v1:"+++class CredentialVaultError(RuntimeError):+ """Raised when the vault cannot encrypt/decrypt safely."""+++def _split_keys(raw: str) -> list[bytes]:+ return [k.strip().encode("ascii") for k in raw.split(",") if k.strip()]+++class CredentialVault:+ """Encrypt and decrypt connector credentials using Fernet."""++ def __init__(self, primary_key: bytes, historical_keys: list[bytes] | None = None) -> None:+ if not primary_key:+ raise CredentialVaultError("CredentialVault requires a non-empty primary key")+ try:+ primary = Fernet(primary_key)+ except (TypeError, ValueError) as exc:+ raise CredentialVaultError(f"AISOC_CREDENTIAL_KEY is not a valid Fernet key: {exc}") from exc++ keyring: list[Fernet] = [primary]+ for k in historical_keys or []:+ try:+ keyring.append(Fernet(k))+ except (TypeError, ValueError) as exc:+ logger.warning("ignoring invalid rotation key: %s", exc)++ self._fernet = MultiFernet(keyring) if len(keyring) > 1 else primary++ def encrypt(self, value: str) -> str:+ if not isinstance(value, str):+ raise CredentialVaultError(f"vault.encrypt expects str, got {type(value).__name__}")+ if value.startswith(_CIPHER_PREFIX):+ return value+ token = self._fernet.encrypt(value.encode("utf-8")).decode("ascii")+ return f"{_CIPHER_PREFIX}{token}"++ def decrypt(self, value: str) -> str:+ if not isinstance(value, str):+ raise CredentialVaultError(f"vault.decrypt expects str, got {type(value).__name__}")+ if not value.startswith(_CIPHER_PREFIX):+ return value+ token = value[len(_CIPHER_PREFIX):].encode("ascii")+ try:+ return self._fernet.decrypt(token).decode("utf-8")+ except InvalidToken as exc:+ raise CredentialVaultError(+ "ciphertext failed integrity check — likely AISOC_CREDENTIAL_KEY mismatch "+ "between API and actions services"+ ) from exc++ def encrypt_dict(self, payload: Mapping[str, Any], *, secret_keys: set[str] | None = None) -> dict[str, Any]:+ return self._walk(payload, encrypt=True, secret_keys=secret_keys)++ def decrypt_dict(self, payload: Mapping[str, Any], *, secret_keys: set[str] | None = None) -> dict[str, Any]:+ return self._walk(payload, encrypt=False, secret_keys=secret_keys)++ def _walk(+ self,+ payload: Any,+ *,+ encrypt: bool,+ secret_keys: set[str] | None,+ _key: str | None = None,+ ) -> Any:+ op = self.encrypt if encrypt else self.decrypt+ if isinstance(payload, Mapping):+ out: dict[str, Any] = {}+ for k, v in payload.items():+ if secret_keys is not None and k not in secret_keys and not isinstance(v, (Mapping, list)):+ out[k] = v+ else:+ out[k] = self._walk(v, encrypt=encrypt, secret_keys=secret_keys, _key=k)+ return out+ if isinstance(payload, list):+ return [self._walk(item, encrypt=encrypt, secret_keys=secret_keys, _key=_key) for item in payload]+ if isinstance(payload, str):+ return op(payload)+ return payload+++_vault_singleton: CredentialVault | None = None+_vault_lock = Lock()+++def get_vault() -> CredentialVault:+ """Return the process-wide vault, lazily constructed from settings.++ Raises ``CredentialVaultError`` if ``AISOC_CREDENTIAL_KEY`` is missing —+ the actions service should never silently invent an ephemeral key, since+ that would break decryption of any Slack/Teams token persisted by the API+ service.+ """+ global _vault_singleton+ if _vault_singleton is not None:+ return _vault_singleton+ with _vault_lock:+ if _vault_singleton is not None: # pragma: no cover - racing init+ return _vault_singleton+ settings = get_settings()+ primary = (settings.AISOC_CREDENTIAL_KEY or "").strip().encode("ascii")+ if not primary:+ raise CredentialVaultError(+ "AISOC_CREDENTIAL_KEY is required for the actions service to decrypt "+ "stored ChatOps credentials. Mount the same key the API service uses."+ )+ rotation = _split_keys(settings.AISOC_CREDENTIAL_KEY_ROTATION_FROM)+ _vault_singleton = CredentialVault(primary, historical_keys=rotation)+ return _vault_singleton+++def reset_vault_for_tests() -> None:+ global _vault_singleton+ with _vault_lock:+ _vault_singleton = Nonediff --git a/services/actions/app/services/chatops_prompt.py b/services/actions/app/services/chatops_prompt.pynew file mode 100644index 000000000..cd6a57e98--- /dev/null+++ b/services/actions/app/services/chatops_prompt.py@@ -0,0 +1,146 @@+"""Send the interactive ChatOps verification message.++Two transports today, mirroring how AiSOC connectors are wired:++* ``slack`` — POSTs an `Incoming Webhook+ <https://api.slack.com/messaging/webhooks>`_ payload with a Block Kit+ ``actions`` block. Buttons carry plain ``url`` links back to the actions+ service, so the user does not need a Slack app installed; any tenant+ with a webhook can use this on day one.+* ``teams`` — POSTs an `MessageCard+ <https://learn.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-reference#office-365-connector-card>`_+ with ``OpenUri`` actions. Same property: webhook-only, no bot-app+ required for the smallest install.++Bot tokens (when present) are decrypted via the shared credential vault+so an organisation that has migrated to OAuth tokens can ship them through+the same code path without re-implementing decryption.+"""++from __future__ import annotations++from dataclasses import dataclass+from typing import Any++import httpx+import structlog++from app.security.credential_vault import CredentialVaultError, get_vault++logger = structlog.get_logger()+++@dataclass(frozen=True)+class ChatOpsButton:+ label: str+ url: str+ style: str = "primary" # one of primary | danger | default+++class ChatOpsPromptError(RuntimeError):+ """Raised when the prompt can't be delivered (network / HTTP error)."""+++def _maybe_decrypt(secret: str | None) -> str | None:+ """Decrypt a vault-prefixed bot token if needed.++ Plaintext webhooks pass through untouched; vault-prefixed tokens go+ through the shared Fernet keyring. Anything else surfaces a+ ``ChatOpsPromptError`` so a misconfigured tenant fails loud rather than+ silently using a corrupted credential.+ """+ if secret is None or secret == "":+ return secret+ try:+ return get_vault().decrypt(secret)+ except CredentialVaultError as exc:+ raise ChatOpsPromptError(f"failed to decrypt ChatOps credential: {exc}") from exc+++async def send_slack_prompt(+ *,+ webhook_url: str,+ question: str,+ context: str,+ buttons: list[ChatOpsButton],+ bot_token: str | None = None,+ channel: str | None = None,+ timeout: float = 10.0,+) -> dict[str, Any]:+ """Post the interactive prompt into Slack.++ ``webhook_url`` itself may be vault-encrypted — the click-and-connect+ flow stores connector secrets that way. ``bot_token`` is accepted for+ parity with future flows that swap incoming webhooks for the Web API,+ but the default Block Kit payload below works against both.+ """+ decrypted_webhook = _maybe_decrypt(webhook_url)+ if not decrypted_webhook:+ raise ChatOpsPromptError("Slack webhook URL is empty after decryption")+ _ = _maybe_decrypt(bot_token) # validates the token decrypts; not yet used by webhooks++ elements = [+ {+ "type": "button",+ "text": {"type": "plain_text", "text": btn.label, "emoji": True},+ "url": btn.url,+ "style": btn.style if btn.style in {"primary", "danger"} else None,+ }+ for btn in buttons+ ]+ # Slack rejects ``style: null``, so strip keys that came back as None.+ elements = [{k: v for k, v in el.items() if v is not None} for el in elements]++ payload: dict[str, Any] = {+ "text": f"AiSOC verification: {question}",+ "blocks": [+ {"type": "section", "text": {"type": "mrkdwn", "text": f"*{question}*"}},+ {"type": "context", "elements": [{"type": "mrkdwn", "text": context}]},+ {"type": "actions", "elements": elements},+ ],+ }+ if channel:+ payload["channel"] = channel++ async with httpx.AsyncClient(timeout=timeout) as client:+ resp = await client.post(decrypted_webhook, json=payload)+ if resp.status_code >= 400:+ raise ChatOpsPromptError(f"Slack webhook returned HTTP {resp.status_code}: {resp.text[:200]}")+ return {"transport": "slack", "channel": channel, "status_code": resp.status_code}+++async def send_teams_prompt(+ *,+ webhook_url: str,+ question: str,+ context: str,+ buttons: list[ChatOpsButton],+ timeout: float = 10.0,+) -> dict[str, Any]:+ """Post the interactive prompt into Microsoft Teams via Connector Card."""+ decrypted_webhook = _maybe_decrypt(webhook_url)+ if not decrypted_webhook:+ raise ChatOpsPromptError("Teams webhook URL is empty after decryption")++ payload = {+ "@type": "MessageCard",+ "@context": "https://schema.org/extensions",+ "summary": f"AiSOC verification: {question}",+ "themeColor": "0078D4",+ "title": "AiSOC verification",+ "text": f"**{question}**\n\n{context}",+ "potentialAction": [+ {+ "@type": "OpenUri",+ "name": btn.label,+ "targets": [{"os": "default", "uri": btn.url}],+ }+ for btn in buttons+ ],+ }++ async with httpx.AsyncClient(timeout=timeout) as client:+ resp = await client.post(decrypted_webhook, json=payload)+ if resp.status_code >= 400:+ raise ChatOpsPromptError(f"Teams webhook returned HTTP {resp.status_code}: {resp.text[:200]}")+ return {"transport": "teams", "status_code": resp.status_code}diff --git a/services/actions/app/services/executor_registry.py b/services/actions/app/services/executor_registry.pyindex f043a4850..c6b7b536c 100644--- a/services/actions/app/services/executor_registry.py+++ b/services/actions/app/services/executor_registry.py@@ -2,6 +2,7 @@Executor registry: maps ActionType to executor implementation."""+from app.executors.chatops import ChatOpsVerifyExecutorfrom app.executors.endpoint import IsolateHostExecutor, KillProcessExecutor, QuarantineFileExecutorfrom app.executors.network import BlockDomainExecutor, BlockIPExecutorfrom app.executors.notification import CreateTicketExecutor, NotifySlackExecutor@@ -15,4 +16,5 @@ EXECUTOR_REGISTRY = {ActionType.KILL_PROCESS: KillProcessExecutor(),ActionType.NOTIFY_SLACK: NotifySlackExecutor(),ActionType.CREATE_TICKET: CreateTicketExecutor(),+ ActionType.CHATOPS_VERIFY: ChatOpsVerifyExecutor(),}diff --git a/services/actions/app/services/timeline_client.py b/services/actions/app/services/timeline_client.pynew file mode 100644index 000000000..e8b421315--- /dev/null+++ b/services/actions/app/services/timeline_client.py@@ -0,0 +1,81 @@+"""Thin client for writing into the `services/api` case timeline.++The actions service needs to post two timeline events per ChatOps verify:++* on prompt — ``"chatops.verify.prompted"`` so analysts see the question+ was asked even before the user replies,+* on response — ``"chatops.verify.responded"`` carrying the user's choice+ and a short rationale.++We keep this client deliberately tiny: one POST, no retries beyond+``httpx``'s default. If the API service is unreachable, the executor+swallows the failure into ``ActionResult.error`` rather than aborting the+ChatOps message — losing a timeline write is recoverable, losing the+outbound prompt is not.+"""++from __future__ import annotations++from typing import Any+from uuid import UUID++import httpx+import structlog++from app.core.config import get_settings++logger = structlog.get_logger()+++class TimelineClientError(RuntimeError):+ """Raised when the timeline write definitively fails (HTTP 4xx/5xx)."""+++async def post_timeline_event(+ *,+ case_id: UUID,+ event_type: str,+ content: str,+ metadata: dict[str, Any] | None = None,+ timeout: float = 10.0,+) -> dict[str, Any]:+ """Append an event to a case timeline via services/api.++ Returns the parsed response on success. The endpoint requires the+ ``cases:write`` permission, which is granted to the service token via+ its API-key scope set.+ """+ settings = get_settings()+ base = settings.AISOC_API_BASE_URL.rstrip("/")+ if not settings.AISOC_API_SERVICE_TOKEN:+ raise TimelineClientError(+ "AISOC_API_SERVICE_TOKEN is not configured; cannot write ChatOps responses to the case timeline"+ )++ url = f"{base}/api/v1/cases/{case_id}/timeline"+ payload = {+ "content": content,+ "event_type": event_type,+ "metadata": metadata or {},+ }+ headers = {+ "Authorization": f"Bearer {settings.AISOC_API_SERVICE_TOKEN}",+ "Content-Type": "application/json",+ }++ async with httpx.AsyncClient(timeout=timeout) as client:+ resp = await client.post(url, json=payload, headers=headers)++ if resp.status_code >= 400:+ logger.warning(+ "timeline write failed",+ case_id=str(case_id),+ event_type=event_type,+ status_code=resp.status_code,+ body=resp.text[:500],+ )+ raise TimelineClientError(+ f"timeline write failed: HTTP {resp.status_code} — {resp.text[:200]}"+ )++ return resp.json()diff --git a/services/actions/pyproject.toml b/services/actions/pyproject.tomlindex 46cd832d8..0a27c28da 100644--- a/services/actions/pyproject.toml+++ b/services/actions/pyproject.toml@@ -18,6 +18,7 @@ structlog = "^24.1.0"httpx = "^0.26.0"aiokafka = "^0.10.0"python-dateutil = "^2.8.2"+cryptography = "^42.0.0"[tool.poetry.group.dev.dependencies]pytest = "^7.4.0"diff --git a/services/actions/tests/test_chatops_token.py b/services/actions/tests/test_chatops_token.pynew file mode 100644index 000000000..f591163c9--- /dev/null+++ b/services/actions/tests/test_chatops_token.py@@ -0,0 +1,127 @@+"""Round-trip tests for the ChatOps callback HMAC tokens.++This module is security-critical: the only thing protecting the callback+endpoint from forged "the user said yes" responses is the signature on+these tokens. Every check below is here because if it silently regresses,+a malicious chat user could acknowledge prompts that were never sent to+them, suppressing legitimate alerts.+"""++from __future__ import annotations++import time+from uuid import uuid4++import pytest+from app.security.chatops_token import (+ ChatOpsTokenError,+ mint_token,+ verify_token,+)++_SECRET = "test-secret-do-not-use-in-prod"+++def _mint(**overrides):+ """Mint a token with sensible defaults so individual tests can override+ only the field they care about."""+ base = {+ "action_id": uuid4(),+ "case_id": uuid4(),+ "tenant_id": uuid4(),+ "choice": "acknowledge",+ "user_ref": "[email protected]",+ "secret": _SECRET,+ "ttl_seconds": 900,+ }+ base.update(overrides)+ return base, mint_token(**base)+++def test_round_trip_returns_original_claims():+ args, token = _mint()+ claims = verify_token(token, _SECRET)+ assert claims.action_id == args["action_id"]+ assert claims.case_id == args["case_id"]+ assert claims.tenant_id == args["tenant_id"]+ assert claims.choice == "acknowledge"+ assert claims.user_ref == "[email protected]"+ assert claims.expires_at > claims.issued_at+++def test_tampered_payload_fails_signature():+ _, token = _mint()+ payload, sig = token.split(".", 1)+ # Flip a single character in the payload — should invalidate HMAC.+ tampered_payload = payload[:-1] + ("A" if payload[-1] != "A" else "B")+ with pytest.raises(ChatOpsTokenError, match="invalid_signature"):+ verify_token(f"{tampered_payload}.{sig}", _SECRET)+++def test_wrong_secret_fails_signature():+ _, token = _mint()+ with pytest.raises(ChatOpsTokenError, match="invalid_signature"):+ verify_token(token, "different-secret")+++def test_expired_token_is_rejected():+ _, token = _mint(ttl_seconds=1)+ # Verify in the future, past the TTL.+ with pytest.raises(ChatOpsTokenError, match="expired"):+ verify_token(token, _SECRET, now=int(time.time()) + 5)+++def test_unsupported_choice_is_rejected_at_mint_time():+ """Tokens for unknown choices never get minted, so the callback handler+ never has to make a policy call about how to log them."""+ with pytest.raises(ChatOpsTokenError, match="unsupported choice"):+ mint_token(+ action_id=uuid4(),+ case_id=uuid4(),+ tenant_id=uuid4(),+ choice="confirm-everything", # not in the allowed set+ user_ref="alice",+ secret=_SECRET,+ ttl_seconds=900,+ )+++def test_missing_secret_at_mint_or_verify_is_rejected():+ with pytest.raises(ChatOpsTokenError):+ mint_token(+ action_id=uuid4(),+ case_id=uuid4(),+ tenant_id=uuid4(),+ choice="deny",+ user_ref="alice",+ secret="",+ ttl_seconds=900,+ )+ _, token = _mint()+ with pytest.raises(ChatOpsTokenError):+ verify_token(token, "")+++def test_malformed_token_fails_clean():+ with pytest.raises(ChatOpsTokenError, match="malformed"):+ verify_token("not-a-valid-token", _SECRET)+ with pytest.raises(ChatOpsTokenError, match="malformed"):+ verify_token("a.b.c", _SECRET)+++def test_each_choice_produces_distinct_tokens():+ """Defensive: same action+case but different choice must produce+ different signatures. Otherwise the callback can't tell which button+ the user pressed."""+ base = {+ "action_id": uuid4(),+ "case_id": uuid4(),+ "tenant_id": uuid4(),+ "user_ref": "alice",+ "secret": _SECRET,+ "ttl_seconds": 900,+ }+ ack = mint_token(choice="acknowledge", **base)+ deny = mint_token(choice="deny", **base)+ escalate = mint_token(choice="escalate", **base)+ assert len({ack, deny, escalate}) == 3diff --git a/services/agents/Dockerfile b/services/agents/Dockerfileindex 9e996410e..dcb42a07e 100644--- a/services/agents/Dockerfile+++ b/services/agents/Dockerfile@@ -47,12 +47,14 @@ RUN set -eux; \"opentelemetry-instrumentation-fastapi>=0.45b0" \"opentelemetry-instrumentation-httpx>=0.45b0" \"asyncpg>=0.29,<0.30" \- "sqlalchemy[asyncio]>=2.0.25,<3" ; \+ "sqlalchemy[asyncio]>=2.0.25,<3" \+ "apscheduler>=3.10.4,<4" \+ "pyyaml>=6.0.1,<7" ; \fi# Smoke-import the modules the orchestrator pulls in at module load time.# Catches "image built but broken" cases at build time instead of runtime.-RUN python -c "import opentelemetry, langgraph, fastapi, sqlalchemy, asyncpg, redis, httpx, structlog"+RUN python -c "import opentelemetry, langgraph, fastapi, sqlalchemy, asyncpg, redis, httpx, structlog, apscheduler, yaml"COPY app/ ./app/diff --git a/services/agents/app/api/hunts.py b/services/agents/app/api/hunts.pynew file mode 100644index 000000000..cbd2da322--- /dev/null+++ b/services/agents/app/api/hunts.py@@ -0,0 +1,126 @@+"""Hunt-as-code REST API (Wave 2 — w2-hac).++Endpoints:++* ``GET /api/v1/hunts`` — list YAML corpus+* ``GET /api/v1/hunts/{hunt_id}`` — single hunt definition+* ``POST /api/v1/hunts/{hunt_id}/run`` — run a hunt on demand+* ``GET /api/v1/hunts/runs`` — recent runs (DB-backed)+* ``GET /api/v1/hunts/findings`` — recent findings (DB-backed,+ filterable by ``hunt_id`` /+ ``status``)+* ``POST /api/v1/hunts/reload`` — reload the corpus from disk+ and re-sync the catalog table++The corpus itself is the source of truth; the database tables exist so the+console can list runs/findings without re-reading every YAML on every+request. All write paths are best-effort: if the database is unreachable+the endpoint still returns the in-memory result so an operator can run a+hunt during a DB outage.+"""++from __future__ import annotations++import logging+from typing import Any++from fastapi import APIRouter, HTTPException, Query++from app.hunt import HuntCorpus+from app.hunt import scheduler as hunt_scheduler+from app.hunt import store as hunt_store++logger = logging.getLogger("aisoc.api.hunts")+router = APIRouter(prefix="/api/v1/hunts", tags=["hunts"])+++def _hunt_summary(h: Any) -> dict[str, Any]:+ """Trim a HuntDefinition into a console-friendly dict."""+ return {+ "id": h.id,+ "name": h.name,+ "description": h.description,+ "version": h.version,+ "severity": h.severity,+ "category": h.category,+ "tags": list(h.tags),+ "log_sources": list(h.log_sources),+ "schedule": {+ "enabled": h.schedule.enabled,+ "interval_minutes": h.schedule.interval_minutes,+ "jitter_seconds": h.schedule.jitter_seconds,+ },+ "hypothesis": h.hypothesis.model_dump(by_alias=True),+ "expected": h.expected.model_dump(),+ "references": list(h.references),+ "author": h.author,+ "source_sha256": h.source_sha256,+ "source_path": h.source_path,+ }+++# ---------------------------------------------------------------------------+# Corpus+# ---------------------------------------------------------------------------++[email protected]("", summary="List hunts in the YAML corpus")+async def list_hunts() -> list[dict[str, Any]]:+ corpus = HuntCorpus.default()+ return [_hunt_summary(h) for h in corpus.list()]++[email protected]("/{hunt_id}", summary="Get a single hunt definition")+async def get_hunt(hunt_id: str) -> dict[str, Any]:+ corpus = HuntCorpus.default()+ h = corpus.get(hunt_id)+ if h is None:+ raise HTTPException(status_code=404, detail=f"hunt {hunt_id} not found")+ return _hunt_summary(h)++[email protected]("/reload", summary="Reload corpus from disk + re-sync catalog")+async def reload_hunts() -> dict[str, Any]:+ corpus = HuntCorpus.default()+ count = corpus.reload()+ synced = await hunt_store.sync_catalog(corpus.list())+ return {"loaded": count, "synced": synced}+++# ---------------------------------------------------------------------------+# Run on demand+# ---------------------------------------------------------------------------++[email protected]("/{hunt_id}/run", summary="Run a hunt on demand")+async def run_hunt(hunt_id: str) -> dict[str, Any]:+ sched = hunt_scheduler.get_scheduler()+ out = await sched.run_one(hunt_id)+ if not out.get("ok"):+ raise HTTPException(+ status_code=404, detail=out.get("error", "hunt run failed")+ )+ return out+++# ---------------------------------------------------------------------------+# Read-side (DB-backed)+# ---------------------------------------------------------------------------++[email protected]("/runs", summary="Recent hunt runs")+async def list_runs(+ limit: int = Query(default=50, ge=1, le=500),+) -> list[dict[str, Any]]:+ return await hunt_store.list_recent_runs(limit=limit)++[email protected]("/findings", summary="Recent hunt findings")+async def list_findings(+ hunt_id: str | None = Query(default=None),+ status: str | None = Query(default=None),+ limit: int = Query(default=100, ge=1, le=500),+) -> list[dict[str, Any]]:+ return await hunt_store.list_recent_findings(+ hunt_id=hunt_id, status=status, limit=limit+ )diff --git a/services/agents/app/hunt/__init__.py b/services/agents/app/hunt/__init__.pynew file mode 100644index 000000000..fc0955717--- /dev/null+++ b/services/agents/app/hunt/__init__.py@@ -0,0 +1,27 @@+"""Hunt-as-code module (Wave 2 — w2-hac).++Loads YAML hunt hypotheses from the repo's ``hunts/`` corpus, runs them on a+schedule against the synthetic telemetry corpus (in dev) or the live event+warehouse (in prod), and persists hunt runs + findings as first-class+artifacts alongside the Investigation Ledger.++The public surface is intentionally thin:++* :class:`HuntCorpus` — load + access the YAML corpus+* :class:`HuntEngine` — match indicators against telemetry events+* :class:`HuntScheduler` — APScheduler-driven continuous runner+* :mod:`store` — persistence helpers (``hunt_runs`` / ``hunt_findings``)+"""++from __future__ import annotations++from .engine import HuntEngine, HuntFindingDraft, HuntRunResult+from .loader import HuntCorpus, HuntDefinition++__all__ = [+ "HuntCorpus",+ "HuntDefinition",+ "HuntEngine",+ "HuntFindingDraft",+ "HuntRunResult",+]diff --git a/services/agents/app/hunt/engine.py b/services/agents/app/hunt/engine.pynew file mode 100644index 000000000..83914cbe3--- /dev/null+++ b/services/agents/app/hunt/engine.py@@ -0,0 +1,236 @@+"""Hunt engine — match YAML hypotheses against a stream of events.++The engine is intentionally small and deterministic so it can run inside the+eval harness without a live event warehouse. ``run`` takes any iterable of+JSON-shaped events (one per row) and returns a :class:`HuntRunResult`+containing the findings the indicators matched.+"""++from __future__ import annotations++import logging+import re+from collections.abc import Iterable+from dataclasses import dataclass, field+from typing import Any++from .loader import HuntDefinition, HuntIndicator++logger = logging.getLogger("aisoc.hunt.engine")+++# ---------------------------------------------------------------------------+# Result types+# ---------------------------------------------------------------------------+++@dataclass+class HuntFindingDraft:+ """A single hunt match. Persisted via ``store.record_finding``."""++ hunt_id: str+ severity: str+ title: str+ summary: str+ evidence: dict[str, Any]+ primary_entity: str | None+ primary_log_source: str | None+ match_score: float+ mitre_techniques: list[str] = field(default_factory=list)+++@dataclass+class HuntRunResult:+ hunt_id: str+ events_scanned: int+ findings: list[HuntFindingDraft]+ match_score: float # 0.0..1.0 — best individual match in this run+ error: str | None = None+++# ---------------------------------------------------------------------------+# Indicator matching+# ---------------------------------------------------------------------------+++def _get_field(event: dict[str, Any], dotted: str) -> Any:+ """Resolve ``a.b.c`` against an event dict; missing keys -> ``None``."""+ cur: Any = event+ for part in dotted.split("."):+ if isinstance(cur, dict) and part in cur:+ cur = cur[part]+ else:+ return None+ return cur+++def _coerce_number(value: Any) -> float | None:+ if isinstance(value, bool): # bool is a subclass of int — exclude on purpose+ return None+ if isinstance(value, (int, float)):+ return float(value)+ if isinstance(value, str):+ try:+ return float(value)+ except ValueError:+ return None+ return None+++def _indicator_matches(event: dict[str, Any], ind: HuntIndicator) -> bool:+ val = _get_field(event, ind.field)++ if ind.exists is not None:+ present = val is not None+ return present == ind.exists++ if val is None:+ return False++ if ind.equals is not None:+ return val == ind.equals++ if ind.in_ is not None:+ return val in ind.in_++ if ind.regex is not None:+ try:+ return re.search(ind.regex, str(val)) is not None+ except re.error:+ return False++ if ind.gte is not None:+ num = _coerce_number(val)+ return num is not None and num >= ind.gte++ if ind.lte is not None:+ num = _coerce_number(val)+ return num is not None and num <= ind.lte++ if ind.contains_any is not None:+ if isinstance(val, (list, tuple, set)):+ haystack = list(val)+ else:+ haystack = [val]+ return any(needle in haystack for needle in ind.contains_any)++ if ind.iendswith is not None:+ return str(val).lower().endswith(ind.iendswith.lower())++ # Indicator with only a ``field`` is treated as ``exists: true``.+ return True+++def _match_event(event: dict[str, Any], hunt: HuntDefinition) -> tuple[bool, float]:+ """Return ``(matched, score)`` for one event against one hunt.++ Score is the fraction of indicators that fired. A hunt with zero+ indicators is treated as a no-op and never matches.+ """+ indicators = hunt.hypothesis.indicators+ if not indicators:+ return False, 0.0+ hits = sum(1 for ind in indicators if _indicator_matches(event, ind))+ score = hits / len(indicators)+ matched = hits == len(indicators)+ return matched, score+++# ---------------------------------------------------------------------------+# Engine+# ---------------------------------------------------------------------------+++_PRIMARY_ENTITY_FIELDS = (+ "TargetUserName",+ "user_name",+ "user",+ "principalEmail",+ "actor",+ "actor.id",+ "src_ip",+ "src",+ "asset_id",+ "computer_name",+ "host",+ "user_id",+)+++def _pick_primary_entity(event: dict[str, Any]) -> str | None:+ for f in _PRIMARY_ENTITY_FIELDS:+ v = _get_field(event, f)+ if v:+ return str(v)+ return None+++def _pick_log_source(event: dict[str, Any], hunt: HuntDefinition) -> str | None:+ src = event.get("source") or event.get("log_source")+ if src:+ return str(src)+ return hunt.log_sources[0] if hunt.log_sources else None+++class HuntEngine:+ """Stateless matcher. ``run`` iterates events once and returns findings."""++ def __init__(self, *, max_findings_per_run: int = 50) -> None:+ self._cap = max_findings_per_run++ def run(+ self,+ hunt: HuntDefinition,+ events: Iterable[dict[str, Any]],+ ) -> HuntRunResult:+ findings: list[HuntFindingDraft] = []+ events_scanned = 0+ best_score = 0.0++ for event in events:+ events_scanned += 1+ matched, score = _match_event(event, hunt)+ if score > best_score:+ best_score = score+ if not matched:+ continue+ if len(findings) >= self._cap:+ continue+ findings.append(self._draft_finding(hunt, event, score))++ return HuntRunResult(+ hunt_id=hunt.id,+ events_scanned=events_scanned,+ findings=findings,+ match_score=best_score,+ )++ def _draft_finding(+ self,+ hunt: HuntDefinition,+ event: dict[str, Any],+ score: float,+ ) -> HuntFindingDraft:+ primary_entity = _pick_primary_entity(event)+ log_source = _pick_log_source(event, hunt)+ title = (+ f"{hunt.name} matched {primary_entity}"+ if primary_entity+ else hunt.name+ )+ summary = hunt.hypothesis.question.strip() or hunt.description.strip() or hunt.name+ return HuntFindingDraft(+ hunt_id=hunt.id,+ severity=hunt.severity,+ title=title,+ summary=summary,+ evidence={+ "matched_event": event,+ "indicators": [ind.model_dump(by_alias=True) for ind in hunt.hypothesis.indicators],+ "match_score": round(score, 3),+ },+ primary_entity=primary_entity,+ primary_log_source=log_source,+ match_score=round(score, 3),+ mitre_techniques=hunt.mitre_techniques,+ )diff --git a/services/agents/app/hunt/loader.py b/services/agents/app/hunt/loader.pynew file mode 100644index 000000000..14beebaf7--- /dev/null+++ b/services/agents/app/hunt/loader.py@@ -0,0 +1,226 @@+"""Hunt YAML loader.++Reads the ``hunts/`` corpus from disk into typed Pydantic models. The loader+is best-effort: invalid hunts are logged and skipped so a single bad YAML+file cannot take down the scheduler.+"""++from __future__ import annotations++import hashlib+import logging+import os+from pathlib import Path+from typing import Any++import yaml+from pydantic import BaseModel, Field, ValidationError++logger = logging.getLogger("aisoc.hunt.loader")+++# ---------------------------------------------------------------------------+# Pydantic models — the YAML schema (mirrors hunts/README.md)+# ---------------------------------------------------------------------------+++class HuntSchedule(BaseModel):+ enabled: bool = True+ interval_minutes: int = 60+ jitter_seconds: int = 60+++class HuntIndicator(BaseModel):+ """One indicator in ``hypothesis.indicators``.++ Mirrors the YAML shape; only one of+ ``equals|in|regex|gte|lte|exists|contains_any|iendswith`` is expected to+ be set per row, but we stay permissive so authors can chain them when+ needed.+ """++ field: str+ equals: Any | None = None+ in_: list[Any] | None = Field(default=None, alias="in")+ regex: str | None = None+ gte: float | None = None+ lte: float | None = None+ exists: bool | None = None+ # Array intersection: indicator fires when any of these values is present in+ # the (list-typed) event field. Used for OAuth scope / tag matching.+ contains_any: list[Any] | None = None+ # Case-insensitive string suffix match. Used for executable paths (e.g.+ # ``\\rundll32.exe``) where the engine should not care about case or+ # parent directories.+ iendswith: str | None = None++ model_config = {"populate_by_name": True}+++class HuntHypothesisBlock(BaseModel):+ question: str = ""+ indicators: list[HuntIndicator] = Field(default_factory=list)+++class HuntExpected(BaseModel):+ """Eval-grading expectations: which synthetic incident the hunt should+ fire on, which it must NOT fire on, and the minimum match score."""++ positive_incident_id: str | None = None+ positive_template_id: str | None = None+ negative_incident_id: str | None = None+ min_match_score: float = 0.8+++class HuntDefinition(BaseModel):+ id: str+ name: str+ description: str = ""+ version: str = "1.0.0"+ severity: str = "medium"+ category: str = "other"+ tags: list[str] = Field(default_factory=list)+ log_sources: list[str] = Field(default_factory=list)+ schedule: HuntSchedule = Field(default_factory=HuntSchedule)+ hypothesis: HuntHypothesisBlock = Field(default_factory=HuntHypothesisBlock)+ expected: HuntExpected = Field(default_factory=HuntExpected)+ references: list[str] = Field(default_factory=list)+ author: str | None = None++ # Computed at load time so callers can detect when the YAML body changed+ # and re-sync the database catalog row.+ source_sha256: str | None = None+ source_path: str | None = None++ @property+ def mitre_techniques(self) -> list[str]:+ """Pull MITRE technique IDs out of ``tags`` (e.g. ``mitre.attack.t1078``).++ Tags are stored as lowercase slugs; we normalise to ``T1078.002``-style+ identifiers because that's what the rest of the platform speaks.+ """+ techniques: list[str] = []+ for tag in self.tags:+ t = tag.strip().lower()+ if not t.startswith("mitre.attack."):+ continue+ tech = t.removeprefix("mitre.attack.")+ # ``t1078.002`` -> ``T1078.002``+ techniques.append(tech.upper())+ return techniques+++# ---------------------------------------------------------------------------+# Corpus+# ---------------------------------------------------------------------------+++def _resolve_corpus_dir() -> Path:+ """Find the ``hunts/`` directory.++ Honours ``AISOC_HUNTS_DIR`` first, then walks parents of this file looking+ for a sibling ``hunts/`` (matches the playbook ``_resolve_repo_root`` trick+ so this works both on the host and inside the agents Docker image).+ """+ env_dir = os.getenv("AISOC_HUNTS_DIR", "").strip()+ if env_dir:+ return Path(env_dir).expanduser().resolve()+ here = Path(__file__).resolve()+ for candidate in here.parents:+ d = candidate / "hunts"+ if d.is_dir():+ return d+ # Fall back to the conventional host layout (parents[4]/hunts).+ parents = list(here.parents)+ if len(parents) > 4:+ return parents[4] / "hunts"+ return Path("hunts").resolve()+++class HuntCorpus:+ """In-memory cache of hunt definitions loaded from disk.++ Hot-reload is intentional: ``reload()`` re-reads every YAML file. The+ scheduler calls it on a slow timer so authors can edit hunts without+ bouncing the agents service.+ """++ _instance: HuntCorpus | None = None++ def __init__(self, corpus_dir: Path | None = None) -> None:+ self._dir: Path = corpus_dir or _resolve_corpus_dir()+ self._hunts: dict[str, HuntDefinition] = {}++ @classmethod+ def default(cls) -> HuntCorpus:+ if cls._instance is None:+ cls._instance = cls()+ cls._instance.reload()+ return cls._instance++ @property+ def directory(self) -> Path:+ return self._dir++ def list(self, *, enabled_only: bool = False) -> list[HuntDefinition]:+ hunts = list(self._hunts.values())+ if enabled_only:+ hunts = [h for h in hunts if h.schedule.enabled]+ return sorted(hunts, key=lambda h: h.id)++ def get(self, hunt_id: str) -> HuntDefinition | None:+ return self._hunts.get(hunt_id)++ def reload(self) -> int:+ """Re-read every YAML file under ``hunts/``. Returns the number loaded."""+ if not self._dir.exists():+ logger.warning("hunt.corpus.missing", extra={"dir": str(self._dir)})+ self._hunts = {}+ return 0+ loaded: dict[str, HuntDefinition] = {}+ for path in sorted(self._dir.glob("*.yaml")):+ hunt = self._load_one(path)+ if hunt is None:+ continue+ if hunt.id in loaded:+ logger.warning(+ "hunt.corpus.duplicate_id",+ extra={"hunt_id": hunt.id, "path": str(path)},+ )+ continue+ loaded[hunt.id] = hunt+ self._hunts = loaded+ logger.info(+ "hunt.corpus.loaded",+ extra={"count": len(loaded), "dir": str(self._dir)},+ )+ return len(loaded)++ def _load_one(self, path: Path) -> HuntDefinition | None:+ try:+ raw = path.read_text(encoding="utf-8")+ except OSError as exc:+ logger.warning("hunt.corpus.read_failed", extra={"path": str(path), "error": str(exc)})+ return None++ try:+ data = yaml.safe_load(raw) or {}+ except yaml.YAMLError as exc:+ logger.warning("hunt.corpus.invalid_yaml", extra={"path": str(path), "error": str(exc)})+ return None++ if not isinstance(data, dict):+ logger.warning("hunt.corpus.invalid_root", extra={"path": str(path)})+ return None++ try:+ hunt = HuntDefinition.model_validate(data)+ except ValidationError as exc:+ logger.warning(+ "hunt.corpus.validation_failed",+ extra={"path": str(path), "error": exc.errors()},+ )+ return None++ sha = hashlib.sha256(raw.encode("utf-8")).hexdigest()+ return hunt.model_copy(update={"source_sha256": sha, "source_path": str(path)})diff --git a/services/agents/app/hunt/scheduler.py b/services/agents/app/hunt/scheduler.pynew file mode 100644index 000000000..24f350771--- /dev/null+++ b/services/agents/app/hunt/scheduler.py@@ -0,0 +1,267 @@+"""Continuous hunt scheduler (Wave 2 — w2-hac).++Runs the YAML hunt corpus on the cadence declared per hunt. Each tick:++1. Loads (or reloads) the corpus from disk.+2. For each enabled hunt whose interval has elapsed, pulls a slice of recent+ telemetry, hands events to :class:`HuntEngine`, and persists the run ++ findings via :mod:`app.hunt.store`.+3. Sleeps until the next due hunt.++Telemetry source resolution — in priority order:++* ``HUNT_TELEMETRY_PROVIDER`` env var set to ``synthetic`` (the default in+ dev/CI) reads from+ ``services/agents/tests/eval_data/synthetic_telemetry.jsonl`` and treats+ each line as a discrete event. This is what the substrate eval uses and+ is what the public benchmark scoreboard scores against.+* ``ingest`` is a placeholder for the live event warehouse path; it+ returns an empty stream until the federated-search layer (Wave 3 —+ w3-fed) lands. This keeps the scheduler safe to leave running in+ production: it records an empty run rather than crashing.++The scheduler is feature-flagged via ``AISOC_FEATURE_HUNT_AS_CODE``. The+caller (``app/main.py``) wires it into the FastAPI lifespan so it starts+on app boot and stops cleanly on shutdown.+"""++from __future__ import annotations++import json+import os+import time+from pathlib import Path+from typing import Any++import structlog+from apscheduler.schedulers.asyncio import AsyncIOScheduler+from apscheduler.triggers.interval import IntervalTrigger++from .engine import HuntEngine+from .loader import HuntCorpus, HuntDefinition+from .store import record_run, sync_catalog++logger = structlog.get_logger()+++# How often the scheduler wakes up to check for due hunts. Individual hunts+# declare their own ``interval_minutes`` and we honour that — this is just+# the polling cadence of the dispatch loop.+_TICK_SECONDS = int(os.environ.get("HUNT_SCHEDULER_TICK_SECONDS", "60"))+++class HuntScheduler:+ """APScheduler-driven runner for the YAML hunt corpus."""++ JOB_ID = "hunt-scheduler-tick"++ def __init__(+ self,+ *,+ corpus: HuntCorpus | None = None,+ engine: HuntEngine | None = None,+ tick_seconds: int = _TICK_SECONDS,+ tenant_ref: str = "default",+ ) -> None:+ self._corpus = corpus or HuntCorpus.default()+ self._engine = engine or HuntEngine()+ self._tick_seconds = tick_seconds+ self._tenant_ref = tenant_ref+ self._scheduler = AsyncIOScheduler()+ # Tracks last run time per hunt id so we don't re-run more often+ # than the hunt's declared interval.+ self._last_run: dict[str, float] = {}++ # ------------------------------------------------------------------+ # Lifecycle+ # ------------------------------------------------------------------++ async def start(self) -> None:+ if self._tick_seconds <= 0:+ logger.info("hunt.scheduler.disabled", reason="tick<=0")+ return++ # Reload + sync the corpus on boot so the catalog table is current.+ try:+ count = self._corpus.reload()+ logger.info("hunt.scheduler.corpus_loaded", count=count)+ await sync_catalog(self._corpus.list(), tenant_ref=self._tenant_ref)+ except Exception as exc: # noqa: BLE001+ logger.warning("hunt.scheduler.corpus_load_failed", error=str(exc))++ self._scheduler.add_job(+ func=self._tick,+ trigger=IntervalTrigger(seconds=self._tick_seconds),+ id=self.JOB_ID,+ name="Hunt-as-code dispatch",+ replace_existing=True,+ max_instances=1,+ coalesce=True,+ )+ if not self._scheduler.running:+ self._scheduler.start()+ logger.info("hunt.scheduler.started", tick_seconds=self._tick_seconds)++ async def stop(self) -> None:+ if self._scheduler.running:+ self._scheduler.shutdown(wait=False)+ logger.info("hunt.scheduler.stopped")++ # ------------------------------------------------------------------+ # Dispatch+ # ------------------------------------------------------------------++ async def _tick(self) -> None:+ """Run every hunt whose interval has elapsed since its last run."""+ now = time.time()+ events = _load_telemetry() # one shared snapshot per tick++ for hunt in self._corpus.list():+ if not hunt.schedule.enabled:+ continue+ interval = max(60, hunt.schedule.interval_minutes * 60)+ last = self._last_run.get(hunt.id)+ if last is not None and (now - last) < interval:+ continue+ try:+ await self._run_hunt(hunt, events)+ except Exception as exc: # noqa: BLE001+ logger.warning(+ "hunt.scheduler.run_failed", hunt_id=hunt.id, error=str(exc)+ )+ finally:+ self._last_run[hunt.id] = now++ async def _run_hunt(+ self, hunt: HuntDefinition, events: list[dict[str, Any]]+ ) -> None:+ result = self._engine.run(hunt, events)+ await record_run(+ hunt,+ result,+ tenant_ref=self._tenant_ref,+ trigger_source="scheduler",+ )+ logger.info(+ "hunt.scheduler.completed",+ hunt_id=hunt.id,+ events_scanned=result.events_scanned,+ findings=len(result.findings),+ match_score=round(result.match_score, 3),+ )++ # ------------------------------------------------------------------+ # Manual trigger (used by the API)+ # ------------------------------------------------------------------++ async def run_one(self, hunt_id: str) -> dict[str, Any]:+ """Run a single hunt on demand. Returns a summary dict."""+ hunt = self._corpus.get(hunt_id)+ if hunt is None:+ return {"ok": False, "error": f"hunt {hunt_id} not found"}+ result = self._engine.run(hunt, _load_telemetry())+ await record_run(+ hunt,+ result,+ tenant_ref=self._tenant_ref,+ trigger_source="manual",+ )+ self._last_run[hunt.id] = time.time()+ return {+ "ok": True,+ "hunt_id": hunt.id,+ "events_scanned": result.events_scanned,+ "findings": len(result.findings),+ "match_score": round(result.match_score, 3),+ }+++# ---------------------------------------------------------------------------+# Telemetry loaders+# ---------------------------------------------------------------------------+++def _load_telemetry() -> list[dict[str, Any]]:+ """Resolve and load events according to ``HUNT_TELEMETRY_PROVIDER``.++ Defaults to ``synthetic`` so the scheduler is useful out of the box —+ that's also what the public benchmark scoreboard scores hunts against.+ """+ provider = os.environ.get("HUNT_TELEMETRY_PROVIDER", "synthetic").strip().lower()+ if provider == "synthetic":+ return _load_synthetic_events()+ if provider == "ingest":+ # Live event-warehouse path is wired up by the federated search work+ # in Wave 3 (w3-fed). Until then the scheduler records empty runs+ # rather than crashing — that's deliberate, it lets ops watch the+ # job heartbeat without faking findings.+ return []+ logger.warning("hunt.telemetry.unknown_provider", provider=provider)+ return []+++_SYNTHETIC_PATH_OVERRIDE = "HUNT_SYNTHETIC_TELEMETRY_PATH"+++def _resolve_synthetic_path() -> Path | None:+ override = os.environ.get(_SYNTHETIC_PATH_OVERRIDE, "").strip()+ if override:+ p = Path(override)+ return p if p.exists() else None++ # Walk up from this file: services/agents/app/hunt/scheduler.py+ here = Path(__file__).resolve()+ candidates = [+ here.parents[2] / "tests" / "eval_data" / "synthetic_telemetry.jsonl",+ here.parents[3] / "services" / "agents" / "tests" / "eval_data" / "synthetic_telemetry.jsonl",+ ]+ for c in candidates:+ if c.exists():+ return c+ return None+++def _load_synthetic_events() -> list[dict[str, Any]]:+ path = _resolve_synthetic_path()+ if path is None:+ logger.debug("hunt.telemetry.synthetic.missing")+ return []+ events: list[dict[str, Any]] = []+ try:+ with path.open("r", encoding="utf-8") as fh:+ for line in fh:+ line = line.strip()+ if not line:+ continue+ try:+ events.append(json.loads(line))+ except json.JSONDecodeError:+ continue+ except OSError as exc:+ logger.warning("hunt.telemetry.synthetic.read_failed", error=str(exc))+ return []+ return events+++# Singleton — set up by ``app.main`` on startup so the API router can call+# ``run_one`` without re-instantiating.+_INSTANCE: HuntScheduler | None = None+++def get_scheduler() -> HuntScheduler:+ global _INSTANCE+ if _INSTANCE is None:+ _INSTANCE = HuntScheduler()+ return _INSTANCE+++async def start_scheduler() -> HuntScheduler:+ sched = get_scheduler()+ await sched.start()+ return sched+++async def stop_scheduler() -> None:+ global _INSTANCE+ if _INSTANCE is not None:+ await _INSTANCE.stop()diff --git a/services/agents/app/hunt/store.py b/services/agents/app/hunt/store.pynew file mode 100644index 000000000..9fb8d40eb--- /dev/null+++ b/services/agents/app/hunt/store.py@@ -0,0 +1,348 @@+"""Hunt persistence — best-effort writes to ``hunt_hypotheses`` /+``hunt_runs`` / ``hunt_findings``.++Mirrors :mod:`app.investigator.ledger`: raw asyncpg, lazy-initialised pool,+RLS context set on every connection, all writes wrapped so a database+outage never takes the scheduler offline.+"""++from __future__ import annotations++import json+import os+import uuid+from typing import Any++import asyncpg+import structlog++from .engine import HuntFindingDraft, HuntRunResult+from .loader import HuntDefinition++logger = structlog.get_logger()+++_POOL: asyncpg.Pool | None = None+++def _normalise_dsn(url: str) -> str:+ return url.replace("postgresql+asyncpg://", "postgresql://").replace(+ "postgres+asyncpg://", "postgresql://"+ )+++async def _get_pool() -> asyncpg.Pool | None:+ global _POOL+ if _POOL is not None:+ return _POOL+ dsn = os.environ.get("DATABASE_URL", "").strip()+ if not dsn:+ logger.debug("hunt.store.disabled", reason="DATABASE_URL not set")+ return None+ try:+ _POOL = await asyncpg.create_pool(+ dsn=_normalise_dsn(dsn),+ min_size=1,+ max_size=4,+ command_timeout=10,+ )+ logger.info("hunt.store.pool_initialised")+ return _POOL+ except Exception as exc: # noqa: BLE001+ logger.warning("hunt.store.pool_init_failed", error=str(exc))+ return None+++async def close_pool() -> None:+ global _POOL+ if _POOL is not None:+ await _POOL.close()+ _POOL = None+++async def _resolve_tenant_id(conn: asyncpg.Connection, tenant_ref: str) -> uuid.UUID | None:+ try:+ return uuid.UUID(tenant_ref)+ except (ValueError, TypeError):+ pass+ row = await conn.fetchrow(+ "SELECT id FROM tenants WHERE slug = $1 OR name = $1 LIMIT 1",+ tenant_ref,+ )+ return row["id"] if row else None+++async def _set_rls_context(conn: asyncpg.Connection, tenant_id: uuid.UUID) -> None:+ await conn.execute("SELECT set_config('app.tenant_id', $1, true)", str(tenant_id))+++# ---------------------------------------------------------------------------+# Catalog sync — keep ``hunt_hypotheses`` table in sync with the YAML corpus+# ---------------------------------------------------------------------------+++async def sync_catalog(+ hunts: list[HuntDefinition],+ *,+ tenant_ref: str = "default",+) -> int:+ """Upsert each YAML hunt into the ``hunt_hypotheses`` table.++ The hunts directory is the source of truth; the database row is just a+ cache so the API/UI can list and inspect hunts without re-reading the+ filesystem on every request. Returns the number of rows touched.+ """+ pool = await _get_pool()+ if pool is None or not hunts:+ return 0++ touched = 0+ try:+ async with pool.acquire() as conn:+ tenant_id = await _resolve_tenant_id(conn, tenant_ref)+ if tenant_id is None:+ logger.debug(+ "hunt.store.catalog.skip", reason="unknown_tenant", tenant_ref=tenant_ref+ )+ return 0+ await _set_rls_context(conn, tenant_id)++ for hunt in hunts:+ await conn.execute(+ """+ INSERT INTO hunt_hypotheses+ (tenant_id, hunt_id, name, description, version,+ severity, category, tags, log_sources,+ schedule_enabled, interval_minutes, jitter_seconds,+ hypothesis, expected, refs, author, source_sha256,+ created_at, updated_at)+ VALUES+ ($1, $2, $3, $4, $5,+ $6, $7, $8::text[], $9::text[],+ $10, $11, $12,+ $13::jsonb, $14::jsonb, $15::text[], $16, $17,+ NOW(), NOW())+ ON CONFLICT (tenant_id, hunt_id) DO UPDATE SET+ name = EXCLUDED.name,+ description = EXCLUDED.description,+ version = EXCLUDED.version,+ severity = EXCLUDED.severity,+ category = EXCLUDED.category,+ tags = EXCLUDED.tags,+ log_sources = EXCLUDED.log_sources,+ schedule_enabled = EXCLUDED.schedule_enabled,+ interval_minutes = EXCLUDED.interval_minutes,+ jitter_seconds = EXCLUDED.jitter_seconds,+ hypothesis = EXCLUDED.hypothesis,+ expected = EXCLUDED.expected,+ refs = EXCLUDED.refs,+ author = EXCLUDED.author,+ source_sha256 = EXCLUDED.source_sha256,+ updated_at = NOW()+ """,+ tenant_id,+ hunt.id,+ hunt.name,+ hunt.description,+ hunt.version,+ hunt.severity,+ hunt.category,+ list(hunt.tags),+ list(hunt.log_sources),+ hunt.schedule.enabled,+ hunt.schedule.interval_minutes,+ hunt.schedule.jitter_seconds,+ json.dumps(hunt.hypothesis.model_dump(by_alias=True)),+ json.dumps(hunt.expected.model_dump()),+ list(hunt.references),+ hunt.author,+ hunt.source_sha256,+ )+ touched += 1+ logger.info("hunt.store.catalog.synced", count=touched)+ except Exception as exc: # noqa: BLE001+ logger.warning("hunt.store.catalog.failed", error=str(exc))+ return touched+++# ---------------------------------------------------------------------------+# Run + finding writes+# ---------------------------------------------------------------------------+++async def record_run(+ hunt: HuntDefinition,+ result: HuntRunResult,+ *,+ tenant_ref: str = "default",+ trigger_source: str = "scheduler",+) -> uuid.UUID | None:+ """Persist one ``hunt_runs`` row plus its findings. Returns the run id."""+ pool = await _get_pool()+ if pool is None:+ return None++ run_id = uuid.uuid4()+ try:+ async with pool.acquire() as conn:+ tenant_id = await _resolve_tenant_id(conn, tenant_ref)+ if tenant_id is None:+ logger.debug(+ "hunt.store.run.skip", reason="unknown_tenant", tenant_ref=tenant_ref+ )+ return None+ await _set_rls_context(conn, tenant_id)++ hyp_row = await conn.fetchrow(+ "SELECT id FROM hunt_hypotheses WHERE tenant_id = $1 AND hunt_id = $2",+ tenant_id,+ hunt.id,+ )+ hypothesis_id = hyp_row["id"] if hyp_row else None++ status = "error" if result.error else "completed"+ await conn.execute(+ """+ INSERT INTO hunt_runs+ (id, tenant_id, hunt_id, hypothesis_id, trigger_source,+ status, events_scanned, findings_count, match_score,+ error, started_at, completed_at, created_at)+ VALUES+ ($1, $2, $3, $4, $5,+ $6, $7, $8, $9,+ $10, NOW(), NOW(), NOW())+ """,+ run_id,+ tenant_id,+ hunt.id,+ hypothesis_id,+ trigger_source,+ status,+ result.events_scanned,+ len(result.findings),+ round(result.match_score, 3),+ result.error,+ )++ for f in result.findings:+ await _insert_finding(conn, tenant_id, run_id, f)++ logger.info(+ "hunt.store.run.recorded",+ hunt_id=hunt.id,+ events_scanned=result.events_scanned,+ findings=len(result.findings),+ )+ except Exception as exc: # noqa: BLE001+ logger.warning("hunt.store.run.failed", hunt_id=hunt.id, error=str(exc))+ return None++ return run_id+++async def _insert_finding(+ conn: asyncpg.Connection,+ tenant_id: uuid.UUID,+ run_id: uuid.UUID,+ f: HuntFindingDraft,+) -> None:+ await conn.execute(+ """+ INSERT INTO hunt_findings+ (tenant_id, hunt_run_id, hunt_id, severity, title, summary,+ evidence, primary_entity, primary_log_source, match_score,+ mitre_techniques, status, created_at, updated_at)+ VALUES+ ($1, $2, $3, $4, $5, $6,+ $7::jsonb, $8, $9, $10,+ $11::text[], 'open', NOW(), NOW())+ """,+ tenant_id,+ run_id,+ f.hunt_id,+ f.severity,+ f.title,+ f.summary,+ json.dumps(f.evidence, default=str),+ f.primary_entity,+ f.primary_log_source,+ round(f.match_score, 3),+ list(f.mitre_techniques),+ )+++# ---------------------------------------------------------------------------+# Read-side helpers (used by the API router)+# ---------------------------------------------------------------------------+++async def list_recent_runs(+ *, tenant_ref: str = "default", limit: int = 50+) -> list[dict[str, Any]]:+ pool = await _get_pool()+ if pool is None:+ return []+ try:+ async with pool.acquire() as conn:+ tenant_id = await _resolve_tenant_id(conn, tenant_ref)+ if tenant_id is None:+ return []+ await _set_rls_context(conn, tenant_id)+ rows = await conn.fetch(+ """+ SELECT id, hunt_id, status, trigger_source, events_scanned,+ findings_count, match_score, error, started_at,+ completed_at+ FROM hunt_runs+ WHERE tenant_id = $1+ ORDER BY started_at DESC+ LIMIT $2+ """,+ tenant_id,+ limit,+ )+ return [dict(r) for r in rows]+ except Exception as exc: # noqa: BLE001+ logger.warning("hunt.store.list_runs.failed", error=str(exc))+ return []+++async def list_recent_findings(+ *,+ tenant_ref: str = "default",+ hunt_id: str | None = None,+ status: str | None = None,+ limit: int = 100,+) -> list[dict[str, Any]]:+ pool = await _get_pool()+ if pool is None:+ return []+ try:+ async with pool.acquire() as conn:+ tenant_id = await _resolve_tenant_id(conn, tenant_ref)+ if tenant_id is None:+ return []+ await _set_rls_context(conn, tenant_id)+ clauses = ["tenant_id = $1"]+ params: list[Any] = [tenant_id]+ if hunt_id:+ params.append(hunt_id)+ clauses.append(f"hunt_id = ${len(params)}")+ if status:+ params.append(status)+ clauses.append(f"status = ${len(params)}")+ params.append(limit)+ sql = f"""+ SELECT id, hunt_run_id, hunt_id, severity, title, summary,+ primary_entity, primary_log_source, match_score,+ mitre_techniques, status, created_at+ FROM hunt_findings+ WHERE {' AND '.join(clauses)}+ ORDER BY created_at DESC+ LIMIT ${len(params)}+ """+ rows = await conn.fetch(sql, *params)+ return [dict(r) for r in rows]+ except Exception as exc: # noqa: BLE001+ logger.warning("hunt.store.list_findings.failed", error=str(exc))+ return []diff --git a/services/agents/app/main.py b/services/agents/app/main.pyindex e22c7ef2f..f5cce37fe 100644--- a/services/agents/app/main.py+++ b/services/agents/app/main.py@@ -7,10 +7,13 @@ from fastapi import FastAPIfrom fastapi.middleware.cors import CORSMiddlewarefrom app.api.contextual import router as contextual_router+from app.api.hunts import router as hunts_routerfrom app.api.investigate import router as investigate_routerfrom app.api.playbooks import router as playbook_routerfrom app.api.router import routerfrom app.core.telemetry import instrument_app+from app.hunt import scheduler as hunt_scheduler+from app.hunt import store as hunt_storefrom app.investigator import ledger as investigation_ledgerfrom app.playbook import PlaybookStorefrom app.tools.mitre_full import embed_techniques_into_qdrant, load_attck_corpus@@ -55,8 +58,30 @@ async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:except Exception as exc: # noqa: BLE001logger.warning("investigation_ledger.warmup_failed", error=str(exc))+ # Start the continuous hunt scheduler (Wave 2 — w2-hac). Gated by env+ # so dev/CI runs that don't want background jobs can opt out via+ # AISOC_HUNT_SCHEDULER_DISABLE=1. Best-effort: a corpus load failure+ # or DB outage must not block API startup.+ if os.getenv("AISOC_HUNT_SCHEDULER_DISABLE", "").strip() not in ("1", "true", "yes"):+ try:+ await hunt_scheduler.start_scheduler()+ except Exception as exc: # noqa: BLE001+ logger.warning("hunt.scheduler.start_failed", error=str(exc))+yield+ # Stop the hunt scheduler before draining DB pools so in-flight runs+ # can flush their writes.+ try:+ await hunt_scheduler.stop_scheduler()+ except Exception as exc: # noqa: BLE001+ logger.warning("hunt.scheduler.stop_failed", error=str(exc))++ try:+ await hunt_store.close_pool()+ except Exception as exc: # noqa: BLE001+ logger.warning("hunt.store.close_failed", error=str(exc))+# Drain the pool so the container exits cleanly on shutdown.try:await investigation_ledger.close_pool()@@ -95,6 +120,7 @@ app.include_router(router, prefix="/api/v1")app.include_router(investigate_router) # prefix already set in investigate.pyapp.include_router(playbook_router) # prefix: /api/v1/playbooksapp.include_router(contextual_router) # prefix: /api/v1/contextual+app.include_router(hunts_router) # prefix: /api/v1/hunts@app.get("/health")diff --git a/services/agents/pyproject.toml b/services/agents/pyproject.tomlindex a1149aae9..53de971fb 100644--- a/services/agents/pyproject.toml+++ b/services/agents/pyproject.toml@@ -31,6 +31,8 @@ opentelemetry-instrumentation-fastapi = "^0.45b0"opentelemetry-instrumentation-httpx = "^0.45b0"asyncpg = "^0.29.0"sqlalchemy = {extras = ["asyncio"], version = "^2.0.25"}+apscheduler = "^3.10.4"+pyyaml = "^6.0.1"[tool.poetry.group.dev.dependencies]pytest = "^7.4.0"diff --git a/services/agents/tests/eval_data/adversary_incidents.json b/services/agents/tests/eval_data/adversary_incidents.jsonnew file mode 100644index 000000000..1a2de0663--- /dev/null+++ b/services/agents/tests/eval_data/adversary_incidents.json@@ -0,0 +1,5443 @@+[+ {+ "id": "INC-EVAL-001",+ "template_id": "phishing-macro-email",+ "template_index": 0,+ "adversary_intensity": "heavy",+ "title": "narrow-cast baiting email with m@cro-laden attachment delivered to [email protected]",+ "description": "Inbound email from 45.142.122.111 delivered an Office document with a malicious doc-embedded autom m@cro to [email protected]. Attachment opened on WIN-DC-PRIMARY; m@cro spawned command interpreter binary and downloaded a second-tier dropper from a known Lazarus infrastructure.",+ "expected_tactics": [+ "TA0001",+ "TA0002"+ ],+ "expected_techniques": [+ "T1566.001",+ "T1059.005"+ ],+ "severity": "high",+ "response_class": "block_indicator",+ "evidence_keywords": [+ "phishing email",+ "macro",+ "45.142.122.111",+ "WIN-DC-PRIMARY",+ "[email protected]",+ "stage-2 payload"+ ],+ "original_title": "Spear-phishing email with macro-laden attachment delivered to [email protected]",+ "original_description": "Inbound email from 45.142.122.111 delivered an Office document with a malicious VBA macro to [email protected]. Attachment opened on WIN-DC-PRIMARY; macro spawned cmd.exe and downloaded a stage-2 payload from a known Lazarus infrastructure."+ },+ {+ "id": "INC-EVAL-002",+ "template_id": "webapp-sqli-ssrf-exploit",+ "template_index": 1,+ "adversary_intensity": "heavy",+ "title": "Exploitation of public-facing web app on LIN-BUILD-CI03",+ "description": "WAF logs show SQL-injection and SSRF probes from 172.16.50.7 against the application on LIN-BUILD-CI03. One request returned 200 with internal cloud-metadata content. Likely exploitation of CVE-2024-1234.",+ "expected_tactics": [+ "TA0001",+ "TA0007"+ ],+ "expected_techniques": [+ "T1190",+ "T1082"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "WAF",+ "SQL injection",+ "SSRF",+ "CVE-2024-1234",+ "LIN-BUILD-CI03",+ "172.16.50.7"+ ],+ "original_title": "Exploitation of public-facing web app on LIN-BUILD-CI03",+ "original_description": "WAF logs show SQL-injection and SSRF probes from 172.16.50.7 against the application on LIN-BUILD-CI03. One request returned 200 with internal cloud-metadata content. Likely exploitation of CVE-2024-1234."+ },+ {+ "id": "INC-EVAL-003",+ "template_id": "confluence-watering-hole",+ "template_index": 2,+ "adversary_intensity": "light",+ "title": "Watering-hole exploit served from internal Confluence by 203.0.113.45",+ "description": "Internal Confluence page injected with malicious JavaScript by 203.0.113.45. Drive-by exploit triggered browser exploitation on multiple visitors including [email protected]. Linked to Lazarus TTPs.",+ "expected_tactics": [+ "TA0001",+ "TA0002"+ ],+ "expected_techniques": [+ "T1189",+ "T1203"+ ],+ "severity": "high",+ "response_class": "block_indicator",+ "evidence_keywords": [+ "watering hole",+ "drive-by",+ "Confluence",+ "203.0.113.45",+ "[email protected]",+ "Lazarus"+ ],+ "original_title": "Watering-hole exploit served from internal Confluence by 203.0.113.45",+ "original_description": "Internal Confluence page injected with malicious JavaScript by 203.0.113.45. Drive-by exploit triggered browser exploitation on multiple visitors including [email protected]. Linked to Lazarus TTPs."+ },+ {+ "id": "INC-EVAL-004",+ "template_id": "npm-supply-chain",+ "template_index": 3,+ "adversary_intensity": "medium",+ "title": "Supply-chain compromise: malicious npm p@ckage on WIN-DC-PRIMARY",+ "description": "CI pipeline on WIN-DC-PRIMARY installed trojanized js-libs release p@ckage `event-stream`. Post-install hook executed reverse shell to 198.51.100.23. Build artefacts may be tainted.",+ "expected_tactics": [+ "TA0001",+ "TA0002"+ ],+ "expected_techniques": [+ "T1195.001",+ "T1059.007"+ ],+ "severity": "critical",+ "response_class": "rollback_change",+ "evidence_keywords": [+ "supply chain",+ "npm package",+ "event-stream",+ "post-install",+ "WIN-DC-PRIMARY",+ "198.51.100.23"+ ],+ "original_title": "Supply-chain compromise: malicious npm package on WIN-DC-PRIMARY",+ "original_description": "CI pipeline on WIN-DC-PRIMARY installed compromised npm package `event-stream`. Post-install hook executed reverse shell to 198.51.100.23. Build artefacts may be tainted."+ },+ {+ "id": "INC-EVAL-005",+ "template_id": "usb-autorun-airgap",+ "template_index": 4,+ "adversary_intensity": "light",+ "title": "Malicious USB autorun on air-gapped host WIN-DEVOPS-LT",+ "description": "USB device inserted on air-gapped WIN-DEVOPS-LT by [email protected]. AutoRun executed Python stager that collected local files. Data staged in C:\\Temp\\.",+ "expected_tactics": [+ "TA0001",+ "TA0009"+ ],+ "expected_techniques": [+ "T1091",+ "T1005"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "USB",+ "autorun",+ "air-gapped",+ "WIN-DEVOPS-LT",+ "[email protected]",+ "Python stager"+ ],+ "original_title": "Malicious USB autorun on air-gapped host WIN-DEVOPS-LT",+ "original_description": "USB device inserted on air-gapped WIN-DEVOPS-LT by [email protected]. AutoRun executed Python stager that collected local files. Data staged in C:\\Temp\\."+ },+ {+ "id": "INC-EVAL-006",+ "template_id": "oauth-consent-phish",+ "template_index": 5,+ "adversary_intensity": "medium",+ "title": "delegated grant consent phishing targeting [email protected]",+ "description": "Malicious delegated grant application granted Mail.Read and Files.Read.All scopes by [email protected]. Inbox forwarding rule created sending mail to 91.134.231.15.",+ "expected_tactics": [+ "TA0001",+ "TA0006"+ ],+ "expected_techniques": [+ "T1528",+ "T1550.001"+ ],+ "severity": "high",+ "response_class": "disable_account",+ "evidence_keywords": [+ "OAuth consent",+ "Mail.Read",+ "Files.Read.All",+ "[email protected]",+ "91.134.231.15",+ "forwarding rule"+ ],+ "original_title": "OAuth consent phishing targeting [email protected]",+ "original_description": "Malicious OAuth application granted Mail.Read and Files.Read.All scopes by [email protected]. Inbox forwarding rule created sending mail to 91.134.231.15."+ },+ {+ "id": "INC-EVAL-007",+ "template_id": "powershell-obfuscated-dropper",+ "template_index": 6,+ "adversary_intensity": "light",+ "title": "Obfuscated powershell dropper executed on LIN-OBS-LOGGER",+ "description": "powershell dropper executed on LIN-OBS-LOGGER by [email protected]; payload base64-encoded and decoded in-memory. Linked to MagicWeb ransomware staging.",+ "expected_tactics": [+ "TA0002",+ "TA0005"+ ],+ "expected_techniques": [+ "T1059.001",+ "T1027"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "powershell",+ "obfuscated",+ "base64",+ "LIN-OBS-LOGGER",+ "[email protected]",+ "MagicWeb"+ ],+ "original_title": "Obfuscated PowerShell dropper executed on LIN-OBS-LOGGER",+ "original_description": "PowerShell dropper executed on LIN-OBS-LOGGER by [email protected]; payload base64-encoded and decoded in-memory. Linked to MagicWeb ransomware staging."+ },+ {+ "id": "INC-EVAL-008",+ "template_id": "certutil-download-cradle",+ "template_index": 7,+ "adversary_intensity": "medium",+ "title": "Living-off-the-land: certutil download cradle on AWS-Ecallback infra-PROD-API",+ "description": "certutil.exe -urlcache invoked from cm\u200bd.exe on AWS-Ecallback infra-PROD-API. cm\u200bd.exe was spawned by outlook.exe. Payload downloaded from 172.16.50.7.",+ "expected_tactics": [+ "TA0002",+ "TA0005"+ ],+ "expected_techniques": [+ "T1105",+ "T1218.009"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "certutil",+ "urlcache",+ "outlook.exe",+ "AWS-EC2-PROD-API",+ "172.16.50.7",+ "download cradle"+ ],+ "original_title": "Living-off-the-land: certutil download cradle on AWS-EC2-PROD-API",+ "original_description": "certutil.exe -urlcache invoked from cmd.exe on AWS-EC2-PROD-API. cmd.exe was spawned by outlook.exe. Payload downloaded from 172.16.50.7."+ },+ {+ "id": "INC-EVAL-009",+ "template_id": "docker-runtime-abuse",+ "template_index": 8,+ "adversary_intensity": "medium",+ "title": "Container runtime abuse: malicious `runc launch` on LIN-EDGE-VPN02",+ "description": "Unauthenticated Docker API on LIN-EDGE-VPN02 exploited from 198.51.100.23. image carrying cryptominer spawned. CPU on host saturated to 95%.",+ "expected_tactics": [+ "TA0002",+ "TA0001",+ "TA0040"+ ],+ "expected_techniques": [+ "T1610",+ "T1059.004",+ "T1496"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "docker",+ "container",+ "cryptominer",+ "miner",+ "LIN-EDGE-VPN02",+ "198.51.100.23"+ ],+ "original_title": "Container runtime abuse: malicious `docker run` on LIN-EDGE-VPN02",+ "original_description": "Unauthenticated Docker API on LIN-EDGE-VPN02 exploited from 198.51.100.23. Container with cryptominer spawned. CPU on host saturated to 95%."+ },+ {+ "id": "INC-EVAL-010",+ "template_id": "wmi-event-subscription",+ "template_index": 9,+ "adversary_intensity": "heavy",+ "title": "Malicious WM\u200bI subautomation snippetion on AZURE-VM-FIN-001",+ "description": "perm wm\u200bi event subautomation snippetion created on AZURE-VM-FIN-001 by [email protected]. Consumer runs byte-wrapd automation snippet. re-establish footing + binary launch mechanism.",+ "expected_tactics": [+ "TA0002",+ "TA0003"+ ],+ "expected_techniques": [+ "T1546.003",+ "T1059.001"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "WMI",+ "subscription",+ "permanent",+ "AZURE-VM-FIN-001",+ "[email protected]",+ "encoded script"+ ],+ "original_title": "Malicious WMI subscription on AZURE-VM-FIN-001",+ "original_description": "Permanent WMI event subscription created on AZURE-VM-FIN-001 by [email protected]. Consumer runs encoded script. Persistence + execution mechanism."+ },+ {+ "id": "INC-EVAL-011",+ "template_id": "registry-run-persistence",+ "template_index": 10,+ "adversary_intensity": "medium",+ "title": "Registry Run key persistence created by [email protected] on AWS-Ec\u200b2-PROD-API",+ "description": "New value written to HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run on AWS-Ec\u200b2-PROD-API. Points to roaming binary signed with revoked cert. Linked to Volt Typhoon.",+ "expected_tactics": [+ "TA0003"+ ],+ "expected_techniques": [+ "T1547.001"+ ],+ "severity": "medium",+ "response_class": "rollback_change",+ "evidence_keywords": [+ "registry run",+ "persistence",+ "revoked cert",+ "AWS-EC2-PROD-API",+ "[email protected]",+ "Volt Typhoon"+ ],+ "original_title": "Registry Run key persistence created by [email protected] on AWS-EC2-PROD-API",+ "original_description": "New value written to HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run on AWS-EC2-PROD-API. Points to roaming binary signed with revoked cert. Linked to Volt Typhoon."+ },+ {+ "id": "INC-EVAL-012",+ "template_id": "scheduled-task-persistence",+ "template_index": 11,+ "adversary_intensity": "light",+ "title": "Scheduled task persistence on GCP-GKE-NODE-04",+ "description": "Hidden scheduled task created on GCP-GKE-NODE-04 by [email protected]: triggers every 30 minutes, runs script from %APPDATA%\\Roaming. Persistence mechanism.",+ "expected_tactics": [+ "TA0003"+ ],+ "expected_techniques": [+ "T1053.005"+ ],+ "severity": "medium",+ "response_class": "rollback_change",+ "evidence_keywords": [+ "scheduled task",+ "persistence",+ "APPDATA",+ "GCP-GKE-NODE-04",+ ],+ "original_title": "Scheduled task persistence on GCP-GKE-NODE-04",+ "original_description": "Hidden scheduled task created on GCP-GKE-NODE-04 by [email protected]: triggers every 30 minutes, runs script from %APPDATA%\\Roaming. Persistence mechanism."+ },+ {+ "id": "INC-EVAL-013",+ "template_id": "uefi-firmware-implant",+ "template_index": 12,+ "adversary_intensity": "heavy",+ "title": "below-os layer imp1ant detected on ue\u200bfi partition of WIN-FIN-DB01",+ "description": "ue\u200bfi secure-boot violation on WIN-FIN-DB01. Unknown module detected in below-os layer. Signature matches MosaicRoutbound flowor imp1ant.",+ "expected_tactics": [+ "TA0003",+ "TA0005"+ ],+ "expected_techniques": [+ "T1542.001",+ "T1027.002"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "UEFI",+ "firmware",+ "implant",+ "secure boot",+ "WIN-FIN-DB01",+ "MosaicRegressor"+ ],+ "original_title": "Firmware implant detected on UEFI partition of WIN-FIN-DB01",+ "original_description": "UEFI secure-boot violation on WIN-FIN-DB01. Unknown module detected in firmware. Signature matches MosaicRegressor implant."+ },+ {+ "id": "INC-EVAL-014",+ "template_id": "cron-backdoor",+ "template_index": 13,+ "adversary_intensity": "medium",+ "title": "Backdoor cron job installed on WIN-HR-DESKTOP",+ "description": "/etc/cron.d entry created by [email protected] on WIN-HR-DESKTOP. Reverse shell regular check-in to 203.0.113.45 every 5 minutes.",+ "expected_tactics": [+ "TA0003",+ "TA0011"+ ],+ "expected_techniques": [+ "T1053.003",+ "T1071.001"+ ],+ "severity": "high",+ "response_class": "rollback_change",+ "evidence_keywords": [+ "cron",+ "backdoor",+ "reverse shell",+ "WIN-HR-DESKTOP",+ "[email protected]",+ "203.0.113.45"+ ],+ "original_title": "Backdoor cron job installed on WIN-HR-DESKTOP",+ "original_description": "/etc/cron.d entry created by [email protected] on WIN-HR-DESKTOP. Reverse shell beacon to 203.0.113.45 every 5 minutes."+ },+ {+ "id": "INC-EVAL-015",+ "template_id": "uac-bypass-fodhelper",+ "template_index": 14,+ "adversary_intensity": "medium",+ "title": "UAC bypass observed on MAC-LEGAL-LAPTOP",+ "description": "fodhelper.exe abuse on MAC-LEGAL-LAPTOP by [email protected]; auto-elevation triggered without prompt. Process tree shows escalation to SYSTEM.",+ "expected_tactics": [+ "TA0004",+ "TA0005"+ ],+ "expected_techniques": [+ "T1548.002"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "UAC",+ "fodhelper",+ "auto-elevation",+ "MAC-LEGAL-LAPTOP",+ "[email protected]",+ "SYSTEM"+ ],+ "original_title": "UAC bypass observed on MAC-LEGAL-LAPTOP",+ "original_description": "fodhelper.exe abuse on MAC-LEGAL-LAPTOP by [email protected]; auto-elevation triggered without prompt. Process tree shows escalation to SYSTEM."+ },+ {+ "id": "INC-EVAL-016",+ "template_id": "k8s-privileged-pod-escape",+ "template_index": 15,+ "adversary_intensity": "heavy",+ "title": "namespace breakout via p0werful pod on K8S-PROD-CLUSTER",+ "description": "Kubernetes p0werful pod created on K8S-PROD-CLUSTER by [email protected]. cgroup escape to host namespace observed. n0de runtime filesystem accessed.",+ "expected_tactics": [+ "TA0004",+ "TA0007"+ ],+ "expected_techniques": [+ "T1611",+ "T1082"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "kubernetes",+ "privileged pod",+ "container escape",+ "cgroup",+ "K8S-PROD-CLUSTER",+ ],+ "original_title": "Container escape via privileged pod on K8S-PROD-CLUSTER",+ "original_description": "Kubernetes privileged pod created on K8S-PROD-CLUSTER by [email protected]. cgroup escape to host namespace observed. Node filesystem accessed."+ },+ {+ "id": "INC-EVAL-017",+ "template_id": "linux-suid-abuse",+ "template_index": 16,+ "adversary_intensity": "heavy",+ "title": "Linux su\u200bid binary abuse on LIN-DB-REPLICA",+ "description": "Custom su\u200bid binary discovered in /tmp on LIN-DB-REPLICA; allows arbitrary command payload delivery step as root. Likely rights step-up by [email protected].",+ "expected_tactics": [+ "TA0004"+ ],+ "expected_techniques": [+ "T1548.001"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "SUID",+ "/tmp",+ "root escalation",+ "LIN-DB-REPLICA",+ ],+ "original_title": "Linux SUID binary abuse on LIN-DB-REPLICA",+ "original_description": "Custom SUID binary discovered in /tmp on LIN-DB-REPLICA; allows arbitrary command execution as root. Likely escalation by [email protected]."+ },+ {+ "id": "INC-EVAL-018",+ "template_id": "process-hollowing-svchost",+ "template_index": 17,+ "adversary_intensity": "medium",+ "title": "ram-resident ram-resident-only long-residence agent in svchost on MAC-CFO-LAPTOP",+ "description": "Process memory-cavity swap detected on MAC-CFO-LAPTOP: svchost.exe replaced with crimson-team toolkit callback ping to 10.0.99.42. No disk artefacts. Linked to Scattered Spider.",+ "expected_tactics": [+ "TA0002",+ "TA0005"+ ],+ "expected_techniques": [+ "T1055.012",+ "T1620"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "process hollowing",+ "fileless",+ "svchost",+ "Cobalt Strike",+ "MAC-CFO-LAPTOP",+ "10.0.99.42"+ ],+ "original_title": "Memory-only fileless implant in svchost on MAC-CFO-LAPTOP",+ "original_description": "Process hollowing detected on MAC-CFO-LAPTOP: svchost.exe replaced with Cobalt Strike beacon to 10.0.99.42. No disk artefacts. Linked to Scattered Spider."+ },+ {+ "id": "INC-EVAL-019",+ "template_id": "event-log-cleared",+ "template_index": 18,+ "adversary_intensity": "light",+ "title": "Indicator removal: Windows event log cleared on LIN-EDGE-VPN02",+ "description": "Security event log cleared on LIN-EDGE-VPN02 by [email protected]. wevtutil.exe cl Security observed in command-line telemetry.",+ "expected_tactics": [+ "TA0005"+ ],+ "expected_techniques": [+ "T1070.001"+ ],+ "severity": "high",+ "response_class": "escalate",+ "evidence_keywords": [+ "wevtutil",+ "log cleared",+ "indicator removal",+ "LIN-EDGE-VPN02",+ ],+ "original_title": "Indicator removal: Windows event log cleared on LIN-EDGE-VPN02",+ "original_description": "Security event log cleared on LIN-EDGE-VPN02 by [email protected]. wevtutil.exe cl Security observed in command-line telemetry."+ },+ {+ "id": "INC-EVAL-020",+ "template_id": "disable-edr-tooling",+ "template_index": 19,+ "adversary_intensity": "medium",+ "title": "Disable security tooling on GCP-GKE-n\u200bode.js-04",+ "description": "[email protected] attempted to stop Defender, CrowdStrike, and Sysmon on GCP-GKE-n\u200bode.js-04. Tampering telemetry triggered alert.",+ "expected_tactics": [+ "TA0005"+ ],+ "expected_techniques": [+ "T1562.001"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "defender",+ "crowdstrike",+ "sysmon",+ "tampering",+ "GCP-GKE-NODE-04",+ ],+ "original_title": "Disable security tooling on GCP-GKE-NODE-04",+ "original_description": "[email protected] attempted to stop Defender, CrowdStrike, and Sysmon on GCP-GKE-NODE-04. Tampering telemetry triggered alert."+ },+ {+ "id": "INC-EVAL-021",+ "template_id": "lsass-memory-dump",+ "template_index": 20,+ "adversary_intensity": "heavy",+ "title": "l$ass memory proc-mem snapshot on AZURE-VM-FIN-001 by [email protected]",+ "description": "comsvcs.loadable code module proc-snapshot observed on AZURE-VM-FIN-001. l$ass.exe memory proc-mem snapshoted to C:\\Windows\\Temp\\. m1m1katz signatures detected.",+ "expected_tactics": [+ "TA0006"+ ],+ "expected_techniques": [+ "T1003.001"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "lsass",+ "minidump",+ "comsvcs",+ "mimikatz",+ "AZURE-VM-FIN-001",+ ],+ "original_title": "LSASS memory dump on AZURE-VM-FIN-001 by [email protected]",+ "original_description": "comsvcs.dll MiniDump observed on AZURE-VM-FIN-001. lsass.exe memory dumped to C:\\Windows\\Temp\\. Mimikatz signatures detected."+ },+ {+ "id": "INC-EVAL-022",+ "template_id": "credential-spray",+ "template_index": 21,+ "adversary_intensity": "heavy",+ "title": "repeated-guess auth-token probe spread against [email protected] from 45.142.122.111",+ "description": "auth-token probe spread from 45.142.122.111 against [email protected]. 1500 password attempts in 30 minutes. One success followed by anomalous Azure AD sign-in.",+ "expected_tactics": [+ "TA0006"+ ],+ "expected_techniques": [+ "T1110.003"+ ],+ "severity": "high",+ "response_class": "disable_account",+ "evidence_keywords": [+ "brute force",+ "credential spray",+ "[email protected]",+ "45.142.122.111",+ "azure ad"+ ],+ "original_title": "Brute-force credential spray against [email protected] from 45.142.122.111",+ "original_description": "Credential spray from 45.142.122.111 against [email protected]. 1500 password attempts in 30 minutes. One success followed by anomalous Azure AD sign-in."+ },+ {+ "id": "INC-EVAL-023",+ "template_id": "kerberoasting",+ "template_index": 22,+ "adversary_intensity": "heavy",+ "title": "kerb-ticket grinding from MAC-CFO-LAPTOP",+ "description": "background unit account tg\u200bs tickets requested en-masse from MAC-CFO-LAPTOP by [email protected]. AES256 \u2192 RC4 downgrade observed. auth-secrets puller tooling indicators.",+ "expected_tactics": [+ "TA0006",+ "TA0008"+ ],+ "expected_techniques": [+ "T1558.003",+ "T1021.001"+ ],+ "severity": "critical",+ "response_class": "disable_account",+ "evidence_keywords": [+ "kerberoast",+ "TGS",+ "RC4",+ "mimikatz",+ "MAC-CFO-LAPTOP",+ ],+ "original_title": "Kerberoasting from MAC-CFO-LAPTOP",+ "original_description": "Service account TGS tickets requested en-masse from MAC-CFO-LAPTOP by [email protected]. AES256 \u2192 RC4 downgrade observed. Mimikatz tooling indicators."+ },+ {+ "id": "INC-EVAL-024",+ "template_id": "ad-dcsync",+ "template_index": 23,+ "adversary_intensity": "medium",+ "title": "Active Directory dc-replica-pull abuse from non-DC host AWS-Ecallback infra-PROD-API",+ "description": "directory replica use rights abused from AWS-Ecallback infra-PROD-API by [email protected]. All domain challenge-response auth hashes replicated. Severe login secret exposure.",+ "expected_tactics": [+ "TA0006",+ "TA0004"+ ],+ "expected_techniques": [+ "T1003.006",+ "T1078.002"+ ],+ "severity": "critical",+ "response_class": "disable_account",+ "evidence_keywords": [+ "dcsync",+ "replication",+ "ntlm hash",+ "AWS-EC2-PROD-API",+ ],+ "original_title": "Active Directory DCSync from non-DC host AWS-EC2-PROD-API",+ "original_description": "Replication rights abused from AWS-EC2-PROD-API by [email protected]. All domain NTLM hashes replicated. Severe credential exposure."+ },+ {+ "id": "INC-EVAL-025",+ "template_id": "saml-golden-ticket",+ "template_index": 24,+ "adversary_intensity": "heavy",+ "title": "federation token golden-ticket: forged assertion targeting [email protected]",+ "description": "Forged federation token assertion detected for [email protected]. Attacker pivoted to Azure AD; account listing-oution followed from 198.51.100.23.",+ "expected_tactics": [+ "TA0006",+ "TA0007"+ ],+ "expected_techniques": [+ "T1606.002",+ "T1087.002"+ ],+ "severity": "critical",+ "response_class": "disable_account",+ "evidence_keywords": [+ "saml",+ "golden ticket",+ "forged",+ "azure ad",+ "[email protected]",+ "198.51.100.23"+ ],+ "original_title": "SAML golden-ticket: forged assertion targeting [email protected]",+ "original_description": "Forged SAML assertion detected for [email protected]. Attacker pivoted to Azure AD; account enumeration followed from 198.51.100.23."+ },+ {+ "id": "INC-EVAL-026",+ "template_id": "ldap-bloodhound-discovery",+ "template_index": 25,+ "adversary_intensity": "heavy",+ "title": "Domain listing-oution from LIN-K8S-n0de runtime01",+ "description": "x.500 query scout-stage from LIN-K8S-n0de runtime01 by [email protected]: bl0odhound-style queries listing-outing users, groups, ACLs.",+ "expected_tactics": [+ "TA0007"+ ],+ "expected_techniques": [+ "T1087.002"+ ],+ "severity": "medium",+ "response_class": "monitor",+ "evidence_keywords": [+ "ldap",+ "bloodhound",+ "domain enumeration",+ "LIN-K8S-NODE01",+ ],+ "original_title": "Domain enumeration from LIN-K8S-NODE01",+ "original_description": "ldap discovery from LIN-K8S-NODE01 by [email protected]: BloodHound-style queries enumerating users, groups, ACLs."+ },+ {+ "id": "INC-EVAL-027",+ "template_id": "smb-share-enumeration",+ "template_index": 26,+ "adversary_intensity": "heavy",+ "title": "fileshare mount listing-oution on LIN-EDGE-VPN02",+ "description": "Mass SMB fileshare listingeration from LIN-EDGE-VPN02 by [email protected]; net.exe and PoSh Get-SmbShare invocations across /24 subnet.",+ "expected_tactics": [+ "TA0007"+ ],+ "expected_techniques": [+ "T1135"+ ],+ "severity": "medium",+ "response_class": "monitor",+ "evidence_keywords": [+ "smb",+ "net.exe",+ "Get-SmbShare",+ "share enumeration",+ "LIN-EDGE-VPN02",+ ],+ "original_title": "Network share enumeration on LIN-EDGE-VPN02",+ "original_description": "Mass SMB share enumeration from LIN-EDGE-VPN02 by [email protected]; net.exe and PowerShell Get-SmbShare invocations across /24 subnet."+ },+ {+ "id": "INC-EVAL-028",+ "template_id": "pass-the-hash-lateral",+ "template_index": 27,+ "adversary_intensity": "light",+ "title": "Pass-the-hash from AZURE-VM-FIN-001 to LIN-EDGE-VPN02",+ "description": "Pass-the-hash lateral movement from AZURE-VM-FIN-001 to LIN-EDGE-VPN02 by [email protected]. Golden ticket indicators present. Linked to APT28.",+ "expected_tactics": [+ "TA0008",+ "TA0006"+ ],+ "expected_techniques": [+ "T1550.002",+ "T1558.001"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "pass-the-hash",+ "golden ticket",+ "AZURE-VM-FIN-001",+ "LIN-EDGE-VPN02",+ "[email protected]",+ "APT28"+ ],+ "original_title": "Pass-the-hash from AZURE-VM-FIN-001 to LIN-EDGE-VPN02",+ "original_description": "Pass-the-hash lateral movement from AZURE-VM-FIN-001 to LIN-EDGE-VPN02 by [email protected]. Golden ticket indicators present. Linked to APT28."+ },+ {+ "id": "INC-EVAL-029",+ "template_id": "rdp-lateral-movement",+ "template_index": 28,+ "adversary_intensity": "medium",+ "title": "RDP lateral movement from LIN-BUILD-CI03",+ "description": "Anomalous RDP session from LIN-BUILD-CI03 ([email protected]) to AZURE-VM-FIN-001 outside business hours. Source admin not normal for AZURE-VM-FIN-001.",+ "expected_tactics": [+ "TA0008"+ ],+ "expected_techniques": [+ "T1021.001"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "rdp",+ "lateral movement",+ "outside hours",+ "LIN-BUILD-CI03",+ "AZURE-VM-FIN-001",+ ],+ "original_title": "RDP lateral movement from LIN-BUILD-CI03",+ "original_description": "Anomalous RDP session from LIN-BUILD-CI03 ([email protected]) to AZURE-VM-FIN-001 outside business hours. Source admin not normal for AZURE-VM-FIN-001."+ },+ {+ "id": "INC-EVAL-030",+ "template_id": "wmi-lateral-execution",+ "template_index": 29,+ "adversary_intensity": "light",+ "title": "WMI lateral execution from WIN-PROD-WEB02 to AWS-EC2-PROD-API",+ "description": "wmic.exe /node:AWS-EC2-PROD-API process call create observed from WIN-PROD-WEB02 by [email protected]. Remote command execution; payload from 91.134.231.15.",+ "expected_tactics": [+ "TA0008",+ "TA0002"+ ],+ "expected_techniques": [+ "T1047"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "wmic",+ "lateral",+ "WIN-PROD-WEB02",+ "AWS-EC2-PROD-API",+ "[email protected]",+ "91.134.231.15"+ ],+ "original_title": "WMI lateral execution from WIN-PROD-WEB02 to AWS-EC2-PROD-API",+ "original_description": "wmic.exe /node:AWS-EC2-PROD-API process call create observed from WIN-PROD-WEB02 by [email protected]. Remote command execution; payload from 91.134.231.15."+ },+ {+ "id": "INC-EVAL-031",+ "template_id": "bulk-pii-download",+ "template_index": 30,+ "adversary_intensity": "heavy",+ "title": "Bulk user identity data download by [email protected]",+ "description": "[email protected] downloaded >10 GB of customer rows from production database from LIN-DB-REPLICA. Outside normal access p@ttern.",+ "expected_tactics": [+ "TA0009",+ "TA0010"+ ],+ "expected_techniques": [+ "T1005",+ "T1041"+ ],+ "severity": "critical",+ "response_class": "disable_account",+ "evidence_keywords": [+ "bulk download",+ "pii",+ "customer record",+ "LIN-DB-REPLICA",+ ],+ "original_title": "Bulk PII download by [email protected]",+ "original_description": "[email protected] downloaded >10 GB of customer records from production database from LIN-DB-REPLICA. Outside normal access pattern."+ },+ {+ "id": "INC-EVAL-032",+ "template_id": "clipboard-keylogger",+ "template_index": 31,+ "adversary_intensity": "heavy",+ "title": "paste buffer logging imp1ant on WIN-DC-SECONDARY",+ "description": "paste buffer contents from WIN-DC-SECONDARY ([email protected]) being captured to %APPDATA%\\Local\\. Captures span 2 hours and include creds and crypto addresses.",+ "expected_tactics": [+ "TA0009"+ ],+ "expected_techniques": [+ "T1115"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "clipboard",+ "keylog",+ "credentials",+ "WIN-DC-SECONDARY",+ ],+ "original_title": "Clipboard logging implant on WIN-DC-SECONDARY",+ "original_description": "Clipboard contents from WIN-DC-SECONDARY ([email protected]) being captured to %APPDATA%\\Local\\. Captures span 2 hours and include credentials and crypto addresses."+ },+ {+ "id": "INC-EVAL-033",+ "template_id": "dns-tunnel-exfil",+ "template_index": 32,+ "adversary_intensity": "heavy",+ "title": "udp/53 covert trackling ex-bound transferion from MAC-LEGAL-LAPTOP",+ "description": "name-resolution volume from MAC-LEGAL-LAPTOP 50\u00d7 baseline. TXT records contain base64-transformd payloads. Estimated exfil ~200 MB; destination 172.16.50.7.",+ "expected_tactics": [+ "TA0011",+ "TA0010"+ ],+ "expected_techniques": [+ "T1071.004",+ "T1048.003"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "dns tunnel",+ "txt records",+ "base64",+ "exfiltrat",+ "MAC-LEGAL-LAPTOP",+ "172.16.50.7"+ ],+ "original_title": "DNS tunnelling exfiltration from MAC-LEGAL-LAPTOP",+ "original_description": "DNS query volume from MAC-LEGAL-LAPTOP 50\u00d7 baseline. TXT records contain base64-encoded payloads. Estimated exfil ~200 MB; destination 172.16.50.7."+ },+ {+ "id": "INC-EVAL-034",+ "template_id": "s3-exfil-cloud-storage",+ "template_index": 33,+ "adversary_intensity": "heavy",+ "title": "blob-store push target exfil: data outflow to attacker-controlled S3 from WIN-DC-PRIMARY",+ "description": "outbound flow from WIN-DC-PRIMARY to object-store-uriatk-stage-91.134.231.15/d\u200bump/ by [email protected]. 8 GB transferred over 20 minutes. CloudTrail PutObject events match.",+ "expected_tactics": [+ "TA0010"+ ],+ "expected_techniques": [+ "T1567.002"+ ],+ "severity": "critical",+ "response_class": "block_indicator",+ "evidence_keywords": [+ "s3",+ "cloud storage",+ "egress",+ "exfiltrat",+ "WIN-DC-PRIMARY",+ "91.134.231.15",+ ],+ "original_title": "Cloud storage exfil: data egress to attacker-controlled S3 from WIN-DC-PRIMARY",+ "original_description": "Egress from WIN-DC-PRIMARY to s3://atk-stage-91.134.231.15/dump/ by [email protected]. 8 GB transferred over 20 minutes. CloudTrail PutObject events match."+ },+ {+ "id": "INC-EVAL-035",+ "template_id": "personal-drive-exfil",+ "template_index": 34,+ "adversary_intensity": "light",+ "title": "Personal Drive exfil by [email protected]",+ "description": "[email protected] on LIN-K8S-NODE01 uploaded 4 GB to personal Google Drive. Files include source code and customer PII.",+ "expected_tactics": [+ "TA0009",+ "TA0010"+ ],+ "expected_techniques": [+ "T1567.002",+ "T1005"+ ],+ "severity": "critical",+ "response_class": "disable_account",+ "evidence_keywords": [+ "google drive",+ "personal",+ "exfiltrat",+ "source code",+ "pii",+ "LIN-K8S-NODE01",+ ],+ "original_title": "Personal Drive exfil by [email protected]",+ "original_description": "[email protected] on LIN-K8S-NODE01 uploaded 4 GB to personal Google Drive. Files include source code and customer PII."+ },+ {+ "id": "INC-EVAL-036",+ "template_id": "dga-c2",+ "template_index": 35,+ "adversary_intensity": "heavy",+ "title": "domain-gen algorithm-based ops channel traffic from MAC-LEGAL-LAPTOP",+ "description": "domain-gen algorithm traffic from MAC-LEGAL-LAPTOP observed; 200+ NXDomain replies/min, IoCs match Scattered Spider epoch 5. callback pings to 172.16.50.7.",+ "expected_tactics": [+ "TA0011"+ ],+ "expected_techniques": [+ "T1568.002"+ ],+ "severity": "high",+ "response_class": "block_indicator",+ "evidence_keywords": [+ "dga",+ "domain generation",+ "nxdomain",+ "beacon",+ "MAC-LEGAL-LAPTOP",+ "172.16.50.7",+ "Scattered Spider"+ ],+ "original_title": "DGA-based C2 traffic from MAC-LEGAL-LAPTOP",+ "original_description": "DGA traffic from MAC-LEGAL-LAPTOP observed; 200+ NXDomain replies/min, IoCs match Scattered Spider epoch 5. Beacons to 172.16.50.7."+ },+ {+ "id": "INC-EVAL-037",+ "template_id": "https-c2-beacon",+ "template_index": 36,+ "adversary_intensity": "light",+ "title": "HTTPS C2 beacon from LIN-DB-REPLICA to 198.51.100.23",+ "description": "Periodic HTTPS beacon from LIN-DB-REPLICA to 198.51.100.23 every 60 seconds with low jitter. JA3 fingerprint matches Cobalt Strike.",+ "expected_tactics": [+ "TA0011"+ ],+ "expected_techniques": [+ "T1071.001"+ ],+ "severity": "critical",+ "response_class": "block_indicator",+ "evidence_keywords": [+ "c2",+ "beacon",+ "ja3",+ "Cobalt Strike",+ "LIN-DB-REPLICA",+ "198.51.100.23"+ ],+ "original_title": "HTTPS C2 beacon from LIN-DB-REPLICA to 198.51.100.23",+ "original_description": "Periodic HTTPS beacon from LIN-DB-REPLICA to 198.51.100.23 every 60 seconds with low jitter. JA3 fingerprint matches Cobalt Strike."+ },+ {+ "id": "INC-EVAL-038",+ "template_id": "ransomware-encryption",+ "template_index": 37,+ "adversary_intensity": "light",+ "title": "Ransomware encryption in progress on GCP-GKE-NODE-04",+ "description": "Mass file rename observed on GCP-GKE-NODE-04 ([email protected]); ..enc extension applied to ~20 k files. Ransomware note R3ADM3-LockBit 3.0.txt found.",+ "expected_tactics": [+ "TA0040"+ ],+ "expected_techniques": [+ "T1486"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "ransomware",+ "encrypt",+ "rename",+ "ransom note",+ "GCP-GKE-NODE-04",+ "[email protected]",+ "LockBit 3.0"+ ],+ "original_title": "Ransomware encryption in progress on GCP-GKE-NODE-04",+ "original_description": "Mass file rename observed on GCP-GKE-NODE-04 ([email protected]); ..enc extension applied to ~20 k files. Ransomware note R3ADM3-LockBit 3.0.txt found."+ },+ {+ "id": "INC-EVAL-039",+ "template_id": "xmrig-cryptominer",+ "template_index": 38,+ "adversary_intensity": "heavy",+ "title": "cycles for currencyr binary launch on WIN-DC-SECONDARY",+ "description": "xm\u200brig c0in-miner spawned on WIN-DC-SECONDARY; CPU saturated to 95%. Mining pool 172.16.50.7:5555. Linked to LockBit 3.0.",+ "expected_tactics": [+ "TA0002",+ "TA0040"+ ],+ "expected_techniques": [+ "T1496"+ ],+ "severity": "medium",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "xmrig",+ "miner",+ "cryptomine",+ "WIN-DC-SECONDARY",+ "172.16.50.7",+ "LockBit 3.0"+ ],+ "original_title": "Cryptominer execution on WIN-DC-SECONDARY",+ "original_description": "XMRig miner spawned on WIN-DC-SECONDARY; CPU saturated to 95%. Mining pool 172.16.50.7:5555. Linked to LockBit 3.0."+ },+ {+ "id": "INC-EVAL-040",+ "template_id": "bec-wire-fraud",+ "template_index": 39,+ "adversary_intensity": "medium",+ "title": "boss-impersonation fraud: payment redirect by [email protected]",+ "description": "Spear-phishing email spoofed CFO. Wire transfer of a quarter-million-dollar k initiated by [email protected] from AWS-Ecallback infra-PROD-API to threat-actor account. Linked to ALPHV/BlackCat.",+ "expected_tactics": [+ "TA0001",+ "TA0040"+ ],+ "expected_techniques": [+ "T1566.001",+ "T1657"+ ],+ "severity": "critical",+ "response_class": "escalate",+ "evidence_keywords": [+ "phishing",+ "spoofed cfo",+ "wire transfer",+ "$250",+ "[email protected]",+ "AWS-EC2-PROD-API",+ "ALPHV/BlackCat"+ ],+ "original_title": "BEC: payment redirect by [email protected]",+ "original_description": "Spear-phishing email spoofed CFO. Wire transfer of $250 k initiated by [email protected] from AWS-EC2-PROD-API to threat-actor account. Linked to ALPHV/BlackCat."+ },+ {+ "id": "INC-EVAL-041",+ "template_id": "public-s3-bucket-pii",+ "template_index": 40,+ "adversary_intensity": "heavy",+ "title": "Public blob-store bucket exposing user identity data",+ "description": "blob-store bucket world-readable; ~40k employee records accessible. CloudTrail shows external listing-oution from 203.0.113.45.",+ "expected_tactics": [+ "TA0009",+ "TA0010"+ ],+ "expected_techniques": [+ "T1530",+ "T1567.002"+ ],+ "severity": "critical",+ "response_class": "rollback_change",+ "evidence_keywords": [+ "s3",+ "public bucket",+ "pii",+ "cloudtrail",+ "203.0.113.45"+ ],+ "original_title": "Public S3 bucket exposing PII",+ "original_description": "S3 bucket world-readable; ~40k employee records accessible. CloudTrail shows external enumeration from 203.0.113.45."+ },+ {+ "id": "INC-EVAL-042",+ "template_id": "azure-ad-impossible-travel",+ "template_index": 41,+ "adversary_intensity": "medium",+ "title": "Identity provider compromise \u2014 anomalous Azure AD sign-in for [email protected]",+ "description": "Successful Azure AD sign-in for [email protected] from 45.142.122.111 (impossible-travel from prior location). MFA satisfied via session-takeover token.",+ "expected_tactics": [+ "TA0001",+ "TA0006"+ ],+ "expected_techniques": [+ "T1078.004",+ "T1550.001"+ ],+ "severity": "critical",+ "response_class": "disable_account",+ "evidence_keywords": [+ "azure ad",+ "impossible travel",+ "session token",+ "mfa",+ "[email protected]",+ "45.142.122.111"+ ],+ "original_title": "Identity provider compromise \u2014 anomalous Azure AD sign-in for [email protected]",+ "original_description": "Successful Azure AD sign-in for [email protected] from 45.142.122.111 (impossible-travel from prior location). MFA satisfied via stolen session token."+ },+ {+ "id": "INC-EVAL-043",+ "template_id": "ddos-syn-flood",+ "template_index": 42,+ "adversary_intensity": "heavy",+ "title": "d\u200bdos volumetric flood targeting public-facing WIN-DEVOPS-LT",+ "description": "L4 tcp-half-open flood from a botnet (>1M PPS) targeting WIN-DEVOPS-LT. Edge mitigation engaged but d@emon entry degraded for 12 minutes.",+ "expected_tactics": [+ "TA0040"+ ],+ "expected_techniques": [+ "T1498.001"+ ],+ "severity": "high",+ "response_class": "block_indicator",+ "evidence_keywords": [+ "ddos",+ "syn flood",+ "botnet",+ "WIN-DEVOPS-LT",+ "1M PPS"+ ],+ "original_title": "DDoS volumetric flood targeting public-facing WIN-DEVOPS-LT",+ "original_description": "L4 SYN flood from a botnet (>1M PPS) targeting WIN-DEVOPS-LT. Edge mitigation engaged but service degraded for 12 minutes."+ },+ {+ "id": "INC-EVAL-044",+ "template_id": "insider-mailbox-export",+ "template_index": 43,+ "adversary_intensity": "heavy",+ "title": "Insider preparing departure: large inbox extract by [email protected]",+ "description": "[email protected] exported full mailbox mail archive (8 GB) from AZURE-VM-FIN-001. HR flag: notice given last week.",+ "expected_tactics": [+ "TA0009",+ "TA0010"+ ],+ "expected_techniques": [+ "T1114.002",+ "T1567.002"+ ],+ "severity": "high",+ "response_class": "disable_account",+ "evidence_keywords": [+ "mailbox export",+ "PST",+ "insider",+ "departure",+ "[email protected]",+ "AZURE-VM-FIN-001"+ ],+ "original_title": "Insider preparing departure: large mailbox export by [email protected]",+ "original_description": "[email protected] exported full mailbox PST (8 GB) from AZURE-VM-FIN-001. HR flag: notice given last week."+ },+ {+ "id": "INC-EVAL-045",+ "template_id": "office-vsto-addin",+ "template_index": 44,+ "adversary_intensity": "medium",+ "title": "Malicious Office add-in installed for [email protected]",+ "description": "Office VSTO add-in registered under HKCU for [email protected] on WIN-EXCHANGE-01; loads on every Outlook startup; b\u200beacons to 185.220.101.7.",+ "expected_tactics": [+ "TA0003",+ "TA0011"+ ],+ "expected_techniques": [+ "T1137.006",+ "T1071.001"+ ],+ "severity": "high",+ "response_class": "rollback_change",+ "evidence_keywords": [+ "office add-in",+ "vsto",+ "outlook",+ "[email protected]",+ "WIN-EXCHANGE-01",+ "185.220.101.7"+ ],+ "original_title": "Malicious Office add-in installed for [email protected]",+ "original_description": "Office VSTO add-in registered under HKCU for [email protected] on WIN-EXCHANGE-01; loads on every Outlook startup; beacons to 185.220.101.7."+ },+ {+ "id": "INC-EVAL-046",+ "template_id": "github-pat-leak",+ "template_index": 45,+ "adversary_intensity": "heavy",+ "title": "GitHub p@t leaked and abused from 185.220.101.7",+ "description": "user-issued api token belonging to [email protected] used from 185.220.101.7 to clone 14 non-public repos. Token committed in public dotfiles repo 6 hours earlier.",+ "expected_tactics": [+ "TA0006",+ "TA0009"+ ],+ "expected_techniques": [+ "T1552.001",+ "T1213.003"+ ],+ "severity": "critical",+ "response_class": "disable_account",+ "evidence_keywords": [+ "github",+ "pat",+ "token",+ "private repo",+ "[email protected]",+ "185.220.101.7"+ ],+ "original_title": "GitHub PAT leaked and abused from 185.220.101.7",+ "original_description": "Personal access token belonging to [email protected] used from 185.220.101.7 to clone 14 private repos. Token committed in public dotfiles repo 6 hours earlier."+ },+ {+ "id": "INC-EVAL-047",+ "template_id": "ec2-imds-credential-theft",+ "template_index": 46,+ "adversary_intensity": "heavy",+ "title": "Ec\u200b2 instance m\u200betadata svc abused on GCP-GKE-n0de runtime-04",+ "description": "im\u200bdsv1 abused on GCP-GKE-n0de runtime-04; temporary IAM login secrets for role exfilled to 198.51.100.23. CloudTrail shows AssumeRole from external.",+ "expected_tactics": [+ "TA0006",+ "TA0004"+ ],+ "expected_techniques": [+ "T1552.005",+ "T1078.004"+ ],+ "severity": "critical",+ "response_class": "rollback_change",+ "evidence_keywords": [+ "imds",+ "metadata",+ "iam credentials",+ "AssumeRole",+ "GCP-GKE-NODE-04",+ "198.51.100.23"+ ],+ "original_title": "EC2 instance metadata service abused on GCP-GKE-NODE-04",+ "original_description": "IMDSv1 abused on GCP-GKE-NODE-04; temporary IAM credentials for role exfilled to 198.51.100.23. CloudTrail shows AssumeRole from external."+ },+ {+ "id": "INC-EVAL-048",+ "template_id": "helpdesk-password-reset-abuse",+ "template_index": 47,+ "adversary_intensity": "heavy",+ "title": "Vendor admin pw rotation request abuse for [email protected]",+ "description": "pw rotation request for [email protected] performed by helpdesk in response to human-factor pretexting call from 185.220.101.7. Token claimed within 90 seconds.",+ "expected_tactics": [+ "TA0001",+ "TA0006"+ ],+ "expected_techniques": [+ "T1566.004",+ "T1078"+ ],+ "severity": "high",+ "response_class": "disable_account",+ "evidence_keywords": [+ "password reset",+ "social engineering",+ "helpdesk",+ "[email protected]",+ "185.220.101.7"+ ],+ "original_title": "Vendor admin password reset abuse for [email protected]",+ "original_description": "Password reset for [email protected] performed by helpdesk in response to social-engineering call from 185.220.101.7. Token claimed within 90 seconds."+ },+ {+ "id": "INC-EVAL-049",+ "template_id": "oauth-refresh-token-theft",+ "template_index": 48,+ "adversary_intensity": "light",+ "title": "OAuth refresh-token theft for [email protected]",+ "description": "Refresh token for [email protected] replayed from 172.16.50.7. Granted access to mailbox + OneDrive without re-prompt.",+ "expected_tactics": [+ "TA0006"+ ],+ "expected_techniques": [+ "T1550.001"+ ],+ "severity": "high",+ "response_class": "disable_account",+ "evidence_keywords": [+ "oauth",+ "refresh token",+ "replay",+ "onedrive",+ "mailbox",+ "[email protected]",+ "172.16.50.7"+ ],+ "original_title": "OAuth refresh-token theft for [email protected]",+ "original_description": "Refresh token for [email protected] replayed from 172.16.50.7. Granted access to mailbox + OneDrive without re-prompt."+ },+ {+ "id": "INC-EVAL-050",+ "template_id": "malicious-container-image",+ "template_index": 49,+ "adversary_intensity": "medium",+ "title": "Container image with embedded b@ckdoor pulled by AWS-Eops channel-PROD-API",+ "description": "Image registry/repo:malicious-b@ckdoor pulled by AWS-Eops channel-PROD-API. Layer probe-pass flagged embedded netcat reverse-shell binary.",+ "expected_tactics": [+ "TA0001",+ "TA0002"+ ],+ "expected_techniques": [+ "T1195.002",+ "T1610"+ ],+ "severity": "high",+ "response_class": "rollback_change",+ "evidence_keywords": [+ "container image",+ "registry",+ "backdoor",+ "netcat",+ "AWS-EC2-PROD-API"+ ],+ "original_title": "Container image with embedded backdoor pulled by AWS-EC2-PROD-API",+ "original_description": "Image registry/repo:malicious-backdoor pulled by AWS-EC2-PROD-API. Layer scan flagged embedded netcat reverse-shell binary."+ },+ {+ "id": "INC-EVAL-051",+ "template_id": "outlook-auto-forward-rule",+ "template_index": 50,+ "adversary_intensity": "light",+ "title": "Outlook rule auto-forwarding mail from [email protected]",+ "description": "Outlook inbox rule created for [email protected] that forwards all mail to external address at 203.0.113.45. Linked to MagicWeb.",+ "expected_tactics": [+ "TA0006",+ "TA0009"+ ],+ "expected_techniques": [+ "T1564.008",+ "T1114.003"+ ],+ "severity": "high",+ "response_class": "disable_account",+ "evidence_keywords": [+ "outlook rule",+ "forward",+ "mail",+ "[email protected]",+ "203.0.113.45",+ "MagicWeb"+ ],+ "original_title": "Outlook rule auto-forwarding mail from [email protected]",+ "original_description": "Outlook inbox rule created for [email protected] that forwards all mail to external address at 203.0.113.45. Linked to MagicWeb."+ },+ {+ "id": "INC-EVAL-052",+ "template_id": "linux-journald-tampering",+ "template_index": 51,+ "adversary_intensity": "heavy",+ "title": "Linux journald log modify-on-the-fly on K8S-PROD-CLUSTER",+ "description": "systemd log cli --rotate --v@cuum-time=1s observed on K8S-PROD-CLUSTER by [email protected]; recent journal entries purged. footprint cleanup.",+ "expected_tactics": [+ "TA0005"+ ],+ "expected_techniques": [+ "T1070.002"+ ],+ "severity": "high",+ "response_class": "escalate",+ "evidence_keywords": [+ "journalctl",+ "log tampering",+ "vacuum",+ "K8S-PROD-CLUSTER",+ ],+ "original_title": "Linux journald log tampering on K8S-PROD-CLUSTER",+ "original_description": "journalctl --rotate --vacuum-time=1s observed on K8S-PROD-CLUSTER by [email protected]; recent journal entries purged. Indicator removal."+ },+ {+ "id": "INC-EVAL-053",+ "template_id": "compromised-ci-runner",+ "template_index": 52,+ "adversary_intensity": "heavy",+ "title": "Compromised CI runner on AZURE-VM-FIN-001 pushing to production",+ "description": "Self-hosted CI runner AZURE-VM-FIN-001 compromised. Job triggered from PR injected secret exfil step; secrets posted to 192.168.1.100.",+ "expected_tactics": [+ "TA0001",+ "TA0006",+ "TA0010"+ ],+ "expected_techniques": [+ "T1195.002",+ "T1552.004"+ ],+ "severity": "critical",+ "response_class": "rollback_change",+ "evidence_keywords": [+ "ci runner",+ "self-hosted",+ "secret",+ "exfil",+ "AZURE-VM-FIN-001",+ "192.168.1.100"+ ],+ "original_title": "Compromised CI runner on AZURE-VM-FIN-001 pushing to production",+ "original_description": "Self-hosted CI runner AZURE-VM-FIN-001 compromised. Job triggered from PR injected secret exfil step; secrets posted to 192.168.1.100."+ },+ {+ "id": "INC-EVAL-054",+ "template_id": "vpn-new-geography",+ "template_index": 53,+ "adversary_intensity": "medium",+ "title": "Suspicious remote-access portal entry from anomalous origin for [email protected]",+ "description": "remote-access portal entry for [email protected] from 10.0.99.42 (new country, no prior history). Subsequent lateral SMB probe-pass from VPN range to LIN-K8S-n0de runtime01.",+ "expected_tactics": [+ "TA0001",+ "TA0008"+ ],+ "expected_techniques": [+ "T1078.004",+ "T1021.002"+ ],+ "severity": "high",+ "response_class": "disable_account",+ "evidence_keywords": [+ "vpn",+ "new geography",+ "lateral",+ "smb scan",+ "[email protected]",+ "10.0.99.42",+ "LIN-K8S-NODE01"+ ],+ "original_title": "Suspicious VPN login from new geography for [email protected]",+ "original_description": "VPN login for [email protected] from 10.0.99.42 (new country, no prior history). Subsequent lateral SMB scan from VPN range to LIN-K8S-NODE01."+ },+ {+ "id": "INC-EVAL-055",+ "template_id": "service-account-privileged-command",+ "template_index": 54,+ "adversary_intensity": "heavy",+ "title": "Privileged command run as background unit account on WIN-PROD-WEB02",+ "description": "background unit account [email protected] (no interactive use expected) ran privileged net.exe + win-log cli cl Security on WIN-PROD-WEB02. Anomalous.",+ "expected_tactics": [+ "TA0005",+ "TA0006"+ ],+ "expected_techniques": [+ "T1078.001",+ "T1070.001"+ ],+ "severity": "high",+ "response_class": "disable_account",+ "evidence_keywords": [+ "service account",+ "wevtutil",+ "log clear",+ "[email protected]",+ "WIN-PROD-WEB02"+ ],+ "original_title": "Privileged command run as service account on WIN-PROD-WEB02",+ "original_description": "Service account [email protected] (no interactive use expected) ran privileged net.exe + wevtutil cl Security on WIN-PROD-WEB02. Anomalous."+ },+ {+ "id": "INC-EVAL-056",+ "template_id": "phishing-macro-email",+ "template_index": 0,+ "adversary_intensity": "heavy",+ "title": "narrow-cast baiting email with off1ce-automation routine-laden attachment delivered to [email protected]",+ "description": "Inbound email from 10.0.99.42 delivered an Office document with a malicious v\u200bba off1ce-automation routine to [email protected]. Attachment opened on LIN-DB-REPLICA; off1ce-automation routine spawned cm\u200bd.exe and downloaded a follow-on artifact from a known Scattered Spider infrastructure.",+ "expected_tactics": [+ "TA0001",+ "TA0002"+ ],+ "expected_techniques": [+ "T1566.001",+ "T1059.005"+ ],+ "severity": "high",+ "response_class": "block_indicator",+ "evidence_keywords": [+ "phishing email",+ "macro",+ "10.0.99.42",+ "LIN-DB-REPLICA",+ "[email protected]",+ "stage-2 payload"+ ],+ "original_title": "Spear-phishing email with macro-laden attachment delivered to [email protected]",+ "original_description": "Inbound email from 10.0.99.42 delivered an Office document with a malicious VBA macro to [email protected]. Attachment opened on LIN-DB-REPLICA; macro spawned cmd.exe and downloaded a stage-2 payload from a known Scattered Spider infrastructure."+ },+ {+ "id": "INC-EVAL-057",+ "template_id": "webapp-sqli-ssrf-exploit",+ "template_index": 1,+ "adversary_intensity": "light",+ "title": "Exploitation of public-facing web app on AWS-EC2-PROD-API",+ "description": "WAF logs show SQL-injection and SSRF probes from 172.16.50.7 against the application on AWS-EC2-PROD-API. One request returned 200 with internal cloud-metadata content. Likely exploitation of CVE-2024-1234.",+ "expected_tactics": [+ "TA0001",+ "TA0007"+ ],+ "expected_techniques": [+ "T1190",+ "T1082"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "WAF",+ "SQL injection",+ "SSRF",+ "CVE-2024-1234",+ "AWS-EC2-PROD-API",+ "172.16.50.7"+ ],+ "original_title": "Exploitation of public-facing web app on AWS-EC2-PROD-API",+ "original_description": "WAF logs show SQL-injection and SSRF probes from 172.16.50.7 against the application on AWS-EC2-PROD-API. One request returned 200 with internal cloud-metadata content. Likely exploitation of CVE-2024-1234."+ },+ {+ "id": "INC-EVAL-058",+ "template_id": "confluence-watering-hole",+ "template_index": 2,+ "adversary_intensity": "medium",+ "title": "Watering-hole exploit served from internal Confluence by 198.51.100.23",+ "description": "Internal Confluence page injected with malicious JavaScript by 198.51.100.23. Drive-by exploit triggered browser exploitation on multiple visitors including [email protected]. Linked to APT29 TTPs.",+ "expected_tactics": [+ "TA0001",+ "TA0002"+ ],+ "expected_techniques": [+ "T1189",+ "T1203"+ ],+ "severity": "high",+ "response_class": "block_indicator",+ "evidence_keywords": [+ "watering hole",+ "drive-by",+ "Confluence",+ "198.51.100.23",+ "[email protected]",+ "APT29"+ ],+ "original_title": "Watering-hole exploit served from internal Confluence by 198.51.100.23",+ "original_description": "Internal Confluence page injected with malicious JavaScript by 198.51.100.23. Drive-by exploit triggered browser exploitation on multiple visitors including [email protected]. Linked to APT29 TTPs."+ },+ {+ "id": "INC-EVAL-059",+ "template_id": "npm-supply-chain",+ "template_index": 3,+ "adversary_intensity": "light",+ "title": "Supply-chain compromise: malicious npm package on MAC-CFO-LAPTOP",+ "description": "CI pipeline on MAC-CFO-LAPTOP installed compromised npm package `event-stream`. Post-install hook executed reverse shell to 198.51.100.23. Build artefacts may be tainted.",+ "expected_tactics": [+ "TA0001",+ "TA0002"+ ],+ "expected_techniques": [+ "T1195.001",+ "T1059.007"+ ],+ "severity": "critical",+ "response_class": "rollback_change",+ "evidence_keywords": [+ "supply chain",+ "npm package",+ "event-stream",+ "post-install",+ "MAC-CFO-LAPTOP",+ "198.51.100.23"+ ],+ "original_title": "Supply-chain compromise: malicious npm package on MAC-CFO-LAPTOP",+ "original_description": "CI pipeline on MAC-CFO-LAPTOP installed compromised npm package `event-stream`. Post-install hook executed reverse shell to 198.51.100.23. Build artefacts may be tainted."+ },+ {+ "id": "INC-EVAL-060",+ "template_id": "usb-autorun-airgap",+ "template_index": 4,+ "adversary_intensity": "heavy",+ "title": "Malicious portable storage stick autorun on air-gapped host MAC-LEGAL-LAPTOP",+ "description": "portable storage stick device inserted on air-gapped MAC-LEGAL-LAPTOP by [email protected]. AutoRun executed py-runtime stager that collected local files. Data staged in C:\\Temp\\.",+ "expected_tactics": [+ "TA0001",+ "TA0009"+ ],+ "expected_techniques": [+ "T1091",+ "T1005"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "USB",+ "autorun",+ "air-gapped",+ "MAC-LEGAL-LAPTOP",+ "[email protected]",+ "Python stager"+ ],+ "original_title": "Malicious USB autorun on air-gapped host MAC-LEGAL-LAPTOP",+ "original_description": "USB device inserted on air-gapped MAC-LEGAL-LAPTOP by [email protected]. AutoRun executed Python stager that collected local files. Data staged in C:\\Temp\\."+ },+ {+ "id": "INC-EVAL-061",+ "template_id": "oauth-consent-phish",+ "template_index": 5,+ "adversary_intensity": "medium",+ "title": "delegated grant consent phishing targeting [email protected]",+ "description": "Malicious delegated grant application granted Mail.Read and Files.Read.All scopes by [email protected]. Inbox forwarding rule created sending mail to 172.16.50.7.",+ "expected_tactics": [+ "TA0001",+ "TA0006"+ ],+ "expected_techniques": [+ "T1528",+ "T1550.001"+ ],+ "severity": "high",+ "response_class": "disable_account",+ "evidence_keywords": [+ "OAuth consent",+ "Mail.Read",+ "Files.Read.All",+ "[email protected]",+ "172.16.50.7",+ "forwarding rule"+ ],+ "original_title": "OAuth consent phishing targeting [email protected]",+ "original_description": "Malicious OAuth application granted Mail.Read and Files.Read.All scopes by [email protected]. Inbox forwarding rule created sending mail to 172.16.50.7."+ },+ {+ "id": "INC-EVAL-062",+ "template_id": "powershell-obfuscated-dropper",+ "template_index": 6,+ "adversary_intensity": "light",+ "title": "Obfuscated powershell dropper executed on WIN-DC-PRIMARY",+ "description": "powershell dropper executed on WIN-DC-PRIMARY by [email protected]; payload base64-encoded and decoded in-memory. Linked to LockBit 3.0 ransomware staging.",+ "expected_tactics": [+ "TA0002",+ "TA0005"+ ],+ "expected_techniques": [+ "T1059.001",+ "T1027"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "powershell",+ "obfuscated",+ "base64",+ "WIN-DC-PRIMARY",+ "[email protected]",+ "LockBit 3.0"+ ],+ "original_title": "Obfuscated PowerShell dropper executed on WIN-DC-PRIMARY",+ "original_description": "PowerShell dropper executed on WIN-DC-PRIMARY by [email protected]; payload base64-encoded and decoded in-memory. Linked to LockBit 3.0 ransomware staging."+ },+ {+ "id": "INC-EVAL-063",+ "template_id": "certutil-download-cradle",+ "template_index": 7,+ "adversary_intensity": "medium",+ "title": "Living-off-the-land: certutil download cradle on WIN-PROD-WEB02",+ "description": "certutil.exe -urlcache invoked from cmd.exe on WIN-PROD-WEB02. cmd.exe was spawned by outlook.exe. Payload downloaded from 91.134.231.15.",+ "expected_tactics": [+ "TA0002",+ "TA0005"+ ],+ "expected_techniques": [+ "T1105",+ "T1218.009"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "certutil",+ "urlcache",+ "outlook.exe",+ "WIN-PROD-WEB02",+ "91.134.231.15",+ "download cradle"+ ],+ "original_title": "Living-off-the-land: certutil download cradle on WIN-PROD-WEB02",+ "original_description": "certutil.exe -urlcache invoked from cmd.exe on WIN-PROD-WEB02. cmd.exe was spawned by outlook.exe. Payload downloaded from 91.134.231.15."+ },+ {+ "id": "INC-EVAL-064",+ "template_id": "docker-runtime-abuse",+ "template_index": 8,+ "adversary_intensity": "light",+ "title": "Container runtime abuse: malicious `docker run` on WIN-FILE-SHARE",+ "description": "Unauthenticated Docker API on WIN-FILE-SHARE exploited from 198.51.100.23. Container with cryptominer spawned. CPU on host saturated to 95%.",+ "expected_tactics": [+ "TA0002",+ "TA0001",+ "TA0040"+ ],+ "expected_techniques": [+ "T1610",+ "T1059.004",+ "T1496"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "docker",+ "container",+ "cryptominer",+ "miner",+ "WIN-FILE-SHARE",+ "198.51.100.23"+ ],+ "original_title": "Container runtime abuse: malicious `docker run` on WIN-FILE-SHARE",+ "original_description": "Unauthenticated Docker API on WIN-FILE-SHARE exploited from 198.51.100.23. Container with cryptominer spawned. CPU on host saturated to 95%."+ },+ {+ "id": "INC-EVAL-065",+ "template_id": "wmi-event-subscription",+ "template_index": 9,+ "adversary_intensity": "medium",+ "title": "Malicious windows-mgmt-fabric subautomation snippetion on LIN-BUILD-CI03",+ "description": "Permanent windows-mgmt-fabric event subautomation snippetion created on LIN-BUILD-CI03 by [email protected]. Consumer runs transformd automation snippet. Persistence + code activation mechanism.",+ "expected_tactics": [+ "TA0002",+ "TA0003"+ ],+ "expected_techniques": [+ "T1546.003",+ "T1059.001"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "WMI",+ "subscription",+ "permanent",+ "LIN-BUILD-CI03",+ "[email protected]",+ "encoded script"+ ],+ "original_title": "Malicious WMI subscription on LIN-BUILD-CI03",+ "original_description": "Permanent WMI event subscription created on LIN-BUILD-CI03 by [email protected]. Consumer runs encoded script. Persistence + execution mechanism."+ },+ {+ "id": "INC-EVAL-066",+ "template_id": "registry-run-persistence",+ "template_index": 10,+ "adversary_intensity": "heavy",+ "title": "winreg autorun stanza key long-term foothold created by [email protected] on LIN-DB-REPLICA",+ "description": "New value written to HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run on LIN-DB-REPLICA. Points to roaming binary signed with revoked cert. Linked to Lazarus.",+ "expected_tactics": [+ "TA0003"+ ],+ "expected_techniques": [+ "T1547.001"+ ],+ "severity": "medium",+ "response_class": "rollback_change",+ "evidence_keywords": [+ "registry run",+ "persistence",+ "revoked cert",+ "LIN-DB-REPLICA",+ "[email protected]",+ "Lazarus"+ ],+ "original_title": "Registry Run key persistence created by [email protected] on LIN-DB-REPLICA",+ "original_description": "New value written to HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run on LIN-DB-REPLICA. Points to roaming binary signed with revoked cert. Linked to Lazarus."+ },+ {+ "id": "INC-EVAL-067",+ "template_id": "scheduled-task-persistence",+ "template_index": 11,+ "adversary_intensity": "medium",+ "title": "Scheduled task persistence on AWS-Ecallback infra-PROD-API",+ "description": "Hidden scheduled task created on AWS-Ecallback infra-PROD-API by [email protected]: triggers every 30 minutes, runs scr1pt from %APPDATA%\\Roaming. Persistence mechanism.",+ "expected_tactics": [+ "TA0003"+ ],+ "expected_techniques": [+ "T1053.005"+ ],+ "severity": "medium",+ "response_class": "rollback_change",+ "evidence_keywords": [+ "scheduled task",+ "persistence",+ "APPDATA",+ "AWS-EC2-PROD-API",+ ],+ "original_title": "Scheduled task persistence on AWS-EC2-PROD-API",+ "original_description": "Hidden scheduled task created on AWS-EC2-PROD-API by [email protected]: triggers every 30 minutes, runs script from %APPDATA%\\Roaming. Persistence mechanism."+ },+ {+ "id": "INC-EVAL-068",+ "template_id": "uefi-firmware-implant",+ "template_index": 12,+ "adversary_intensity": "light",+ "title": "Firmware implant detected on UEFI partition of WIN-PROD-WEB02",+ "description": "UEFI secure-boot violation on WIN-PROD-WEB02. Unknown module detected in firmware. Signature matches MosaicRegressor implant.",+ "expected_tactics": [+ "TA0003",+ "TA0005"+ ],+ "expected_techniques": [+ "T1542.001",+ "T1027.002"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "UEFI",+ "firmware",+ "implant",+ "secure boot",+ "WIN-PROD-WEB02",+ "MosaicRegressor"+ ],+ "original_title": "Firmware implant detected on UEFI partition of WIN-PROD-WEB02",+ "original_description": "UEFI secure-boot violation on WIN-PROD-WEB02. Unknown module detected in firmware. Signature matches MosaicRegressor implant."+ },+ {+ "id": "INC-EVAL-069",+ "template_id": "cron-backdoor",+ "template_index": 13,+ "adversary_intensity": "medium",+ "title": "Backdoor cron job installed on LIN-DB-REPLICA",+ "description": "/etc/cron.d entry created by [email protected] on LIN-DB-REPLICA. Reverse shell b\u200beacon to 45.142.122.111 every 5 minutes.",+ "expected_tactics": [+ "TA0003",+ "TA0011"+ ],+ "expected_techniques": [+ "T1053.003",+ "T1071.001"+ ],+ "severity": "high",+ "response_class": "rollback_change",+ "evidence_keywords": [+ "cron",+ "backdoor",+ "reverse shell",+ "LIN-DB-REPLICA",+ "[email protected]",+ "45.142.122.111"+ ],+ "original_title": "Backdoor cron job installed on LIN-DB-REPLICA",+ "original_description": "/etc/cron.d entry created by [email protected] on LIN-DB-REPLICA. Reverse shell beacon to 45.142.122.111 every 5 minutes."+ },+ {+ "id": "INC-EVAL-070",+ "template_id": "uac-bypass-fodhelper",+ "template_index": 14,+ "adversary_intensity": "heavy",+ "title": "consent-prompt sidestep observed on LIN-BUILD-CI03",+ "description": "f0dhelper.exe abuse on LIN-BUILD-CI03 by [email protected]; auto-rights step-up triggered without prompt. Process tree shows rights uplift to SYSTEM.",+ "expected_tactics": [+ "TA0004",+ "TA0005"+ ],+ "expected_techniques": [+ "T1548.002"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "UAC",+ "fodhelper",+ "auto-elevation",+ "LIN-BUILD-CI03",+ "[email protected]",+ "SYSTEM"+ ],+ "original_title": "UAC bypass observed on LIN-BUILD-CI03",+ "original_description": "fodhelper.exe abuse on LIN-BUILD-CI03 by [email protected]; auto-elevation triggered without prompt. Process tree shows escalation to SYSTEM."+ },+ {+ "id": "INC-EVAL-071",+ "template_id": "k8s-privileged-pod-escape",+ "template_index": 15,+ "adversary_intensity": "heavy",+ "title": "isolation-layer break via host-shared workload on WIN-PROD-WEB02",+ "description": "Kubernetes host-shared workload created on WIN-PROD-WEB02 by [email protected]. cgroup escape to host namespace observed. n0de runtime filesystem accessed.",+ "expected_tactics": [+ "TA0004",+ "TA0007"+ ],+ "expected_techniques": [+ "T1611",+ "T1082"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "kubernetes",+ "privileged pod",+ "container escape",+ "cgroup",+ "WIN-PROD-WEB02",+ ],+ "original_title": "Container escape via privileged pod on WIN-PROD-WEB02",+ "original_description": "Kubernetes privileged pod created on WIN-PROD-WEB02 by [email protected]. cgroup escape to host namespace observed. Node filesystem accessed."+ },+ {+ "id": "INC-EVAL-072",+ "template_id": "linux-suid-abuse",+ "template_index": 16,+ "adversary_intensity": "heavy",+ "title": "Linux setuser bit binary abuse on WIN-DEVOPS-LT",+ "description": "Custom setuser bit binary discovered in /tmp on WIN-DEVOPS-LT; allows arbitrary command code activation as root. Likely rights uplift by [email protected].",+ "expected_tactics": [+ "TA0004"+ ],+ "expected_techniques": [+ "T1548.001"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "SUID",+ "/tmp",+ "root escalation",+ "WIN-DEVOPS-LT",+ ],+ "original_title": "Linux SUID binary abuse on WIN-DEVOPS-LT",+ "original_description": "Custom SUID binary discovered in /tmp on WIN-DEVOPS-LT; allows arbitrary command execution as root. Likely escalation by [email protected]."+ },+ {+ "id": "INC-EVAL-073",+ "template_id": "process-hollowing-svchost",+ "template_index": 17,+ "adversary_intensity": "light",+ "title": "Memory-only fileless implant in svchost on LIN-EDGE-VPN02",+ "description": "Process hollowing detected on LIN-EDGE-VPN02: svchost.exe replaced with Cobalt Strike beacon to 45.142.122.111. No disk artefacts. Linked to LockBit 3.0.",+ "expected_tactics": [+ "TA0002",+ "TA0005"+ ],+ "expected_techniques": [+ "T1055.012",+ "T1620"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "process hollowing",+ "fileless",+ "svchost",+ "Cobalt Strike",+ "LIN-EDGE-VPN02",+ "45.142.122.111"+ ],+ "original_title": "Memory-only fileless implant in svchost on LIN-EDGE-VPN02",+ "original_description": "Process hollowing detected on LIN-EDGE-VPN02: svchost.exe replaced with Cobalt Strike beacon to 45.142.122.111. No disk artefacts. Linked to LockBit 3.0."+ },+ {+ "id": "INC-EVAL-074",+ "template_id": "event-log-cleared",+ "template_index": 18,+ "adversary_intensity": "heavy",+ "title": "evidence cleanup: Windows event telemetry erased on AZURE-VM-FIN-001",+ "description": "Security event telemetry erased on AZURE-VM-FIN-001 by [email protected]. win event tool.exe cl Security observed in command-line telemetry.",+ "expected_tactics": [+ "TA0005"+ ],+ "expected_techniques": [+ "T1070.001"+ ],+ "severity": "high",+ "response_class": "escalate",+ "evidence_keywords": [+ "wevtutil",+ "log cleared",+ "indicator removal",+ "AZURE-VM-FIN-001",+ ],+ "original_title": "Indicator removal: Windows event log cleared on AZURE-VM-FIN-001",+ "original_description": "Security event log cleared on AZURE-VM-FIN-001 by [email protected]. wevtutil.exe cl Security observed in command-line telemetry."+ },+ {+ "id": "INC-EVAL-075",+ "template_id": "disable-edr-tooling",+ "template_index": 19,+ "adversary_intensity": "medium",+ "title": "Disable security tooling on LIN-OBS-LOGGER",+ "description": "[email protected] attempted to stop Defender, CrowdStrike, and Sysmon on LIN-OBS-LOGGER. Tampering telemetry triggered alert.",+ "expected_tactics": [+ "TA0005"+ ],+ "expected_techniques": [+ "T1562.001"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "defender",+ "crowdstrike",+ "sysmon",+ "tampering",+ "LIN-OBS-LOGGER",+ ],+ "original_title": "Disable security tooling on LIN-OBS-LOGGER",+ "original_description": "[email protected] attempted to stop Defender, CrowdStrike, and Sysmon on LIN-OBS-LOGGER. Tampering telemetry triggered alert."+ },+ {+ "id": "INC-EVAL-076",+ "template_id": "lsass-memory-dump",+ "template_index": 20,+ "adversary_intensity": "light",+ "title": "LSASS memory dump on WIN-DEVOPS-LT by [email protected]",+ "description": "comsvcs.dll MiniDump observed on WIN-DEVOPS-LT. lsass.exe memory dumped to C:\\Windows\\Temp\\. Mimikatz signatures detected.",+ "expected_tactics": [+ "TA0006"+ ],+ "expected_techniques": [+ "T1003.001"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "lsass",+ "minidump",+ "comsvcs",+ "mimikatz",+ "WIN-DEVOPS-LT",+ ],+ "original_title": "LSASS memory dump on WIN-DEVOPS-LT by [email protected]",+ "original_description": "comsvcs.dll MiniDump observed on WIN-DEVOPS-LT. lsass.exe memory dumped to C:\\Windows\\Temp\\. Mimikatz signatures detected."+ },+ {+ "id": "INC-EVAL-077",+ "template_id": "credential-spray",+ "template_index": 21,+ "adversary_intensity": "light",+ "title": "Brute-force credentia1 spray against [email protected] from 172.16.50.7",+ "description": "credentia1 spray from 172.16.50.7 against [email protected]. 1500 password attempts in 30 minutes. One success followed by anomalous Azure AD sign-in.",+ "expected_tactics": [+ "TA0006"+ ],+ "expected_techniques": [+ "T1110.003"+ ],+ "severity": "high",+ "response_class": "disable_account",+ "evidence_keywords": [+ "brute force",+ "credential spray",+ "[email protected]",+ "172.16.50.7",+ "azure ad"+ ],+ "original_title": "Brute-force credential spray against [email protected] from 172.16.50.7",+ "original_description": "Credential spray from 172.16.50.7 against [email protected]. 1500 password attempts in 30 minutes. One success followed by anomalous Azure AD sign-in."+ },+ {+ "id": "INC-EVAL-078",+ "template_id": "kerberoasting",+ "template_index": 22,+ "adversary_intensity": "medium",+ "title": "kerb-ticket roasting from WIN-FILE-SHARE",+ "description": "long-running unit account tg\u200bs tickets requested en-masse from WIN-FILE-SHARE by [email protected]. AES256 \u2192 RC4 downgrade observed. secrets extractor tooling indicators.",+ "expected_tactics": [+ "TA0006",+ "TA0008"+ ],+ "expected_techniques": [+ "T1558.003",+ "T1021.001"+ ],+ "severity": "critical",+ "response_class": "disable_account",+ "evidence_keywords": [+ "kerberoast",+ "TGS",+ "RC4",+ "mimikatz",+ "WIN-FILE-SHARE",+ ],+ "original_title": "Kerberoasting from WIN-FILE-SHARE",+ "original_description": "Service account TGS tickets requested en-masse from WIN-FILE-SHARE by [email protected]. AES256 \u2192 RC4 downgrade observed. Mimikatz tooling indicators."+ },+ {+ "id": "INC-EVAL-079",+ "template_id": "ad-dcsync",+ "template_index": 23,+ "adversary_intensity": "heavy",+ "title": "Active Directory msrpc replica-pull abuse from non-DC host AZURE-VM-FIN-001",+ "description": "dir-sync abuse rights abused from AZURE-VM-FIN-001 by [email protected]. All domain challenge-response auth hashes replicated. Severe login secret exposure.",+ "expected_tactics": [+ "TA0006",+ "TA0004"+ ],+ "expected_techniques": [+ "T1003.006",+ "T1078.002"+ ],+ "severity": "critical",+ "response_class": "disable_account",+ "evidence_keywords": [+ "dcsync",+ "replication",+ "ntlm hash",+ "AZURE-VM-FIN-001",+ ],+ "original_title": "Active Directory DCSync from non-DC host AZURE-VM-FIN-001",+ "original_description": "Replication rights abused from AZURE-VM-FIN-001 by [email protected]. All domain NTLM hashes replicated. Severe credential exposure."+ },+ {+ "id": "INC-EVAL-080",+ "template_id": "saml-golden-ticket",+ "template_index": 24,+ "adversary_intensity": "heavy",+ "title": "federation token golden-ticket: forged assertion targeting [email protected]",+ "description": "Forged federation token assertion detected for [email protected]. Attacker pivoted to Azure AD; account walking the directoryion followed from 10.0.99.42.",+ "expected_tactics": [+ "TA0006",+ "TA0007"+ ],+ "expected_techniques": [+ "T1606.002",+ "T1087.002"+ ],+ "severity": "critical",+ "response_class": "disable_account",+ "evidence_keywords": [+ "saml",+ "golden ticket",+ "forged",+ "azure ad",+ "[email protected]",+ "10.0.99.42"+ ],+ "original_title": "SAML golden-ticket: forged assertion targeting [email protected]",+ "original_description": "Forged SAML assertion detected for [email protected]. Attacker pivoted to Azure AD; account enumeration followed from 10.0.99.42."+ },+ {+ "id": "INC-EVAL-081",+ "template_id": "ldap-bloodhound-discovery",+ "template_index": 25,+ "adversary_intensity": "heavy",+ "title": "Domain iterating acrossion from LIN-OBS-LOGGER",+ "description": "l\u200bdap scout-stage from LIN-OBS-LOGGER by [email protected]: bl0odhound-style queries iterating acrossing users, groups, ACLs.",+ "expected_tactics": [+ "TA0007"+ ],+ "expected_techniques": [+ "T1087.002"+ ],+ "severity": "medium",+ "response_class": "monitor",+ "evidence_keywords": [+ "ldap",+ "bloodhound",+ "domain enumeration",+ "LIN-OBS-LOGGER",+ ],+ "original_title": "Domain enumeration from LIN-OBS-LOGGER",+ "original_description": "ldap discovery from LIN-OBS-LOGGER by [email protected]: BloodHound-style queries enumerating users, groups, ACLs."+ },+ {+ "id": "INC-EVAL-082",+ "template_id": "smb-share-enumeration",+ "template_index": 26,+ "adversary_intensity": "light",+ "title": "Network share enumeration on WIN-FIN-DB01",+ "description": "Mass SMB share enumeration from WIN-FIN-DB01 by [email protected]; net.exe and powershell Get-SmbShare invocations across /24 subnet.",+ "expected_tactics": [+ "TA0007"+ ],+ "expected_techniques": [+ "T1135"+ ],+ "severity": "medium",+ "response_class": "monitor",+ "evidence_keywords": [+ "smb",+ "net.exe",+ "Get-SmbShare",+ "share enumeration",+ "WIN-FIN-DB01",+ ],+ "original_title": "Network share enumeration on WIN-FIN-DB01",+ "original_description": "Mass SMB share enumeration from WIN-FIN-DB01 by [email protected]; net.exe and PowerShell Get-SmbShare invocations across /24 subnet."+ },+ {+ "id": "INC-EVAL-083",+ "template_id": "pass-the-hash-lateral",+ "template_index": 27,+ "adversary_intensity": "medium",+ "title": "secret-hash replay from GCP-GKE-n\u200bode.js-04 to WIN-DEVOPS-LT",+ "description": "secret-hash replay horizontal hop from GCP-GKE-n\u200bode.js-04 to WIN-DEVOPS-LT by [email protected]. Golden ticket indicators present. Linked to MosaicRoutward trafficor.",+ "expected_tactics": [+ "TA0008",+ "TA0006"+ ],+ "expected_techniques": [+ "T1550.002",+ "T1558.001"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "pass-the-hash",+ "golden ticket",+ "GCP-GKE-NODE-04",+ "WIN-DEVOPS-LT",+ "[email protected]",+ "MosaicRegressor"+ ],+ "original_title": "Pass-the-hash from GCP-GKE-NODE-04 to WIN-DEVOPS-LT",+ "original_description": "Pass-the-hash lateral movement from GCP-GKE-NODE-04 to WIN-DEVOPS-LT by [email protected]. Golden ticket indicators present. Linked to MosaicRegressor."+ },+ {+ "id": "INC-EVAL-084",+ "template_id": "rdp-lateral-movement",+ "template_index": 28,+ "adversary_intensity": "heavy",+ "title": "ts/mstsc sess side-to-side traversal from MAC-LEGAL-LAPTOP",+ "description": "Anomalous ts/mstsc sess session from MAC-LEGAL-LAPTOP ([email protected]) to LIN-EDGE-VPN02 outside business hours. Source admin not normal for LIN-EDGE-VPN02.",+ "expected_tactics": [+ "TA0008"+ ],+ "expected_techniques": [+ "T1021.001"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "rdp",+ "lateral movement",+ "outside hours",+ "MAC-LEGAL-LAPTOP",+ "LIN-EDGE-VPN02",+ ],+ "original_title": "RDP lateral movement from MAC-LEGAL-LAPTOP",+ "original_description": "Anomalous RDP session from MAC-LEGAL-LAPTOP ([email protected]) to LIN-EDGE-VPN02 outside business hours. Source admin not normal for LIN-EDGE-VPN02."+ },+ {+ "id": "INC-EVAL-085",+ "template_id": "wmi-lateral-execution",+ "template_index": 29,+ "adversary_intensity": "medium",+ "title": "WMI side-to-side execution from WIN-FILE-SHARE to MAC-CFO-LAPTOP",+ "description": "wmic.exe /node:MAC-CFO-LAPTOP process call create observed from WIN-FILE-SHARE by [email protected]. Remote command execution; payload from 91.134.231.15.",+ "expected_tactics": [+ "TA0008",+ "TA0002"+ ],+ "expected_techniques": [+ "T1047"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "wmic",+ "lateral",+ "WIN-FILE-SHARE",+ "MAC-CFO-LAPTOP",+ "[email protected]",+ "91.134.231.15"+ ],+ "original_title": "WMI lateral execution from WIN-FILE-SHARE to MAC-CFO-LAPTOP",+ "original_description": "wmic.exe /node:MAC-CFO-LAPTOP process call create observed from WIN-FILE-SHARE by [email protected]. Remote command execution; payload from 91.134.231.15."+ },+ {+ "id": "INC-EVAL-086",+ "template_id": "bulk-pii-download",+ "template_index": 30,+ "adversary_intensity": "heavy",+ "title": "Bulk user identity data download by [email protected]",+ "description": "[email protected] downloaded >10 GB of client account rows from production database from WIN-EXCHANGE-01. Outside normal access p@ttern.",+ "expected_tactics": [+ "TA0009",+ "TA0010"+ ],+ "expected_techniques": [+ "T1005",+ "T1041"+ ],+ "severity": "critical",+ "response_class": "disable_account",+ "evidence_keywords": [+ "bulk download",+ "pii",+ "customer record",+ "WIN-EXCHANGE-01",+ ],+ "original_title": "Bulk PII download by [email protected]",+ "original_description": "[email protected] downloaded >10 GB of customer records from production database from WIN-EXCHANGE-01. Outside normal access pattern."+ },+ {+ "id": "INC-EVAL-087",+ "template_id": "clipboard-keylogger",+ "template_index": 31,+ "adversary_intensity": "heavy",+ "title": "clip-store logging resident dropper on WIN-PROD-WEB02",+ "description": "clip-store contents from WIN-PROD-WEB02 ([email protected]) being captured to %APPDATA%\\Local\\. Captures span 2 hours and include auth-tokens and crypto addresses.",+ "expected_tactics": [+ "TA0009"+ ],+ "expected_techniques": [+ "T1115"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "clipboard",+ "keylog",+ "credentials",+ "WIN-PROD-WEB02",+ ],+ "original_title": "Clipboard logging implant on WIN-PROD-WEB02",+ "original_description": "Clipboard contents from WIN-PROD-WEB02 ([email protected]) being captured to %APPDATA%\\Local\\. Captures span 2 hours and include credentials and crypto addresses."+ },+ {+ "id": "INC-EVAL-088",+ "template_id": "dns-tunnel-exfil",+ "template_index": 32,+ "adversary_intensity": "heavy",+ "title": "udp/53 covert trackling ex-bound siphonion from WIN-DC-SECONDARY",+ "description": "name-resolution volume from WIN-DC-SECONDARY 50\u00d7 baseline. TXT records contain base64-base64-wrapd payloads. Estimated exfil ~200 MB; destination 185.220.101.7.",+ "expected_tactics": [+ "TA0011",+ "TA0010"+ ],+ "expected_techniques": [+ "T1071.004",+ "T1048.003"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "dns tunnel",+ "txt records",+ "base64",+ "exfiltrat",+ "WIN-DC-SECONDARY",+ "185.220.101.7"+ ],+ "original_title": "DNS tunnelling exfiltration from WIN-DC-SECONDARY",+ "original_description": "DNS query volume from WIN-DC-SECONDARY 50\u00d7 baseline. TXT records contain base64-encoded payloads. Estimated exfil ~200 MB; destination 185.220.101.7."+ },+ {+ "id": "INC-EVAL-089",+ "template_id": "s3-exfil-cloud-storage",+ "template_index": 33,+ "adversary_intensity": "heavy",+ "title": "blob-store push target exfil: ex-bound data flow to attacker-controlled S3 from WIN-EXCHANGE-01",+ "description": "outward traffic from WIN-EXCHANGE-01 to aws://obj/atk-stage-192.168.1.100/proc-mem snapshot/ by [email protected]. 8 GB transferred over 20 minutes. CloudTrail PutObject events match.",+ "expected_tactics": [+ "TA0010"+ ],+ "expected_techniques": [+ "T1567.002"+ ],+ "severity": "critical",+ "response_class": "block_indicator",+ "evidence_keywords": [+ "s3",+ "cloud storage",+ "egress",+ "exfiltrat",+ "WIN-EXCHANGE-01",+ "192.168.1.100",+ ],+ "original_title": "Cloud storage exfil: data egress to attacker-controlled S3 from WIN-EXCHANGE-01",+ "original_description": "Egress from WIN-EXCHANGE-01 to s3://atk-stage-192.168.1.100/dump/ by [email protected]. 8 GB transferred over 20 minutes. CloudTrail PutObject events match."+ },+ {+ "id": "INC-EVAL-090",+ "template_id": "personal-drive-exfil",+ "template_index": 34,+ "adversary_intensity": "heavy",+ "title": "personal cloud bucket exfil by [email protected]",+ "description": "[email protected] on GCP-GKE-j$-runtime daemon-04 push-outed 4 GB to personal consumer-cloud drive. Files include source code and customer personal data.",+ "expected_tactics": [+ "TA0009",+ "TA0010"+ ],+ "expected_techniques": [+ "T1567.002",+ "T1005"+ ],+ "severity": "critical",+ "response_class": "disable_account",+ "evidence_keywords": [+ "google drive",+ "personal",+ "exfiltrat",+ "source code",+ "pii",+ "GCP-GKE-NODE-04",+ ],+ "original_title": "Personal Drive exfil by [email protected]",+ "original_description": "[email protected] on GCP-GKE-NODE-04 uploaded 4 GB to personal Google Drive. Files include source code and customer PII."+ },+ {+ "id": "INC-EVAL-091",+ "template_id": "dga-c2",+ "template_index": 35,+ "adversary_intensity": "medium",+ "title": "DGA-based C2 traffic from GCP-GKE-n0de runtime-04",+ "description": "DGA traffic from GCP-GKE-n0de runtime-04 observed; 200+ NXDomain replies/min, IoCs match Volt Typhoon epoch 5. Beacons to 45.142.122.111.",+ "expected_tactics": [+ "TA0011"+ ],+ "expected_techniques": [+ "T1568.002"+ ],+ "severity": "high",+ "response_class": "block_indicator",+ "evidence_keywords": [+ "dga",+ "domain generation",+ "nxdomain",+ "beacon",+ "GCP-GKE-NODE-04",+ "45.142.122.111",+ "Volt Typhoon"+ ],+ "original_title": "DGA-based C2 traffic from GCP-GKE-NODE-04",+ "original_description": "DGA traffic from GCP-GKE-NODE-04 observed; 200+ NXDomain replies/min, IoCs match Volt Typhoon epoch 5. Beacons to 45.142.122.111."+ },+ {+ "id": "INC-EVAL-092",+ "template_id": "https-c2-beacon",+ "template_index": 36,+ "adversary_intensity": "heavy",+ "title": "HTTPS c\u200b2 regular check-in from LIN-BUILD-CI03 to 91.134.231.15",+ "description": "Periodic tls callback from LIN-BUILD-CI03 to 91.134.231.15 every 60 seconds with low jitter. tls fingerprint hash fingerprint matches red-team-grade dropper.",+ "expected_tactics": [+ "TA0011"+ ],+ "expected_techniques": [+ "T1071.001"+ ],+ "severity": "critical",+ "response_class": "block_indicator",+ "evidence_keywords": [+ "c2",+ "beacon",+ "ja3",+ "Cobalt Strike",+ "LIN-BUILD-CI03",+ "91.134.231.15"+ ],+ "original_title": "HTTPS C2 beacon from LIN-BUILD-CI03 to 91.134.231.15",+ "original_description": "Periodic HTTPS beacon from LIN-BUILD-CI03 to 91.134.231.15 every 60 seconds with low jitter. JA3 fingerprint matches Cobalt Strike."+ },+ {+ "id": "INC-EVAL-093",+ "template_id": "ransomware-encryption",+ "template_index": 37,+ "adversary_intensity": "medium",+ "title": "Ransomware encryption in progress on WIN-FIN-DB01",+ "description": "Mass file rename observed on WIN-FIN-DB01 ([email protected]); ..pwned extension applied to ~20 k files. Ransomware note R3ADM3-FIN7.txt found.",+ "expected_tactics": [+ "TA0040"+ ],+ "expected_techniques": [+ "T1486"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "ransomware",+ "encrypt",+ "rename",+ "ransom note",+ "WIN-FIN-DB01",+ "[email protected]",+ "FIN7"+ ],+ "original_title": "Ransomware encryption in progress on WIN-FIN-DB01",+ "original_description": "Mass file rename observed on WIN-FIN-DB01 ([email protected]); ..pwned extension applied to ~20 k files. Ransomware note R3ADM3-FIN7.txt found."+ },+ {+ "id": "INC-EVAL-094",+ "template_id": "xmrig-cryptominer",+ "template_index": 38,+ "adversary_intensity": "medium",+ "title": "compute hijack for currencyr execution on WIN-DC-PRIMARY",+ "description": "xm\u200brig cycles-stealing process spawned on WIN-DC-PRIMARY; CPU saturated to 95%. Mining pool 192.168.1.100:5555. Linked to MosaicRex-bound flowor.",+ "expected_tactics": [+ "TA0002",+ "TA0040"+ ],+ "expected_techniques": [+ "T1496"+ ],+ "severity": "medium",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "xmrig",+ "miner",+ "cryptomine",+ "WIN-DC-PRIMARY",+ "192.168.1.100",+ "MosaicRegressor"+ ],+ "original_title": "Cryptominer execution on WIN-DC-PRIMARY",+ "original_description": "XMRig miner spawned on WIN-DC-PRIMARY; CPU saturated to 95%. Mining pool 192.168.1.100:5555. Linked to MosaicRegressor."+ },+ {+ "id": "INC-EVAL-095",+ "template_id": "bec-wire-fraud",+ "template_index": 39,+ "adversary_intensity": "heavy",+ "title": "b\u200bec: payment redirect by [email protected]",+ "description": "directed baiting email spoofed CFO. ach payment instruction of two-fifty-K k initiated by [email protected] from GCP-GKE-n\u200bode.js-04 to threat-actor account. Linked to APT29.",+ "expected_tactics": [+ "TA0001",+ "TA0040"+ ],+ "expected_techniques": [+ "T1566.001",+ "T1657"+ ],+ "severity": "critical",+ "response_class": "escalate",+ "evidence_keywords": [+ "phishing",+ "spoofed cfo",+ "wire transfer",+ "$250",+ "[email protected]",+ "GCP-GKE-NODE-04",+ "APT29"+ ],+ "original_title": "BEC: payment redirect by [email protected]",+ "original_description": "Spear-phishing email spoofed CFO. Wire transfer of $250 k initiated by [email protected] from GCP-GKE-NODE-04 to threat-actor account. Linked to APT29."+ },+ {+ "id": "INC-EVAL-096",+ "template_id": "public-s3-bucket-pii",+ "template_index": 40,+ "adversary_intensity": "medium",+ "title": "Public object-store bucket exposing PII",+ "description": "object-store bucket world-readable; ~40k employee records accessible. CloudTrail shows external iterating acrossion from 91.134.231.15.",+ "expected_tactics": [+ "TA0009",+ "TA0010"+ ],+ "expected_techniques": [+ "T1530",+ "T1567.002"+ ],+ "severity": "critical",+ "response_class": "rollback_change",+ "evidence_keywords": [+ "s3",+ "public bucket",+ "pii",+ "cloudtrail",+ "91.134.231.15"+ ],+ "original_title": "Public S3 bucket exposing PII",+ "original_description": "S3 bucket world-readable; ~40k employee records accessible. CloudTrail shows external enumeration from 91.134.231.15."+ },+ {+ "id": "INC-EVAL-097",+ "template_id": "azure-ad-impossible-travel",+ "template_index": 41,+ "adversary_intensity": "heavy",+ "title": "Identity provider compromise \u2014 anomalous Azure AD sign-in for [email protected]",+ "description": "Successful Azure AD sign-in for [email protected] from 192.168.1.100 (impossible-travel from prior location). MFA satisfied via hijacked sess1on token.",+ "expected_tactics": [+ "TA0001",+ "TA0006"+ ],+ "expected_techniques": [+ "T1078.004",+ "T1550.001"+ ],+ "severity": "critical",+ "response_class": "disable_account",+ "evidence_keywords": [+ "azure ad",+ "impossible travel",+ "session token",+ "mfa",+ "[email protected]",+ "192.168.1.100"+ ],+ "original_title": "Identity provider compromise \u2014 anomalous Azure AD sign-in for [email protected]",+ "original_description": "Successful Azure AD sign-in for [email protected] from 192.168.1.100 (impossible-travel from prior location). MFA satisfied via stolen session token."+ },+ {+ "id": "INC-EVAL-098",+ "template_id": "ddos-syn-flood",+ "template_index": 42,+ "adversary_intensity": "heavy",+ "title": "d\u200bdos volumetric flood targeting public-facing WIN-HR-DESKTOP",+ "description": "L4 tcp half-open swarm from a botnet (>1M PPS) targeting WIN-HR-DESKTOP. Edge mitigation engaged but long-running unit degraded for 12 minutes.",+ "expected_tactics": [+ "TA0040"+ ],+ "expected_techniques": [+ "T1498.001"+ ],+ "severity": "high",+ "response_class": "block_indicator",+ "evidence_keywords": [+ "ddos",+ "syn flood",+ "botnet",+ "WIN-HR-DESKTOP",+ "1M PPS"+ ],+ "original_title": "DDoS volumetric flood targeting public-facing WIN-HR-DESKTOP",+ "original_description": "L4 SYN flood from a botnet (>1M PPS) targeting WIN-HR-DESKTOP. Edge mitigation engaged but service degraded for 12 minutes."+ },+ {+ "id": "INC-EVAL-099",+ "template_id": "insider-mailbox-export",+ "template_index": 43,+ "adversary_intensity": "medium",+ "title": "Insider preparing departure: large mailstore export by [email protected]",+ "description": "[email protected] exported full mailbox p\u200bst (8 GB) from MAC-LEGAL-LAPTOP. HR flag: notice given last week.",+ "expected_tactics": [+ "TA0009",+ "TA0010"+ ],+ "expected_techniques": [+ "T1114.002",+ "T1567.002"+ ],+ "severity": "high",+ "response_class": "disable_account",+ "evidence_keywords": [+ "mailbox export",+ "PST",+ "insider",+ "departure",+ "[email protected]",+ "MAC-LEGAL-LAPTOP"+ ],+ "original_title": "Insider preparing departure: large mailbox export by [email protected]",+ "original_description": "[email protected] exported full mailbox PST (8 GB) from MAC-LEGAL-LAPTOP. HR flag: notice given last week."+ },+ {+ "id": "INC-EVAL-100",+ "template_id": "office-vsto-addin",+ "template_index": 44,+ "adversary_intensity": "light",+ "title": "Malicious Office add-in installed for [email protected]",+ "description": "Office VSTO add-in registered under HKCU for [email protected] on WIN-FILE-SHARE; loads on every Outlook startup; beacons to 10.0.99.42.",+ "expected_tactics": [+ "TA0003",+ "TA0011"+ ],+ "expected_techniques": [+ "T1137.006",+ "T1071.001"+ ],+ "severity": "high",+ "response_class": "rollback_change",+ "evidence_keywords": [+ "office add-in",+ "vsto",+ "outlook",+ "[email protected]",+ "WIN-FILE-SHARE",+ "10.0.99.42"+ ],+ "original_title": "Malicious Office add-in installed for [email protected]",+ "original_description": "Office VSTO add-in registered under HKCU for [email protected] on WIN-FILE-SHARE; loads on every Outlook startup; beacons to 10.0.99.42."+ },+ {+ "id": "INC-EVAL-101",+ "template_id": "github-pat-leak",+ "template_index": 45,+ "adversary_intensity": "heavy",+ "title": "GitHub github-token leaked and abused from 45.142.122.111",+ "description": "dev-portal token belonging to [email protected] used from 45.142.122.111 to clone 14 closed repos. Token committed in public dotfiles repo 6 hours earlier.",+ "expected_tactics": [+ "TA0006",+ "TA0009"+ ],+ "expected_techniques": [+ "T1552.001",+ "T1213.003"+ ],+ "severity": "critical",+ "response_class": "disable_account",+ "evidence_keywords": [+ "github",+ "pat",+ "token",+ "private repo",+ "[email protected]",+ "45.142.122.111"+ ],+ "original_title": "GitHub PAT leaked and abused from 45.142.122.111",+ "original_description": "Personal access token belonging to [email protected] used from 45.142.122.111 to clone 14 private repos. Token committed in public dotfiles repo 6 hours earlier."+ },+ {+ "id": "INC-EVAL-102",+ "template_id": "ec2-imds-credential-theft",+ "template_index": 46,+ "adversary_intensity": "heavy",+ "title": "Ecallback infra instance im\u200bds endpoint abused on LIN-BUILD-CI03",+ "description": "instance-info endpointv1 abused on LIN-BUILD-CI03; temporary IAM login secrets for role exfilled to 172.16.50.7. CloudTrail shows AssumeRole from external.",+ "expected_tactics": [+ "TA0006",+ "TA0004"+ ],+ "expected_techniques": [+ "T1552.005",+ "T1078.004"+ ],+ "severity": "critical",+ "response_class": "rollback_change",+ "evidence_keywords": [+ "imds",+ "metadata",+ "iam credentials",+ "AssumeRole",+ "LIN-BUILD-CI03",+ "172.16.50.7"+ ],+ "original_title": "EC2 instance metadata service abused on LIN-BUILD-CI03",+ "original_description": "IMDSv1 abused on LIN-BUILD-CI03; temporary IAM credentials for role exfilled to 172.16.50.7. CloudTrail shows AssumeRole from external."+ },+ {+ "id": "INC-EVAL-103",+ "template_id": "helpdesk-password-reset-abuse",+ "template_index": 47,+ "adversary_intensity": "heavy",+ "title": "Vendor admin cred rotation request abuse for [email protected]",+ "description": "cred rotation request for [email protected] performed by helpdesk in response to human-factor pretexting call from 185.220.101.7. Token claimed within 90 seconds.",+ "expected_tactics": [+ "TA0001",+ "TA0006"+ ],+ "expected_techniques": [+ "T1566.004",+ "T1078"+ ],+ "severity": "high",+ "response_class": "disable_account",+ "evidence_keywords": [+ "password reset",+ "social engineering",+ "helpdesk",+ "[email protected]",+ "185.220.101.7"+ ],+ "original_title": "Vendor admin password reset abuse for [email protected]",+ "original_description": "Password reset for [email protected] performed by helpdesk in response to social-engineering call from 185.220.101.7. Token claimed within 90 seconds."+ },+ {+ "id": "INC-EVAL-104",+ "template_id": "oauth-refresh-token-theft",+ "template_index": 48,+ "adversary_intensity": "medium",+ "title": "OAuth refresh-token theft for [email protected]",+ "description": "Refresh token for [email protected] replayed from 91.134.231.15. Granted access to mailbox + OneDrive without re-prompt.",+ "expected_tactics": [+ "TA0006"+ ],+ "expected_techniques": [+ "T1550.001"+ ],+ "severity": "high",+ "response_class": "disable_account",+ "evidence_keywords": [+ "oauth",+ "refresh token",+ "replay",+ "onedrive",+ "mailbox",+ "[email protected]",+ "91.134.231.15"+ ],+ "original_title": "OAuth refresh-token theft for [email protected]",+ "original_description": "Refresh token for [email protected] replayed from 91.134.231.15. Granted access to mailbox + OneDrive without re-prompt."+ },+ {+ "id": "INC-EVAL-105",+ "template_id": "malicious-container-image",+ "template_index": 49,+ "adversary_intensity": "light",+ "title": "Container image with embedded backdoor pulled by WIN-FILE-SHARE",+ "description": "Image registry/repo:malicious-backdoor pulled by WIN-FILE-SHARE. Layer scan flagged embedded netcat reverse-shell binary.",+ "expected_tactics": [+ "TA0001",+ "TA0002"+ ],+ "expected_techniques": [+ "T1195.002",+ "T1610"+ ],+ "severity": "high",+ "response_class": "rollback_change",+ "evidence_keywords": [+ "container image",+ "registry",+ "backdoor",+ "netcat",+ "WIN-FILE-SHARE"+ ],+ "original_title": "Container image with embedded backdoor pulled by WIN-FILE-SHARE",+ "original_description": "Image registry/repo:malicious-backdoor pulled by WIN-FILE-SHARE. Layer scan flagged embedded netcat reverse-shell binary."+ },+ {+ "id": "INC-EVAL-106",+ "template_id": "outlook-auto-forward-rule",+ "template_index": 50,+ "adversary_intensity": "light",+ "title": "Outlook rule auto-forwarding mail from [email protected]",+ "description": "Outlook inbox rule created for [email protected] that forwards all mail to external address at 192.168.1.100. Linked to MosaicRegressor.",+ "expected_tactics": [+ "TA0006",+ "TA0009"+ ],+ "expected_techniques": [+ "T1564.008",+ "T1114.003"+ ],+ "severity": "high",+ "response_class": "disable_account",+ "evidence_keywords": [+ "outlook rule",+ "forward",+ "mail",+ "[email protected]",+ "192.168.1.100",+ "MosaicRegressor"+ ],+ "original_title": "Outlook rule auto-forwarding mail from [email protected]",+ "original_description": "Outlook inbox rule created for [email protected] that forwards all mail to external address at 192.168.1.100. Linked to MosaicRegressor."+ },+ {+ "id": "INC-EVAL-107",+ "template_id": "linux-journald-tampering",+ "template_index": 51,+ "adversary_intensity": "light",+ "title": "Linux journald log tampering on LIN-OBS-LOGGER",+ "description": "journalctl --rotate --vacuum-time=1s observed on LIN-OBS-LOGGER by [email protected]; recent journal entries purged. Indicator removal.",+ "expected_tactics": [+ "TA0005"+ ],+ "expected_techniques": [+ "T1070.002"+ ],+ "severity": "high",+ "response_class": "escalate",+ "evidence_keywords": [+ "journalctl",+ "log tampering",+ "vacuum",+ "LIN-OBS-LOGGER",+ ],+ "original_title": "Linux journald log tampering on LIN-OBS-LOGGER",+ "original_description": "journalctl --rotate --vacuum-time=1s observed on LIN-OBS-LOGGER by [email protected]; recent journal entries purged. Indicator removal."+ },+ {+ "id": "INC-EVAL-108",+ "template_id": "compromised-ci-runner",+ "template_index": 52,+ "adversary_intensity": "medium",+ "title": "Compromised CI runner on LIN-BUILD-CI03 pushing to production",+ "description": "Self-hosted CI runner LIN-BUILD-CI03 compromised. Job triggered from PR injected secret exfil step; secrets posted to 192.168.1.100.",+ "expected_tactics": [+ "TA0001",+ "TA0006",+ "TA0010"+ ],+ "expected_techniques": [+ "T1195.002",+ "T1552.004"+ ],+ "severity": "critical",+ "response_class": "rollback_change",+ "evidence_keywords": [+ "ci runner",+ "self-hosted",+ "secret",+ "exfil",+ "LIN-BUILD-CI03",+ "192.168.1.100"+ ],+ "original_title": "Compromised CI runner on LIN-BUILD-CI03 pushing to production",+ "original_description": "Self-hosted CI runner LIN-BUILD-CI03 compromised. Job triggered from PR injected secret exfil step; secrets posted to 192.168.1.100."+ },+ {+ "id": "INC-EVAL-109",+ "template_id": "vpn-new-geography",+ "template_index": 53,+ "adversary_intensity": "heavy",+ "title": "Suspicious corp tunnel sign-in from first-time origin for [email protected]",+ "description": "corp tunnel sign-in for [email protected] from 10.0.99.42 (new country, no prior history). Subsequent e-w hop fileshare probe from VPN range to LIN-K8S-n\u200bode.js01.",+ "expected_tactics": [+ "TA0001",+ "TA0008"+ ],+ "expected_techniques": [+ "T1078.004",+ "T1021.002"+ ],+ "severity": "high",+ "response_class": "disable_account",+ "evidence_keywords": [+ "vpn",+ "new geography",+ "lateral",+ "smb scan",+ "[email protected]",+ "10.0.99.42",+ "LIN-K8S-NODE01"+ ],+ "original_title": "Suspicious VPN login from new geography for [email protected]",+ "original_description": "VPN login for [email protected] from 10.0.99.42 (new country, no prior history). Subsequent lateral SMB scan from VPN range to LIN-K8S-NODE01."+ },+ {+ "id": "INC-EVAL-110",+ "template_id": "service-account-privileged-command",+ "template_index": 54,+ "adversary_intensity": "light",+ "title": "Privileged command run as service account on WIN-DEVOPS-LT",+ "description": "Service account [email protected] (no interactive use expected) ran privileged net.exe + wevtutil cl Security on WIN-DEVOPS-LT. Anomalous.",+ "expected_tactics": [+ "TA0005",+ "TA0006"+ ],+ "expected_techniques": [+ "T1078.001",+ "T1070.001"+ ],+ "severity": "high",+ "response_class": "disable_account",+ "evidence_keywords": [+ "service account",+ "wevtutil",+ "log clear",+ "[email protected]",+ "WIN-DEVOPS-LT"+ ],+ "original_title": "Privileged command run as service account on WIN-DEVOPS-LT",+ "original_description": "Service account [email protected] (no interactive use expected) ran privileged net.exe + wevtutil cl Security on WIN-DEVOPS-LT. Anomalous."+ },+ {+ "id": "INC-EVAL-111",+ "template_id": "phishing-macro-email",+ "template_index": 0,+ "adversary_intensity": "heavy",+ "title": "directed baiting email with embedded automation routine-laden attachment delivered to [email protected]",+ "description": "Inbound email from 192.168.1.100 delivered an Office document with a malicious off1ce-automation language embedded automation routine to [email protected]. Attachment opened on LIN-OBS-LOGGER; embedded automation routine spawned command interpreter binary and downloaded a follow-on artifact from a known Scattered Spider infrastructure.",+ "expected_tactics": [+ "TA0001",+ "TA0002"+ ],+ "expected_techniques": [+ "T1566.001",+ "T1059.005"+ ],+ "severity": "high",+ "response_class": "block_indicator",+ "evidence_keywords": [+ "phishing email",+ "macro",+ "192.168.1.100",+ "LIN-OBS-LOGGER",+ "[email protected]",+ "stage-2 payload"+ ],+ "original_title": "Spear-phishing email with macro-laden attachment delivered to [email protected]",+ "original_description": "Inbound email from 192.168.1.100 delivered an Office document with a malicious VBA macro to [email protected]. Attachment opened on LIN-OBS-LOGGER; macro spawned cmd.exe and downloaded a stage-2 payload from a known Scattered Spider infrastructure."+ },+ {+ "id": "INC-EVAL-112",+ "template_id": "webapp-sqli-ssrf-exploit",+ "template_index": 1,+ "adversary_intensity": "medium",+ "title": "Exploitation of public-facing web app on MAC-LEGAL-LAPTOP",+ "description": "WAF logs show SQL-injection and SSRF probes from 198.51.100.23 against the application on MAC-LEGAL-LAPTOP. One request returned 200 with internal cloud-metadata content. Likely exploitation of CVE-2024-1234.",+ "expected_tactics": [+ "TA0001",+ "TA0007"+ ],+ "expected_techniques": [+ "T1190",+ "T1082"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "WAF",+ "SQL injection",+ "SSRF",+ "CVE-2024-1234",+ "MAC-LEGAL-LAPTOP",+ "198.51.100.23"+ ],+ "original_title": "Exploitation of public-facing web app on MAC-LEGAL-LAPTOP",+ "original_description": "WAF logs show SQL-injection and SSRF probes from 198.51.100.23 against the application on MAC-LEGAL-LAPTOP. One request returned 200 with internal cloud-metadata content. Likely exploitation of CVE-2024-1234."+ },+ {+ "id": "INC-EVAL-113",+ "template_id": "confluence-watering-hole",+ "template_index": 2,+ "adversary_intensity": "heavy",+ "title": "Watering-hole exploit served from internal Confluence by 185.220.101.7",+ "description": "Internal Confluence page injected with malicious browser-side code by 185.220.101.7. auto-load infection exploit triggered DOM-engine abuse on multiple visitors including [email protected]. Linked to MagicWeb TTPs.",+ "expected_tactics": [+ "TA0001",+ "TA0002"+ ],+ "expected_techniques": [+ "T1189",+ "T1203"+ ],+ "severity": "high",+ "response_class": "block_indicator",+ "evidence_keywords": [+ "watering hole",+ "drive-by",+ "Confluence",+ "185.220.101.7",+ "[email protected]",+ "MagicWeb"+ ],+ "original_title": "Watering-hole exploit served from internal Confluence by 185.220.101.7",+ "original_description": "Internal Confluence page injected with malicious JavaScript by 185.220.101.7. Drive-by exploit triggered browser exploitation on multiple visitors including [email protected]. Linked to MagicWeb TTPs."+ },+ {+ "id": "INC-EVAL-114",+ "template_id": "npm-supply-chain",+ "template_index": 3,+ "adversary_intensity": "heavy",+ "title": "Supply-chain compromise: malicious n\u200bpm c0mpressage on WIN-DC-PRIMARY",+ "description": "CI pipeline on WIN-DC-PRIMARY installed doctored js-libs build c0mpressage `event-stream`. install-time hook hook executed reverse shell to 192.168.1.100. Build artefacts may be tainted.",+ "expected_tactics": [+ "TA0001",+ "TA0002"+ ],+ "expected_techniques": [+ "T1195.001",+ "T1059.007"+ ],+ "severity": "critical",+ "response_class": "rollback_change",+ "evidence_keywords": [+ "supply chain",+ "npm package",+ "event-stream",+ "post-install",+ "WIN-DC-PRIMARY",+ "192.168.1.100"+ ],+ "original_title": "Supply-chain compromise: malicious npm package on WIN-DC-PRIMARY",+ "original_description": "CI pipeline on WIN-DC-PRIMARY installed compromised npm package `event-stream`. Post-install hook executed reverse shell to 192.168.1.100. Build artefacts may be tainted."+ },+ {+ "id": "INC-EVAL-115",+ "template_id": "usb-autorun-airgap",+ "template_index": 4,+ "adversary_intensity": "medium",+ "title": "Malicious rem0vable media autorun on air-gapped host WIN-PROD-WEB02",+ "description": "rem0vable media device inserted on air-gapped WIN-PROD-WEB02 by [email protected]. AutoRun executed p\u200bython stager that collected local files. Data staged in C:\\Temp\\.",+ "expected_tactics": [+ "TA0001",+ "TA0009"+ ],+ "expected_techniques": [+ "T1091",+ "T1005"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "USB",+ "autorun",+ "air-gapped",+ "WIN-PROD-WEB02",+ "[email protected]",+ "Python stager"+ ],+ "original_title": "Malicious USB autorun on air-gapped host WIN-PROD-WEB02",+ "original_description": "USB device inserted on air-gapped WIN-PROD-WEB02 by [email protected]. AutoRun executed Python stager that collected local files. Data staged in C:\\Temp\\."+ },+ {+ "id": "INC-EVAL-116",+ "template_id": "oauth-consent-phish",+ "template_index": 5,+ "adversary_intensity": "medium",+ "title": "0auth consent phishing targeting [email protected]",+ "description": "Malicious 0auth application granted Mail.Read and Files.Read.All scopes by [email protected]. Inbox forwarding rule created sending mail to 91.134.231.15.",+ "expected_tactics": [+ "TA0001",+ "TA0006"+ ],+ "expected_techniques": [+ "T1528",+ "T1550.001"+ ],+ "severity": "high",+ "response_class": "disable_account",+ "evidence_keywords": [+ "OAuth consent",+ "Mail.Read",+ "Files.Read.All",+ "[email protected]",+ "91.134.231.15",+ "forwarding rule"+ ],+ "original_title": "OAuth consent phishing targeting [email protected]",+ "original_description": "Malicious OAuth application granted Mail.Read and Files.Read.All scopes by [email protected]. Inbox forwarding rule created sending mail to 91.134.231.15."+ },+ {+ "id": "INC-EVAL-117",+ "template_id": "powershell-obfuscated-dropper",+ "template_index": 6,+ "adversary_intensity": "heavy",+ "title": "deob h@rd'ned p\u200bow\u200bersh\u200bell dropper executed on WIN-HR-DESKTOP",+ "description": "p\u200bow\u200bersh\u200bell dropper executed on WIN-HR-DESKTOP by [email protected]; payload base64-byte-wrapd and decoded in-memory. Linked to MosaicRex-bound flowor lockout-for-payware staging.",+ "expected_tactics": [+ "TA0002",+ "TA0005"+ ],+ "expected_techniques": [+ "T1059.001",+ "T1027"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "powershell",+ "obfuscated",+ "base64",+ "WIN-HR-DESKTOP",+ "[email protected]",+ "MosaicRegressor"+ ],+ "original_title": "Obfuscated PowerShell dropper executed on WIN-HR-DESKTOP",+ "original_description": "PowerShell dropper executed on WIN-HR-DESKTOP by [email protected]; payload base64-encoded and decoded in-memory. Linked to MosaicRegressor ransomware staging."+ },+ {+ "id": "INC-EVAL-118",+ "template_id": "certutil-download-cradle",+ "template_index": 7,+ "adversary_intensity": "heavy",+ "title": "Living-off-the-land: cert-handling lolbin download cradle on WIN-PROD-WEB02",+ "description": "cert-handling lolbin.exe -urlcache invoked from shell-host.exe on WIN-PROD-WEB02. shell-host.exe was spawned by outlook.exe. Payload downloaded from 198.51.100.23.",+ "expected_tactics": [+ "TA0002",+ "TA0005"+ ],+ "expected_techniques": [+ "T1105",+ "T1218.009"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "certutil",+ "urlcache",+ "outlook.exe",+ "WIN-PROD-WEB02",+ "198.51.100.23",+ "download cradle"+ ],+ "original_title": "Living-off-the-land: certutil download cradle on WIN-PROD-WEB02",+ "original_description": "certutil.exe -urlcache invoked from cmd.exe on WIN-PROD-WEB02. cmd.exe was spawned by outlook.exe. Payload downloaded from 198.51.100.23."+ },+ {+ "id": "INC-EVAL-119",+ "template_id": "docker-runtime-abuse",+ "template_index": 8,+ "adversary_intensity": "heavy",+ "title": "Container runtime abuse: malicious `runc launch` on WIN-FILE-SHARE",+ "description": "Unauthenticated Docker API on WIN-FILE-SHARE exploited from 185.220.101.7. image carrying compute hijack for currencyr spawned. CPU on host saturated to 95%.",+ "expected_tactics": [+ "TA0002",+ "TA0001",+ "TA0040"+ ],+ "expected_techniques": [+ "T1610",+ "T1059.004",+ "T1496"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "docker",+ "container",+ "cryptominer",+ "miner",+ "WIN-FILE-SHARE",+ "185.220.101.7"+ ],+ "original_title": "Container runtime abuse: malicious `docker run` on WIN-FILE-SHARE",+ "original_description": "Unauthenticated Docker API on WIN-FILE-SHARE exploited from 185.220.101.7. Container with cryptominer spawned. CPU on host saturated to 95%."+ },+ {+ "id": "INC-EVAL-120",+ "template_id": "wmi-event-subscription",+ "template_index": 9,+ "adversary_intensity": "heavy",+ "title": "Malicious windows-mgmt-fabric subscr1ption on WIN-PROD-WEB02",+ "description": "perm wm\u200bi event subscr1ption created on WIN-PROD-WEB02 by [email protected]. Consumer runs byte-wrapd scr1pt. reboot survival + binary launch mechanism.",+ "expected_tactics": [+ "TA0002",+ "TA0003"+ ],+ "expected_techniques": [+ "T1546.003",+ "T1059.001"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "WMI",+ "subscription",+ "permanent",+ "WIN-PROD-WEB02",+ "[email protected]",+ "encoded script"+ ],+ "original_title": "Malicious WMI subscription on WIN-PROD-WEB02",+ "original_description": "Permanent WMI event subscription created on WIN-PROD-WEB02 by [email protected]. Consumer runs encoded script. Persistence + execution mechanism."+ },+ {+ "id": "INC-EVAL-121",+ "template_id": "registry-run-persistence",+ "template_index": 10,+ "adversary_intensity": "medium",+ "title": "Registry Run key persistence created by [email protected] on K8S-PROD-CLUSTER",+ "description": "New value written to HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run on K8S-PROD-CLUSTER. Points to roaming binary signed with revoked cert. Linked to ALPHV/BlackCat.",+ "expected_tactics": [+ "TA0003"+ ],+ "expected_techniques": [+ "T1547.001"+ ],+ "severity": "medium",+ "response_class": "rollback_change",+ "evidence_keywords": [+ "registry run",+ "persistence",+ "revoked cert",+ "K8S-PROD-CLUSTER",+ "[email protected]",+ "ALPHV/BlackCat"+ ],+ "original_title": "Registry Run key persistence created by [email protected] on K8S-PROD-CLUSTER",+ "original_description": "New value written to HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run on K8S-PROD-CLUSTER. Points to roaming binary signed with revoked cert. Linked to ALPHV/BlackCat."+ },+ {+ "id": "INC-EVAL-122",+ "template_id": "scheduled-task-persistence",+ "template_index": 11,+ "adversary_intensity": "heavy",+ "title": "schtasks job reboot survival on WIN-PROD-WEB02",+ "description": "Hidden schtasks job created on WIN-PROD-WEB02 by [email protected]: triggers every 30 minutes, runs automation snippet from %APPDATA%\\Roaming. reboot survival mechanism.",+ "expected_tactics": [+ "TA0003"+ ],+ "expected_techniques": [+ "T1053.005"+ ],+ "severity": "medium",+ "response_class": "rollback_change",+ "evidence_keywords": [+ "scheduled task",+ "persistence",+ "APPDATA",+ "WIN-PROD-WEB02",+ ],+ "original_title": "Scheduled task persistence on WIN-PROD-WEB02",+ "original_description": "Hidden scheduled task created on WIN-PROD-WEB02 by [email protected]: triggers every 30 minutes, runs script from %APPDATA%\\Roaming. Persistence mechanism."+ },+ {+ "id": "INC-EVAL-123",+ "template_id": "uefi-firmware-implant",+ "template_index": 12,+ "adversary_intensity": "medium",+ "title": "f1rmware long-residence agent detected on platform pre-boot f1rmware partition of WIN-PROD-WEB02",+ "description": "platform pre-boot f1rmware secure-boot violation on WIN-PROD-WEB02. Unknown module detected in f1rmware. Signature matches MosaicRex-bound flowor long-residence agent.",+ "expected_tactics": [+ "TA0003",+ "TA0005"+ ],+ "expected_techniques": [+ "T1542.001",+ "T1027.002"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "UEFI",+ "firmware",+ "implant",+ "secure boot",+ "WIN-PROD-WEB02",+ "MosaicRegressor"+ ],+ "original_title": "Firmware implant detected on UEFI partition of WIN-PROD-WEB02",+ "original_description": "UEFI secure-boot violation on WIN-PROD-WEB02. Unknown module detected in firmware. Signature matches MosaicRegressor implant."+ },+ {+ "id": "INC-EVAL-124",+ "template_id": "cron-backdoor",+ "template_index": 13,+ "adversary_intensity": "heavy",+ "title": "covert reverse access cr0n job installed on MAC-LEGAL-LAPTOP",+ "description": "/etc/cr0n.d entry created by [email protected] on MAC-LEGAL-LAPTOP. Reverse shell regular check-in to 91.134.231.15 every 5 minutes.",+ "expected_tactics": [+ "TA0003",+ "TA0011"+ ],+ "expected_techniques": [+ "T1053.003",+ "T1071.001"+ ],+ "severity": "high",+ "response_class": "rollback_change",+ "evidence_keywords": [+ "cron",+ "backdoor",+ "reverse shell",+ "MAC-LEGAL-LAPTOP",+ "[email protected]",+ "91.134.231.15"+ ],+ "original_title": "Backdoor cron job installed on MAC-LEGAL-LAPTOP",+ "original_description": "/etc/cron.d entry created by [email protected] on MAC-LEGAL-LAPTOP. Reverse shell beacon to 91.134.231.15 every 5 minutes."+ },+ {+ "id": "INC-EVAL-125",+ "template_id": "uac-bypass-fodhelper",+ "template_index": 14,+ "adversary_intensity": "medium",+ "title": "ua\u200bc circumvention observed on WIN-EXCHANGE-01",+ "description": "f0dhelper.exe abuse on WIN-EXCHANGE-01 by [email protected]; auto-rights uplift triggered without prompt. Process tree shows level-up to SYSTEM.",+ "expected_tactics": [+ "TA0004",+ "TA0005"+ ],+ "expected_techniques": [+ "T1548.002"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "UAC",+ "fodhelper",+ "auto-elevation",+ "WIN-EXCHANGE-01",+ "[email protected]",+ "SYSTEM"+ ],+ "original_title": "UAC bypass observed on WIN-EXCHANGE-01",+ "original_description": "fodhelper.exe abuse on WIN-EXCHANGE-01 by [email protected]; auto-elevation triggered without prompt. Process tree shows escalation to SYSTEM."+ },+ {+ "id": "INC-EVAL-126",+ "template_id": "k8s-privileged-pod-escape",+ "template_index": 15,+ "adversary_intensity": "medium",+ "title": "workload sandbox break via high-cap pod on GCP-GKE-n0de runtime-04",+ "description": "Kubernetes high-cap pod created on GCP-GKE-n0de runtime-04 by [email protected]. cgroup escape to host namespace observed. n0de runtime filesystem accessed.",+ "expected_tactics": [+ "TA0004",+ "TA0007"+ ],+ "expected_techniques": [+ "T1611",+ "T1082"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "kubernetes",+ "privileged pod",+ "container escape",+ "cgroup",+ "GCP-GKE-NODE-04",+ ],+ "original_title": "Container escape via privileged pod on GCP-GKE-NODE-04",+ "original_description": "Kubernetes privileged pod created on GCP-GKE-NODE-04 by [email protected]. cgroup escape to host namespace observed. Node filesystem accessed."+ },+ {+ "id": "INC-EVAL-127",+ "template_id": "linux-suid-abuse",+ "template_index": 16,+ "adversary_intensity": "medium",+ "title": "Linux SUID binary abuse on WIN-DEVOPS-LT",+ "description": "Custom SUID binary discovered in /tmp on WIN-DEVOPS-LT; allows arbitrary command binary launch as root. Likely escalation by [email protected].",+ "expected_tactics": [+ "TA0004"+ ],+ "expected_techniques": [+ "T1548.001"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "SUID",+ "/tmp",+ "root escalation",+ "WIN-DEVOPS-LT",+ ],+ "original_title": "Linux SUID binary abuse on WIN-DEVOPS-LT",+ "original_description": "Custom SUID binary discovered in /tmp on WIN-DEVOPS-LT; allows arbitrary command execution as root. Likely escalation by [email protected]."+ },+ {+ "id": "INC-EVAL-128",+ "template_id": "process-hollowing-svchost",+ "template_index": 17,+ "adversary_intensity": "heavy",+ "title": "no on-disk artifact no-disk-write resident dropper in svchost on GCP-GKE-n0de runtime-04",+ "description": "in-place process swaping detected on GCP-GKE-n0de runtime-04: svchost.exe replaced with c0balt strike regular check-in to 91.134.231.15. No disk artefacts. Linked to ALPHV/BlackCat.",+ "expected_tactics": [+ "TA0002",+ "TA0005"+ ],+ "expected_techniques": [+ "T1055.012",+ "T1620"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "process hollowing",+ "fileless",+ "svchost",+ "Cobalt Strike",+ "GCP-GKE-NODE-04",+ "91.134.231.15"+ ],+ "original_title": "Memory-only fileless implant in svchost on GCP-GKE-NODE-04",+ "original_description": "Process hollowing detected on GCP-GKE-NODE-04: svchost.exe replaced with Cobalt Strike beacon to 91.134.231.15. No disk artefacts. Linked to ALPHV/BlackCat."+ },+ {+ "id": "INC-EVAL-129",+ "template_id": "event-log-cleared",+ "template_index": 18,+ "adversary_intensity": "medium",+ "title": "Indicator removal: Windows event log cleared on MAC-CFO-LAPTOP",+ "description": "Security event log cleared on MAC-CFO-LAPTOP by [email protected]. wevtutil.exe cl Security observed in command-line telemetry.",+ "expected_tactics": [+ "TA0005"+ ],+ "expected_techniques": [+ "T1070.001"+ ],+ "severity": "high",+ "response_class": "escalate",+ "evidence_keywords": [+ "wevtutil",+ "log cleared",+ "indicator removal",+ "MAC-CFO-LAPTOP",+ ],+ "original_title": "Indicator removal: Windows event log cleared on MAC-CFO-LAPTOP",+ "original_description": "Security event log cleared on MAC-CFO-LAPTOP by [email protected]. wevtutil.exe cl Security observed in command-line telemetry."+ },+ {+ "id": "INC-EVAL-130",+ "template_id": "disable-edr-tooling",+ "template_index": 19,+ "adversary_intensity": "heavy",+ "title": "Disable security tooling on GCP-GKE-n0de runtime-04",+ "description": "[email protected] attempted to halt windows av, CrowdStrike, and Sysmon on GCP-GKE-n0de runtime-04. d0ctoring telemetry triggered alert.",+ "expected_tactics": [+ "TA0005"+ ],+ "expected_techniques": [+ "T1562.001"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "defender",+ "crowdstrike",+ "sysmon",+ "tampering",+ "GCP-GKE-NODE-04",+ ],+ "original_title": "Disable security tooling on GCP-GKE-NODE-04",+ "original_description": "[email protected] attempted to stop Defender, CrowdStrike, and Sysmon on GCP-GKE-NODE-04. Tampering telemetry triggered alert."+ },+ {+ "id": "INC-EVAL-131",+ "template_id": "lsass-memory-dump",+ "template_index": 20,+ "adversary_intensity": "heavy",+ "title": "auth subsystem proc memory proc-mem snapshot on GCP-GKE-n0de runtime-04 by [email protected]",+ "description": "comsvcs.loadable code module proc-snapshot observed on GCP-GKE-n0de runtime-04. auth subsystem proc.exe memory proc-mem snapshoted to C:\\Windows\\Temp\\. auth-secrets puller signatures detected.",+ "expected_tactics": [+ "TA0006"+ ],+ "expected_techniques": [+ "T1003.001"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "lsass",+ "minidump",+ "comsvcs",+ "mimikatz",+ "GCP-GKE-NODE-04",+ ],+ "original_title": "LSASS memory dump on GCP-GKE-NODE-04 by [email protected]",+ "original_description": "comsvcs.dll MiniDump observed on GCP-GKE-NODE-04. lsass.exe memory dumped to C:\\Windows\\Temp\\. Mimikatz signatures detected."+ },+ {+ "id": "INC-EVAL-132",+ "template_id": "credential-spray",+ "template_index": 21,+ "adversary_intensity": "heavy",+ "title": "repeated-guess spread-out cred probe against [email protected] from 91.134.231.15",+ "description": "spread-out cred probe from 91.134.231.15 against [email protected]. 1500 password attempts in 30 minutes. One success followed by anomalous Azure AD sign-in.",+ "expected_tactics": [+ "TA0006"+ ],+ "expected_techniques": [+ "T1110.003"+ ],+ "severity": "high",+ "response_class": "disable_account",+ "evidence_keywords": [+ "brute force",+ "credential spray",+ "[email protected]",+ "91.134.231.15",+ "azure ad"+ ],+ "original_title": "Brute-force credential spray against [email protected] from 91.134.231.15",+ "original_description": "Credential spray from 91.134.231.15 against [email protected]. 1500 password attempts in 30 minutes. One success followed by anomalous Azure AD sign-in."+ },+ {+ "id": "INC-EVAL-133",+ "template_id": "kerberoasting",+ "template_index": 22,+ "adversary_intensity": "medium",+ "title": "Kerberoasting from WIN-EXCHANGE-01",+ "description": "d@emon entry account TGS tickets requested en-masse from WIN-EXCHANGE-01 by [email protected]. AES256 \u2192 RC4 downgrade observed. Mimikatz tooling indicators.",+ "expected_tactics": [+ "TA0006",+ "TA0008"+ ],+ "expected_techniques": [+ "T1558.003",+ "T1021.001"+ ],+ "severity": "critical",+ "response_class": "disable_account",+ "evidence_keywords": [+ "kerberoast",+ "TGS",+ "RC4",+ "mimikatz",+ "WIN-EXCHANGE-01",+ ],+ "original_title": "Kerberoasting from WIN-EXCHANGE-01",+ "original_description": "Service account TGS tickets requested en-masse from WIN-EXCHANGE-01 by [email protected]. AES256 \u2192 RC4 downgrade observed. Mimikatz tooling indicators."+ },+ {+ "id": "INC-EVAL-134",+ "template_id": "ad-dcsync",+ "template_index": 23,+ "adversary_intensity": "heavy",+ "title": "Active Directory msrpc replica-pull abuse from non-DC host WIN-FIN-DB01",+ "description": "ad-sync abuse rights abused from WIN-FIN-DB01 by [email protected]. All domain n\u200btlm hashes replicated. Severe cred exposure.",+ "expected_tactics": [+ "TA0006",+ "TA0004"+ ],+ "expected_techniques": [+ "T1003.006",+ "T1078.002"+ ],+ "severity": "critical",+ "response_class": "disable_account",+ "evidence_keywords": [+ "dcsync",+ "replication",+ "ntlm hash",+ "WIN-FIN-DB01",+ ],+ "original_title": "Active Directory DCSync from non-DC host WIN-FIN-DB01",+ "original_description": "Replication rights abused from WIN-FIN-DB01 by [email protected]. All domain NTLM hashes replicated. Severe credential exposure."+ },+ {+ "id": "INC-EVAL-135",+ "template_id": "saml-golden-ticket",+ "template_index": 24,+ "adversary_intensity": "heavy",+ "title": "fed-assertion golden-ticket: forged assertion targeting [email protected]",+ "description": "Forged fed-assertion assertion detected for [email protected]. Attacker pivoted to Azure AD; account listing-oution followed from 45.142.122.111.",+ "expected_tactics": [+ "TA0006",+ "TA0007"+ ],+ "expected_techniques": [+ "T1606.002",+ "T1087.002"+ ],+ "severity": "critical",+ "response_class": "disable_account",+ "evidence_keywords": [+ "saml",+ "golden ticket",+ "forged",+ "azure ad",+ "[email protected]",+ "45.142.122.111"+ ],+ "original_title": "SAML golden-ticket: forged assertion targeting [email protected]",+ "original_description": "Forged SAML assertion detected for [email protected]. Attacker pivoted to Azure AD; account enumeration followed from 45.142.122.111."+ },+ {+ "id": "INC-EVAL-136",+ "template_id": "ldap-bloodhound-discovery",+ "template_index": 25,+ "adversary_intensity": "light",+ "title": "Domain enumeration from GCP-GKE-NODE-04",+ "description": "ldap discovery from GCP-GKE-NODE-04 by [email protected]: BloodHound-style queries enumerating users, groups, ACLs.",+ "expected_tactics": [+ "TA0007"+ ],+ "expected_techniques": [+ "T1087.002"+ ],+ "severity": "medium",+ "response_class": "monitor",+ "evidence_keywords": [+ "ldap",+ "bloodhound",+ "domain enumeration",+ "GCP-GKE-NODE-04",+ ],+ "original_title": "Domain enumeration from GCP-GKE-NODE-04",+ "original_description": "ldap discovery from GCP-GKE-NODE-04 by [email protected]: BloodHound-style queries enumerating users, groups, ACLs."+ },+ {+ "id": "INC-EVAL-137",+ "template_id": "smb-share-enumeration",+ "template_index": 26,+ "adversary_intensity": "light",+ "title": "Network share enumeration on LIN-EDGE-VPN02",+ "description": "Mass SMB share enumeration from LIN-EDGE-VPN02 by [email protected]; net.exe and powershell Get-SmbShare invocations across /24 subnet.",+ "expected_tactics": [+ "TA0007"+ ],+ "expected_techniques": [+ "T1135"+ ],+ "severity": "medium",+ "response_class": "monitor",+ "evidence_keywords": [+ "smb",+ "net.exe",+ "Get-SmbShare",+ "share enumeration",+ "LIN-EDGE-VPN02",+ ],+ "original_title": "Network share enumeration on LIN-EDGE-VPN02",+ "original_description": "Mass SMB share enumeration from LIN-EDGE-VPN02 by [email protected]; net.exe and PowerShell Get-SmbShare invocations across /24 subnet."+ },+ {+ "id": "INC-EVAL-138",+ "template_id": "pass-the-hash-lateral",+ "template_index": 27,+ "adversary_intensity": "heavy",+ "title": "auth-hash replay from LIN-DB-REPLICA to MAC-LEGAL-LAPTOP",+ "description": "auth-hash replay side-to-side traversal from LIN-DB-REPLICA to MAC-LEGAL-LAPTOP by [email protected]. Golden ticket indicators present. Linked to MagicWeb.",+ "expected_tactics": [+ "TA0008",+ "TA0006"+ ],+ "expected_techniques": [+ "T1550.002",+ "T1558.001"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "pass-the-hash",+ "golden ticket",+ "LIN-DB-REPLICA",+ "MAC-LEGAL-LAPTOP",+ "[email protected]",+ "MagicWeb"+ ],+ "original_title": "Pass-the-hash from LIN-DB-REPLICA to MAC-LEGAL-LAPTOP",+ "original_description": "Pass-the-hash lateral movement from LIN-DB-REPLICA to MAC-LEGAL-LAPTOP by [email protected]. Golden ticket indicators present. Linked to MagicWeb."+ },+ {+ "id": "INC-EVAL-139",+ "template_id": "rdp-lateral-movement",+ "template_index": 28,+ "adversary_intensity": "medium",+ "title": "RDP lateral movement from WIN-EXCHANGE-01",+ "description": "Anomalous RDP session from WIN-EXCHANGE-01 ([email protected]) to AWS-Ecallback infra-PROD-API outside business hours. Source admin not normal for AWS-Ecallback infra-PROD-API.",+ "expected_tactics": [+ "TA0008"+ ],+ "expected_techniques": [+ "T1021.001"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "rdp",+ "lateral movement",+ "outside hours",+ "WIN-EXCHANGE-01",+ "AWS-EC2-PROD-API",+ ],+ "original_title": "RDP lateral movement from WIN-EXCHANGE-01",+ "original_description": "Anomalous RDP session from WIN-EXCHANGE-01 ([email protected]) to AWS-EC2-PROD-API outside business hours. Source admin not normal for AWS-EC2-PROD-API."+ },+ {+ "id": "INC-EVAL-140",+ "template_id": "wmi-lateral-execution",+ "template_index": 29,+ "adversary_intensity": "heavy",+ "title": "windows-mgmt-fabric e-w hop code activation from MAC-CFO-LAPTOP to MAC-LEGAL-LAPTOP",+ "description": "wm\u200bic.exe /j$-runtime daemon:MAC-LEGAL-LAPTOP process call create observed from MAC-CFO-LAPTOP by [email protected]. Remote command code activation; payload from 91.134.231.15.",+ "expected_tactics": [+ "TA0008",+ "TA0002"+ ],+ "expected_techniques": [+ "T1047"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "wmic",+ "lateral",+ "MAC-CFO-LAPTOP",+ "MAC-LEGAL-LAPTOP",+ "[email protected]",+ "91.134.231.15"+ ],+ "original_title": "WMI lateral execution from MAC-CFO-LAPTOP to MAC-LEGAL-LAPTOP",+ "original_description": "wmic.exe /node:MAC-LEGAL-LAPTOP process call create observed from MAC-CFO-LAPTOP by [email protected]. Remote command execution; payload from 91.134.231.15."+ },+ {+ "id": "INC-EVAL-141",+ "template_id": "bulk-pii-download",+ "template_index": 30,+ "adversary_intensity": "light",+ "title": "Bulk PII download by [email protected]",+ "description": "[email protected] downloaded >10 GB of customer records from production database from WIN-DC-PRIMARY. Outside normal access pattern.",+ "expected_tactics": [+ "TA0009",+ "TA0010"+ ],+ "expected_techniques": [+ "T1005",+ "T1041"+ ],+ "severity": "critical",+ "response_class": "disable_account",+ "evidence_keywords": [+ "bulk download",+ "pii",+ "customer record",+ "WIN-DC-PRIMARY",+ ],+ "original_title": "Bulk PII download by [email protected]",+ "original_description": "[email protected] downloaded >10 GB of customer records from production database from WIN-DC-PRIMARY. Outside normal access pattern."+ },+ {+ "id": "INC-EVAL-142",+ "template_id": "clipboard-keylogger",+ "template_index": 31,+ "adversary_intensity": "heavy",+ "title": "clip-store logging imp1ant on WIN-PROD-WEB02",+ "description": "clip-store contents from WIN-PROD-WEB02 ([email protected]) being captured to %APPDATA%\\Local\\. Captures span 2 hours and include creds and crypto addresses.",+ "expected_tactics": [+ "TA0009"+ ],+ "expected_techniques": [+ "T1115"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "clipboard",+ "keylog",+ "credentials",+ "WIN-PROD-WEB02",+ ],+ "original_title": "Clipboard logging implant on WIN-PROD-WEB02",+ "original_description": "Clipboard contents from WIN-PROD-WEB02 ([email protected]) being captured to %APPDATA%\\Local\\. Captures span 2 hours and include credentials and crypto addresses."+ },+ {+ "id": "INC-EVAL-143",+ "template_id": "dns-tunnel-exfil",+ "template_index": 32,+ "adversary_intensity": "heavy",+ "title": "udp/53 covert trackling ex-bound transferion from WIN-DC-PRIMARY",+ "description": "name lookup volume from WIN-DC-PRIMARY 50\u00d7 baseline. TXT records contain base64-base64-wrapd payloads. Estimated exfil ~200 MB; destination 198.51.100.23.",+ "expected_tactics": [+ "TA0011",+ "TA0010"+ ],+ "expected_techniques": [+ "T1071.004",+ "T1048.003"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "dns tunnel",+ "txt records",+ "base64",+ "exfiltrat",+ "WIN-DC-PRIMARY",+ "198.51.100.23"+ ],+ "original_title": "DNS tunnelling exfiltration from WIN-DC-PRIMARY",+ "original_description": "DNS query volume from WIN-DC-PRIMARY 50\u00d7 baseline. TXT records contain base64-encoded payloads. Estimated exfil ~200 MB; destination 198.51.100.23."+ },+ {+ "id": "INC-EVAL-144",+ "template_id": "s3-exfil-cloud-storage",+ "template_index": 33,+ "adversary_intensity": "heavy",+ "title": "external bucket exfil: outbound data flow to attacker-controlled S3 from WIN-PROD-WEB02",+ "description": "outbound flow from WIN-PROD-WEB02 to aws://obj/atk-stage-185.220.101.7/proc-mem snapshot/ by [email protected]. 8 GB transferred over 20 minutes. CloudTrail PutObject events match.",+ "expected_tactics": [+ "TA0010"+ ],+ "expected_techniques": [+ "T1567.002"+ ],+ "severity": "critical",+ "response_class": "block_indicator",+ "evidence_keywords": [+ "s3",+ "cloud storage",+ "egress",+ "exfiltrat",+ "WIN-PROD-WEB02",+ "185.220.101.7",+ ],+ "original_title": "Cloud storage exfil: data egress to attacker-controlled S3 from WIN-PROD-WEB02",+ "original_description": "Egress from WIN-PROD-WEB02 to s3://atk-stage-185.220.101.7/dump/ by [email protected]. 8 GB transferred over 20 minutes. CloudTrail PutObject events match."+ },+ {+ "id": "INC-EVAL-145",+ "template_id": "personal-drive-exfil",+ "template_index": 34,+ "adversary_intensity": "heavy",+ "title": "non-corp drive exfil by [email protected]",+ "description": "[email protected] on AWS-Eops channel-PROD-API push-outed 4 GB to personal consumer-cloud drive. Files include source code and customer personal data.",+ "expected_tactics": [+ "TA0009",+ "TA0010"+ ],+ "expected_techniques": [+ "T1567.002",+ "T1005"+ ],+ "severity": "critical",+ "response_class": "disable_account",+ "evidence_keywords": [+ "google drive",+ "personal",+ "exfiltrat",+ "source code",+ "pii",+ "AWS-EC2-PROD-API",+ ],+ "original_title": "Personal Drive exfil by [email protected]",+ "original_description": "[email protected] on AWS-EC2-PROD-API uploaded 4 GB to personal Google Drive. Files include source code and customer PII."+ },+ {+ "id": "INC-EVAL-146",+ "template_id": "dga-c2",+ "template_index": 35,+ "adversary_intensity": "medium",+ "title": "DGA-based C2 traffic from GCP-GKE-n\u200bode.js-04",+ "description": "DGA traffic from GCP-GKE-n\u200bode.js-04 observed; 200+ NXDomain replies/min, IoCs match Scattered Spider epoch 5. Beacons to 45.142.122.111.",+ "expected_tactics": [+ "TA0011"+ ],+ "expected_techniques": [+ "T1568.002"+ ],+ "severity": "high",+ "response_class": "block_indicator",+ "evidence_keywords": [+ "dga",+ "domain generation",+ "nxdomain",+ "beacon",+ "GCP-GKE-NODE-04",+ "45.142.122.111",+ "Scattered Spider"+ ],+ "original_title": "DGA-based C2 traffic from GCP-GKE-NODE-04",+ "original_description": "DGA traffic from GCP-GKE-NODE-04 observed; 200+ NXDomain replies/min, IoCs match Scattered Spider epoch 5. Beacons to 45.142.122.111."+ },+ {+ "id": "INC-EVAL-147",+ "template_id": "https-c2-beacon",+ "template_index": 36,+ "adversary_intensity": "medium",+ "title": "HTTPS C2 beacon from WIN-DEVOPS-LT to 198.51.100.23",+ "description": "Periodic HTTPS beacon from WIN-DEVOPS-LT to 198.51.100.23 every 60 seconds with low jitter. JA3 fingerprint matches Cobalt Strike.",+ "expected_tactics": [+ "TA0011"+ ],+ "expected_techniques": [+ "T1071.001"+ ],+ "severity": "critical",+ "response_class": "block_indicator",+ "evidence_keywords": [+ "c2",+ "beacon",+ "ja3",+ "Cobalt Strike",+ "WIN-DEVOPS-LT",+ "198.51.100.23"+ ],+ "original_title": "HTTPS C2 beacon from WIN-DEVOPS-LT to 198.51.100.23",+ "original_description": "Periodic HTTPS beacon from WIN-DEVOPS-LT to 198.51.100.23 every 60 seconds with low jitter. JA3 fingerprint matches Cobalt Strike."+ },+ {+ "id": "INC-EVAL-148",+ "template_id": "ransomware-encryption",+ "template_index": 37,+ "adversary_intensity": "medium",+ "title": "Ransomware encryption in progress on LIN-DB-REPLICA",+ "description": "Mass file rename observed on LIN-DB-REPLICA ([email protected]); ..enc extension applied to ~20 k files. Ransomware note R3ADM3-Emotet epoch 5.txt found.",+ "expected_tactics": [+ "TA0040"+ ],+ "expected_techniques": [+ "T1486"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "ransomware",+ "encrypt",+ "rename",+ "ransom note",+ "LIN-DB-REPLICA",+ "[email protected]",+ "Emotet epoch 5"+ ],+ "original_title": "Ransomware encryption in progress on LIN-DB-REPLICA",+ "original_description": "Mass file rename observed on LIN-DB-REPLICA ([email protected]); ..enc extension applied to ~20 k files. Ransomware note R3ADM3-Emotet epoch 5.txt found."+ },+ {+ "id": "INC-EVAL-149",+ "template_id": "xmrig-cryptominer",+ "template_index": 38,+ "adversary_intensity": "heavy",+ "title": "c0in-miningr binary launch on MAC-LEGAL-LAPTOP",+ "description": "xm\u200brig compute-hijacking process spawned on MAC-LEGAL-LAPTOP; CPU saturated to 95%. Mining pool 10.0.99.42:5555. Linked to APT28.",+ "expected_tactics": [+ "TA0002",+ "TA0040"+ ],+ "expected_techniques": [+ "T1496"+ ],+ "severity": "medium",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "xmrig",+ "miner",+ "cryptomine",+ "MAC-LEGAL-LAPTOP",+ "10.0.99.42",+ "APT28"+ ],+ "original_title": "Cryptominer execution on MAC-LEGAL-LAPTOP",+ "original_description": "XMRig miner spawned on MAC-LEGAL-LAPTOP; CPU saturated to 95%. Mining pool 10.0.99.42:5555. Linked to APT28."+ },+ {+ "id": "INC-EVAL-150",+ "template_id": "bec-wire-fraud",+ "template_index": 39,+ "adversary_intensity": "medium",+ "title": "exec-impersonation fraud: payment redirect by [email protected]",+ "description": "Spear-phishing email spoofed CFO. Wire transfer of two-fifty-K k initiated by [email protected] from WIN-FILE-SHARE to threat-actor account. Linked to APT29.",+ "expected_tactics": [+ "TA0001",+ "TA0040"+ ],+ "expected_techniques": [+ "T1566.001",+ "T1657"+ ],+ "severity": "critical",+ "response_class": "escalate",+ "evidence_keywords": [+ "phishing",+ "spoofed cfo",+ "wire transfer",+ "$250",+ "[email protected]",+ "WIN-FILE-SHARE",+ "APT29"+ ],+ "original_title": "BEC: payment redirect by [email protected]",+ "original_description": "Spear-phishing email spoofed CFO. Wire transfer of $250 k initiated by [email protected] from WIN-FILE-SHARE to threat-actor account. Linked to APT29."+ },+ {+ "id": "INC-EVAL-151",+ "template_id": "public-s3-bucket-pii",+ "template_index": 40,+ "adversary_intensity": "heavy",+ "title": "Public blob-store bucket exposing user identity data",+ "description": "blob-store bucket world-readable; ~40k employee records accessible. CloudTrail shows external listing-oution from 91.134.231.15.",+ "expected_tactics": [+ "TA0009",+ "TA0010"+ ],+ "expected_techniques": [+ "T1530",+ "T1567.002"+ ],+ "severity": "critical",+ "response_class": "rollback_change",+ "evidence_keywords": [+ "s3",+ "public bucket",+ "pii",+ "cloudtrail",+ "91.134.231.15"+ ],+ "original_title": "Public S3 bucket exposing PII",+ "original_description": "S3 bucket world-readable; ~40k employee records accessible. CloudTrail shows external enumeration from 91.134.231.15."+ },+ {+ "id": "INC-EVAL-152",+ "template_id": "azure-ad-impossible-travel",+ "template_index": 41,+ "adversary_intensity": "heavy",+ "title": "Identity provider compromise \u2014 anomalous Azure AD sign-in for [email protected]",+ "description": "Successful Azure AD sign-in for [email protected] from 91.134.231.15 (impossible-travel from prior location). MFA satisfied via co-opted active sess token.",+ "expected_tactics": [+ "TA0001",+ "TA0006"+ ],+ "expected_techniques": [+ "T1078.004",+ "T1550.001"+ ],+ "severity": "critical",+ "response_class": "disable_account",+ "evidence_keywords": [+ "azure ad",+ "impossible travel",+ "session token",+ "mfa",+ "[email protected]",+ "91.134.231.15"+ ],+ "original_title": "Identity provider compromise \u2014 anomalous Azure AD sign-in for [email protected]",+ "original_description": "Successful Azure AD sign-in for [email protected] from 91.134.231.15 (impossible-travel from prior location). MFA satisfied via stolen session token."+ },+ {+ "id": "INC-EVAL-153",+ "template_id": "ddos-syn-flood",+ "template_index": 42,+ "adversary_intensity": "medium",+ "title": "DDoS volumetric flood targeting public-facing MAC-CFO-LAPTOP",+ "description": "L4 SYN flood from a botnet (>1M PPS) targeting MAC-CFO-LAPTOP. Edge mitigation engaged but long-running unit degraded for 12 minutes.",+ "expected_tactics": [+ "TA0040"+ ],+ "expected_techniques": [+ "T1498.001"+ ],+ "severity": "high",+ "response_class": "block_indicator",+ "evidence_keywords": [+ "ddos",+ "syn flood",+ "botnet",+ "MAC-CFO-LAPTOP",+ "1M PPS"+ ],+ "original_title": "DDoS volumetric flood targeting public-facing MAC-CFO-LAPTOP",+ "original_description": "L4 SYN flood from a botnet (>1M PPS) targeting MAC-CFO-LAPTOP. Edge mitigation engaged but service degraded for 12 minutes."+ },+ {+ "id": "INC-EVAL-154",+ "template_id": "insider-mailbox-export",+ "template_index": 43,+ "adversary_intensity": "light",+ "title": "Insider preparing departure: large mailbox export by [email protected]",+ "description": "[email protected] exported full mailbox PST (8 GB) from WIN-EXCHANGE-01. HR flag: notice given last week.",+ "expected_tactics": [+ "TA0009",+ "TA0010"+ ],+ "expected_techniques": [+ "T1114.002",+ "T1567.002"+ ],+ "severity": "high",+ "response_class": "disable_account",+ "evidence_keywords": [+ "mailbox export",+ "PST",+ "insider",+ "departure",+ "[email protected]",+ "WIN-EXCHANGE-01"+ ],+ "original_title": "Insider preparing departure: large mailbox export by [email protected]",+ "original_description": "[email protected] exported full mailbox PST (8 GB) from WIN-EXCHANGE-01. HR flag: notice given last week."+ },+ {+ "id": "INC-EVAL-155",+ "template_id": "office-vsto-addin",+ "template_index": 44,+ "adversary_intensity": "medium",+ "title": "Malicious Office add-in installed for [email protected]",+ "description": "Office VSTO add-in registered under HKCU for [email protected] on WIN-DC-SECONDARY; loads on every Outlook startup; regular check-ins to 45.142.122.111.",+ "expected_tactics": [+ "TA0003",+ "TA0011"+ ],+ "expected_techniques": [+ "T1137.006",+ "T1071.001"+ ],+ "severity": "high",+ "response_class": "rollback_change",+ "evidence_keywords": [+ "office add-in",+ "vsto",+ "outlook",+ "[email protected]",+ "WIN-DC-SECONDARY",+ "45.142.122.111"+ ],+ "original_title": "Malicious Office add-in installed for [email protected]",+ "original_description": "Office VSTO add-in registered under HKCU for [email protected] on WIN-DC-SECONDARY; loads on every Outlook startup; beacons to 45.142.122.111."+ },+ {+ "id": "INC-EVAL-156",+ "template_id": "github-pat-leak",+ "template_index": 45,+ "adversary_intensity": "heavy",+ "title": "GitHub p@t leaked and abused from 45.142.122.111",+ "description": "user-issued api token belonging to [email protected] used from 45.142.122.111 to clone 14 non-public repos. Token committed in public dotfiles repo 6 hours earlier.",+ "expected_tactics": [+ "TA0006",+ "TA0009"+ ],+ "expected_techniques": [+ "T1552.001",+ "T1213.003"+ ],+ "severity": "critical",+ "response_class": "disable_account",+ "evidence_keywords": [+ "github",+ "pat",+ "token",+ "private repo",+ "[email protected]",+ "45.142.122.111"+ ],+ "original_title": "GitHub PAT leaked and abused from 45.142.122.111",+ "original_description": "Personal access token belonging to [email protected] used from 45.142.122.111 to clone 14 private repos. Token committed in public dotfiles repo 6 hours earlier."+ },+ {+ "id": "INC-EVAL-157",+ "template_id": "ec2-imds-credential-theft",+ "template_index": 46,+ "adversary_intensity": "heavy",+ "title": "Ecallback infra instance im\u200bds endpoint abused on WIN-PROD-WEB02",+ "description": "im\u200bdsv1 abused on WIN-PROD-WEB02; temporary IAM auth-tokens for role exfilled to 91.134.231.15. CloudTrail shows AssumeRole from external.",+ "expected_tactics": [+ "TA0006",+ "TA0004"+ ],+ "expected_techniques": [+ "T1552.005",+ "T1078.004"+ ],+ "severity": "critical",+ "response_class": "rollback_change",+ "evidence_keywords": [+ "imds",+ "metadata",+ "iam credentials",+ "AssumeRole",+ "WIN-PROD-WEB02",+ "91.134.231.15"+ ],+ "original_title": "EC2 instance metadata service abused on WIN-PROD-WEB02",+ "original_description": "IMDSv1 abused on WIN-PROD-WEB02; temporary IAM credentials for role exfilled to 91.134.231.15. CloudTrail shows AssumeRole from external."+ },+ {+ "id": "INC-EVAL-158",+ "template_id": "helpdesk-password-reset-abuse",+ "template_index": 47,+ "adversary_intensity": "heavy",+ "title": "Vendor admin self-serve cred change abuse for [email protected]",+ "description": "self-serve cred change for [email protected] performed by helpdesk in response to human-factor pretexting call from 91.134.231.15. Token claimed within 90 seconds.",+ "expected_tactics": [+ "TA0001",+ "TA0006"+ ],+ "expected_techniques": [+ "T1566.004",+ "T1078"+ ],+ "severity": "high",+ "response_class": "disable_account",+ "evidence_keywords": [+ "password reset",+ "social engineering",+ "helpdesk",+ "[email protected]",+ "91.134.231.15"+ ],+ "original_title": "Vendor admin password reset abuse for [email protected]",+ "original_description": "Password reset for [email protected] performed by helpdesk in response to social-engineering call from 91.134.231.15. Token claimed within 90 seconds."+ },+ {+ "id": "INC-EVAL-159",+ "template_id": "oauth-refresh-token-theft",+ "template_index": 48,+ "adversary_intensity": "medium",+ "title": "OAuth refresh-token theft for [email protected]",+ "description": "Refresh token for [email protected] replayed from 10.0.99.42. Granted access to mailbox + OneDrive without re-prompt.",+ "expected_tactics": [+ "TA0006"+ ],+ "expected_techniques": [+ "T1550.001"+ ],+ "severity": "high",+ "response_class": "disable_account",+ "evidence_keywords": [+ "oauth",+ "refresh token",+ "replay",+ "onedrive",+ "mailbox",+ "[email protected]",+ "10.0.99.42"+ ],+ "original_title": "OAuth refresh-token theft for [email protected]",+ "original_description": "Refresh token for [email protected] replayed from 10.0.99.42. Granted access to mailbox + OneDrive without re-prompt."+ },+ {+ "id": "INC-EVAL-160",+ "template_id": "malicious-container-image",+ "template_index": 49,+ "adversary_intensity": "light",+ "title": "Container image with embedded backdoor pulled by AZURE-VM-FIN-001",+ "description": "Image registry/repo:malicious-backdoor pulled by AZURE-VM-FIN-001. Layer scan flagged embedded netcat reverse-shell binary.",+ "expected_tactics": [+ "TA0001",+ "TA0002"+ ],+ "expected_techniques": [+ "T1195.002",+ "T1610"+ ],+ "severity": "high",+ "response_class": "rollback_change",+ "evidence_keywords": [+ "container image",+ "registry",+ "backdoor",+ "netcat",+ "AZURE-VM-FIN-001"+ ],+ "original_title": "Container image with embedded backdoor pulled by AZURE-VM-FIN-001",+ "original_description": "Image registry/repo:malicious-backdoor pulled by AZURE-VM-FIN-001. Layer scan flagged embedded netcat reverse-shell binary."+ },+ {+ "id": "INC-EVAL-161",+ "template_id": "outlook-auto-forward-rule",+ "template_index": 50,+ "adversary_intensity": "medium",+ "title": "Outlook rule auto-forwarding mail from [email protected]",+ "description": "Outlook inbox rule created for [email protected] that forwards all mail to external address at 185.220.101.7. Linked to LockBit 3.0.",+ "expected_tactics": [+ "TA0006",+ "TA0009"+ ],+ "expected_techniques": [+ "T1564.008",+ "T1114.003"+ ],+ "severity": "high",+ "response_class": "disable_account",+ "evidence_keywords": [+ "outlook rule",+ "forward",+ "mail",+ "[email protected]",+ "185.220.101.7",+ "LockBit 3.0"+ ],+ "original_title": "Outlook rule auto-forwarding mail from [email protected]",+ "original_description": "Outlook inbox rule created for [email protected] that forwards all mail to external address at 185.220.101.7. Linked to LockBit 3.0."+ },+ {+ "id": "INC-EVAL-162",+ "template_id": "linux-journald-tampering",+ "template_index": 51,+ "adversary_intensity": "heavy",+ "title": "Linux journald log modify-on-the-fly on WIN-PROD-WEB02",+ "description": "j0urnalctl --rotate --c0mpact db-time=1s observed on WIN-PROD-WEB02 by [email protected]; recent journal entries purged. footprint cleanup.",+ "expected_tactics": [+ "TA0005"+ ],+ "expected_techniques": [+ "T1070.002"+ ],+ "severity": "high",+ "response_class": "escalate",+ "evidence_keywords": [+ "journalctl",+ "log tampering",+ "vacuum",+ "WIN-PROD-WEB02",+ ],+ "original_title": "Linux journald log tampering on WIN-PROD-WEB02",+ "original_description": "journalctl --rotate --vacuum-time=1s observed on WIN-PROD-WEB02 by [email protected]; recent journal entries purged. Indicator removal."+ },+ {+ "id": "INC-EVAL-163",+ "template_id": "compromised-ci-runner",+ "template_index": 52,+ "adversary_intensity": "heavy",+ "title": "Compromised CI runner on AZURE-VM-FIN-001 pushing to production",+ "description": "Self-hosted CI runner AZURE-VM-FIN-001 compromised. Job triggered from PR injected secret exfil step; secrets posted to 172.16.50.7.",+ "expected_tactics": [+ "TA0001",+ "TA0006",+ "TA0010"+ ],+ "expected_techniques": [+ "T1195.002",+ "T1552.004"+ ],+ "severity": "critical",+ "response_class": "rollback_change",+ "evidence_keywords": [+ "ci runner",+ "self-hosted",+ "secret",+ "exfil",+ "AZURE-VM-FIN-001",+ "172.16.50.7"+ ],+ "original_title": "Compromised CI runner on AZURE-VM-FIN-001 pushing to production",+ "original_description": "Self-hosted CI runner AZURE-VM-FIN-001 compromised. Job triggered from PR injected secret exfil step; secrets posted to 172.16.50.7."+ },+ {+ "id": "INC-EVAL-164",+ "template_id": "vpn-new-geography",+ "template_index": 53,+ "adversary_intensity": "medium",+ "title": "Suspicious VPN login from new geography for [email protected]",+ "description": "VPN login for [email protected] from 10.0.99.42 (new country, no prior history). Subsequent e-w hop windows-share probe from VPN range to LIN-EDGE-VPN02.",+ "expected_tactics": [+ "TA0001",+ "TA0008"+ ],+ "expected_techniques": [+ "T1078.004",+ "T1021.002"+ ],+ "severity": "high",+ "response_class": "disable_account",+ "evidence_keywords": [+ "vpn",+ "new geography",+ "lateral",+ "smb scan",+ "[email protected]",+ "10.0.99.42",+ "LIN-EDGE-VPN02"+ ],+ "original_title": "Suspicious VPN login from new geography for [email protected]",+ "original_description": "VPN login for [email protected] from 10.0.99.42 (new country, no prior history). Subsequent lateral SMB scan from VPN range to LIN-EDGE-VPN02."+ },+ {+ "id": "INC-EVAL-165",+ "template_id": "service-account-privileged-command",+ "template_index": 54,+ "adversary_intensity": "medium",+ "title": "Privileged command run as background unit account on K8S-PROD-CLUSTER",+ "description": "background unit account [email protected] (no interactive use expected) ran privileged net.exe + wevtutil cl Security on K8S-PROD-CLUSTER. Anomalous.",+ "expected_tactics": [+ "TA0005",+ "TA0006"+ ],+ "expected_techniques": [+ "T1078.001",+ "T1070.001"+ ],+ "severity": "high",+ "response_class": "disable_account",+ "evidence_keywords": [+ "service account",+ "wevtutil",+ "log clear",+ "[email protected]",+ "K8S-PROD-CLUSTER"+ ],+ "original_title": "Privileged command run as service account on K8S-PROD-CLUSTER",+ "original_description": "Service account [email protected] (no interactive use expected) ran privileged net.exe + wevtutil cl Security on K8S-PROD-CLUSTER. Anomalous."+ },+ {+ "id": "INC-EVAL-166",+ "template_id": "phishing-macro-email",+ "template_index": 0,+ "adversary_intensity": "heavy",+ "title": "directed baiting email with m@cro-laden attachment delivered to [email protected]",+ "description": "Inbound email from 203.0.113.45 delivered an Office document with a malicious off1ce-automation language m@cro to [email protected]. Attachment opened on LIN-BUILD-CI03; m@cro spawned shell-host.exe and downloaded a second-tier dropper from a known Emotet epoch 5 infrastructure.",+ "expected_tactics": [+ "TA0001",+ "TA0002"+ ],+ "expected_techniques": [+ "T1566.001",+ "T1059.005"+ ],+ "severity": "high",+ "response_class": "block_indicator",+ "evidence_keywords": [+ "phishing email",+ "macro",+ "203.0.113.45",+ "LIN-BUILD-CI03",+ "[email protected]",+ "stage-2 payload"+ ],+ "original_title": "Spear-phishing email with macro-laden attachment delivered to [email protected]",+ "original_description": "Inbound email from 203.0.113.45 delivered an Office document with a malicious VBA macro to [email protected]. Attachment opened on LIN-BUILD-CI03; macro spawned cmd.exe and downloaded a stage-2 payload from a known Emotet epoch 5 infrastructure."+ },+ {+ "id": "INC-EVAL-167",+ "template_id": "webapp-sqli-ssrf-exploit",+ "template_index": 1,+ "adversary_intensity": "medium",+ "title": "Exploitation of public-facing web app on AZURE-VM-FIN-001",+ "description": "WAF logs show SQL-injection and SSRF probes from 198.51.100.23 against the application on AZURE-VM-FIN-001. One request returned 200 with internal cloud-metadata content. Likely exploitation of CVE-2024-1234.",+ "expected_tactics": [+ "TA0001",+ "TA0007"+ ],+ "expected_techniques": [+ "T1190",+ "T1082"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "WAF",+ "SQL injection",+ "SSRF",+ "CVE-2024-1234",+ "AZURE-VM-FIN-001",+ "198.51.100.23"+ ],+ "original_title": "Exploitation of public-facing web app on AZURE-VM-FIN-001",+ "original_description": "WAF logs show SQL-injection and SSRF probes from 198.51.100.23 against the application on AZURE-VM-FIN-001. One request returned 200 with internal cloud-metadata content. Likely exploitation of CVE-2024-1234."+ },+ {+ "id": "INC-EVAL-168",+ "template_id": "confluence-watering-hole",+ "template_index": 2,+ "adversary_intensity": "medium",+ "title": "Watering-hole exploit served from internal Confluence by 172.16.50.7",+ "description": "Internal Confluence page injected with malicious JavaScript by 172.16.50.7. Drive-by exploit triggered browser exploitation on multiple visitors including [email protected]. Linked to ALPHV/BlackCat TTPs.",+ "expected_tactics": [+ "TA0001",+ "TA0002"+ ],+ "expected_techniques": [+ "T1189",+ "T1203"+ ],+ "severity": "high",+ "response_class": "block_indicator",+ "evidence_keywords": [+ "watering hole",+ "drive-by",+ "Confluence",+ "172.16.50.7",+ "[email protected]",+ "ALPHV/BlackCat"+ ],+ "original_title": "Watering-hole exploit served from internal Confluence by 172.16.50.7",+ "original_description": "Internal Confluence page injected with malicious JavaScript by 172.16.50.7. Drive-by exploit triggered browser exploitation on multiple visitors including [email protected]. Linked to ALPHV/BlackCat TTPs."+ },+ {+ "id": "INC-EVAL-169",+ "template_id": "npm-supply-chain",+ "template_index": 3,+ "adversary_intensity": "light",+ "title": "Supply-chain compromise: malicious npm package on WIN-PROD-WEB02",+ "description": "CI pipeline on WIN-PROD-WEB02 installed compromised npm package `event-stream`. Post-install hook executed reverse shell to 91.134.231.15. Build artefacts may be tainted.",+ "expected_tactics": [+ "TA0001",+ "TA0002"+ ],+ "expected_techniques": [+ "T1195.001",+ "T1059.007"+ ],+ "severity": "critical",+ "response_class": "rollback_change",+ "evidence_keywords": [+ "supply chain",+ "npm package",+ "event-stream",+ "post-install",+ "WIN-PROD-WEB02",+ "91.134.231.15"+ ],+ "original_title": "Supply-chain compromise: malicious npm package on WIN-PROD-WEB02",+ "original_description": "CI pipeline on WIN-PROD-WEB02 installed compromised npm package `event-stream`. Post-install hook executed reverse shell to 91.134.231.15. Build artefacts may be tainted."+ },+ {+ "id": "INC-EVAL-170",+ "template_id": "usb-autorun-airgap",+ "template_index": 4,+ "adversary_intensity": "medium",+ "title": "Malicious USB autorun on air-gapped host AWS-Eops channel-PROD-API",+ "description": "USB device inserted on air-gapped AWS-Eops channel-PROD-API by [email protected]. AutoRun executed py interpreter stager that collected local files. Data staged in C:\\Temp\\.",+ "expected_tactics": [+ "TA0001",+ "TA0009"+ ],+ "expected_techniques": [+ "T1091",+ "T1005"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "USB",+ "autorun",+ "air-gapped",+ "AWS-EC2-PROD-API",+ "[email protected]",+ "Python stager"+ ],+ "original_title": "Malicious USB autorun on air-gapped host AWS-EC2-PROD-API",+ "original_description": "USB device inserted on air-gapped AWS-EC2-PROD-API by [email protected]. AutoRun executed Python stager that collected local files. Data staged in C:\\Temp\\."+ },+ {+ "id": "INC-EVAL-171",+ "template_id": "oauth-consent-phish",+ "template_index": 5,+ "adversary_intensity": "light",+ "title": "OAuth consent phi$hing targeting [email protected]",+ "description": "Malicious OAuth application granted Mail.Read and Files.Read.All scopes by [email protected]. Inbox forwarding rule created sending mail to 45.142.122.111.",+ "expected_tactics": [+ "TA0001",+ "TA0006"+ ],+ "expected_techniques": [+ "T1528",+ "T1550.001"+ ],+ "severity": "high",+ "response_class": "disable_account",+ "evidence_keywords": [+ "OAuth consent",+ "Mail.Read",+ "Files.Read.All",+ "[email protected]",+ "45.142.122.111",+ "forwarding rule"+ ],+ "original_title": "OAuth consent phishing targeting [email protected]",+ "original_description": "Malicious OAuth application granted Mail.Read and Files.Read.All scopes by [email protected]. Inbox forwarding rule created sending mail to 45.142.122.111."+ },+ {+ "id": "INC-EVAL-172",+ "template_id": "powershell-obfuscated-dropper",+ "template_index": 6,+ "adversary_intensity": "medium",+ "title": "Obfuscated p\u200bow\u200bersh\u200bell dropper executed on AWS-Ecallback infra-PROD-API",+ "description": "p\u200bow\u200bersh\u200bell dropper executed on AWS-Ecallback infra-PROD-API by [email protected]; payload base64-encoded and decoded in-memory. Linked to Volt Typhoon data-lockout demandware staging.",+ "expected_tactics": [+ "TA0002",+ "TA0005"+ ],+ "expected_techniques": [+ "T1059.001",+ "T1027"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "powershell",+ "obfuscated",+ "base64",+ "AWS-EC2-PROD-API",+ "[email protected]",+ "Volt Typhoon"+ ],+ "original_title": "Obfuscated PowerShell dropper executed on AWS-EC2-PROD-API",+ "original_description": "PowerShell dropper executed on AWS-EC2-PROD-API by [email protected]; payload base64-encoded and decoded in-memory. Linked to Volt Typhoon ransomware staging."+ },+ {+ "id": "INC-EVAL-173",+ "template_id": "certutil-download-cradle",+ "template_index": 7,+ "adversary_intensity": "light",+ "title": "Living-off-the-land: certutil download cradle on MAC-LEGAL-LAPTOP",+ "description": "certutil.exe -urlcache invoked from cmd.exe on MAC-LEGAL-LAPTOP. cmd.exe was spawned by outlook.exe. Payload downloaded from 192.168.1.100.",+ "expected_tactics": [+ "TA0002",+ "TA0005"+ ],+ "expected_techniques": [+ "T1105",+ "T1218.009"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "certutil",+ "urlcache",+ "outlook.exe",+ "MAC-LEGAL-LAPTOP",+ "192.168.1.100",+ "download cradle"+ ],+ "original_title": "Living-off-the-land: certutil download cradle on MAC-LEGAL-LAPTOP",+ "original_description": "certutil.exe -urlcache invoked from cmd.exe on MAC-LEGAL-LAPTOP. cmd.exe was spawned by outlook.exe. Payload downloaded from 192.168.1.100."+ },+ {+ "id": "INC-EVAL-174",+ "template_id": "docker-runtime-abuse",+ "template_index": 8,+ "adversary_intensity": "medium",+ "title": "Container runtime abuse: malicious `orchestrator launch` on WIN-DC-SECONDARY",+ "description": "Unauthenticated Docker API on WIN-DC-SECONDARY exploited from 198.51.100.23. workload containing compute hijack for currencyr spawned. CPU on host saturated to 95%.",+ "expected_tactics": [+ "TA0002",+ "TA0001",+ "TA0040"+ ],+ "expected_techniques": [+ "T1610",+ "T1059.004",+ "T1496"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "docker",+ "container",+ "cryptominer",+ "miner",+ "WIN-DC-SECONDARY",+ "198.51.100.23"+ ],+ "original_title": "Container runtime abuse: malicious `docker run` on WIN-DC-SECONDARY",+ "original_description": "Unauthenticated Docker API on WIN-DC-SECONDARY exploited from 198.51.100.23. Container with cryptominer spawned. CPU on host saturated to 95%."+ },+ {+ "id": "INC-EVAL-175",+ "template_id": "wmi-event-subscription",+ "template_index": 9,+ "adversary_intensity": "light",+ "title": "Malicious WMI subscription on MAC-CFO-LAPTOP",+ "description": "Permanent WMI event subscription created on MAC-CFO-LAPTOP by [email protected]. Consumer runs encoded script. Persistence + execution mechanism.",+ "expected_tactics": [+ "TA0002",+ "TA0003"+ ],+ "expected_techniques": [+ "T1546.003",+ "T1059.001"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "WMI",+ "subscription",+ "permanent",+ "MAC-CFO-LAPTOP",+ "[email protected]",+ "encoded script"+ ],+ "original_title": "Malicious WMI subscription on MAC-CFO-LAPTOP",+ "original_description": "Permanent WMI event subscription created on MAC-CFO-LAPTOP by [email protected]. Consumer runs encoded script. Persistence + execution mechanism."+ },+ {+ "id": "INC-EVAL-176",+ "template_id": "registry-run-persistence",+ "template_index": 10,+ "adversary_intensity": "heavy",+ "title": "reg-autostart entry key re-establish footing created by [email protected] on AWS-Ec\u200b2-PROD-API",+ "description": "New value written to HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run on AWS-Ec\u200b2-PROD-API. Points to roaming binary signed with revoked cert. Linked to APT29.",+ "expected_tactics": [+ "TA0003"+ ],+ "expected_techniques": [+ "T1547.001"+ ],+ "severity": "medium",+ "response_class": "rollback_change",+ "evidence_keywords": [+ "registry run",+ "persistence",+ "revoked cert",+ "AWS-EC2-PROD-API",+ "[email protected]",+ "APT29"+ ],+ "original_title": "Registry Run key persistence created by [email protected] on AWS-EC2-PROD-API",+ "original_description": "New value written to HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run on AWS-EC2-PROD-API. Points to roaming binary signed with revoked cert. Linked to APT29."+ },+ {+ "id": "INC-EVAL-177",+ "template_id": "scheduled-task-persistence",+ "template_index": 11,+ "adversary_intensity": "medium",+ "title": "Scheduled task persistence on WIN-DC-SECONDARY",+ "description": "Hidden scheduled task created on WIN-DC-SECONDARY by [email protected]: triggers every 30 minutes, runs in-line code blob from %APPDATA%\\Roaming. Persistence mechanism.",+ "expected_tactics": [+ "TA0003"+ ],+ "expected_techniques": [+ "T1053.005"+ ],+ "severity": "medium",+ "response_class": "rollback_change",+ "evidence_keywords": [+ "scheduled task",+ "persistence",+ "APPDATA",+ "WIN-DC-SECONDARY",+ ],+ "original_title": "Scheduled task persistence on WIN-DC-SECONDARY",+ "original_description": "Hidden scheduled task created on WIN-DC-SECONDARY by [email protected]: triggers every 30 minutes, runs script from %APPDATA%\\Roaming. Persistence mechanism."+ },+ {+ "id": "INC-EVAL-178",+ "template_id": "uefi-firmware-implant",+ "template_index": 12,+ "adversary_intensity": "medium",+ "title": "low-level board code long-residence agent detected on platform pre-boot f1rmware partition of MAC-CFO-LAPTOP",+ "description": "platform pre-boot f1rmware secure-boot violation on MAC-CFO-LAPTOP. Unknown module detected in low-level board code. Signature matches MosaicRoutward trafficor long-residence agent.",+ "expected_tactics": [+ "TA0003",+ "TA0005"+ ],+ "expected_techniques": [+ "T1542.001",+ "T1027.002"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "UEFI",+ "firmware",+ "implant",+ "secure boot",+ "MAC-CFO-LAPTOP",+ "MosaicRegressor"+ ],+ "original_title": "Firmware implant detected on UEFI partition of MAC-CFO-LAPTOP",+ "original_description": "UEFI secure-boot violation on MAC-CFO-LAPTOP. Unknown module detected in firmware. Signature matches MosaicRegressor implant."+ },+ {+ "id": "INC-EVAL-179",+ "template_id": "cron-backdoor",+ "template_index": 13,+ "adversary_intensity": "medium",+ "title": "b@ckdoor unix periodic job job installed on LIN-BUILD-CI03",+ "description": "/etc/unix periodic job.d entry created by [email protected] on LIN-BUILD-CI03. Reverse shell beacon to 10.0.99.42 every 5 minutes.",+ "expected_tactics": [+ "TA0003",+ "TA0011"+ ],+ "expected_techniques": [+ "T1053.003",+ "T1071.001"+ ],+ "severity": "high",+ "response_class": "rollback_change",+ "evidence_keywords": [+ "cron",+ "backdoor",+ "reverse shell",+ "LIN-BUILD-CI03",+ "[email protected]",+ "10.0.99.42"+ ],+ "original_title": "Backdoor cron job installed on LIN-BUILD-CI03",+ "original_description": "/etc/cron.d entry created by [email protected] on LIN-BUILD-CI03. Reverse shell beacon to 10.0.99.42 every 5 minutes."+ },+ {+ "id": "INC-EVAL-180",+ "template_id": "uac-bypass-fodhelper",+ "template_index": 14,+ "adversary_intensity": "heavy",+ "title": "ua\u200bc circumvention observed on LIN-BUILD-CI03",+ "description": "trusted helper binary.exe abuse on LIN-BUILD-CI03 by [email protected]; auto-rights step-up triggered without prompt. Process tree shows rights uplift to SYSTEM.",+ "expected_tactics": [+ "TA0004",+ "TA0005"+ ],+ "expected_techniques": [+ "T1548.002"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "UAC",+ "fodhelper",+ "auto-elevation",+ "LIN-BUILD-CI03",+ "[email protected]",+ "SYSTEM"+ ],+ "original_title": "UAC bypass observed on LIN-BUILD-CI03",+ "original_description": "fodhelper.exe abuse on LIN-BUILD-CI03 by [email protected]; auto-elevation triggered without prompt. Process tree shows escalation to SYSTEM."+ },+ {+ "id": "INC-EVAL-181",+ "template_id": "k8s-privileged-pod-escape",+ "template_index": 15,+ "adversary_intensity": "heavy",+ "title": "namespace breakout via host-shared workload on WIN-DC-SECONDARY",+ "description": "Kubernetes host-shared workload created on WIN-DC-SECONDARY by [email protected]. cgroup escape to host namespace observed. j$-runtime daemon filesystem accessed.",+ "expected_tactics": [+ "TA0004",+ "TA0007"+ ],+ "expected_techniques": [+ "T1611",+ "T1082"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "kubernetes",+ "privileged pod",+ "container escape",+ "cgroup",+ "WIN-DC-SECONDARY",+ ],+ "original_title": "Container escape via privileged pod on WIN-DC-SECONDARY",+ "original_description": "Kubernetes privileged pod created on WIN-DC-SECONDARY by [email protected]. cgroup escape to host namespace observed. Node filesystem accessed."+ },+ {+ "id": "INC-EVAL-182",+ "template_id": "linux-suid-abuse",+ "template_index": 16,+ "adversary_intensity": "heavy",+ "title": "Linux setid-perm bit binary abuse on WIN-DC-SECONDARY",+ "description": "Custom setid-perm bit binary discovered in /tmp on WIN-DC-SECONDARY; allows arbitrary command code activation as root. Likely level-up by [email protected].",+ "expected_tactics": [+ "TA0004"+ ],+ "expected_techniques": [+ "T1548.001"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "SUID",+ "/tmp",+ "root escalation",+ "WIN-DC-SECONDARY",+ ],+ "original_title": "Linux SUID binary abuse on WIN-DC-SECONDARY",+ "original_description": "Custom SUID binary discovered in /tmp on WIN-DC-SECONDARY; allows arbitrary command execution as root. Likely escalation by [email protected]."+ },+ {+ "id": "INC-EVAL-183",+ "template_id": "process-hollowing-svchost",+ "template_index": 17,+ "adversary_intensity": "heavy",+ "title": "in-mem-only no-disk-write long-residence agent in svchost on WIN-FILE-SHARE",+ "description": "image substitution into target procing detected on WIN-FILE-SHARE: svchost.exe replaced with c0balt strike callback ping to 192.168.1.100. No disk artefacts. Linked to ALPHV/BlackCat.",+ "expected_tactics": [+ "TA0002",+ "TA0005"+ ],+ "expected_techniques": [+ "T1055.012",+ "T1620"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "process hollowing",+ "fileless",+ "svchost",+ "Cobalt Strike",+ "WIN-FILE-SHARE",+ "192.168.1.100"+ ],+ "original_title": "Memory-only fileless implant in svchost on WIN-FILE-SHARE",+ "original_description": "Process hollowing detected on WIN-FILE-SHARE: svchost.exe replaced with Cobalt Strike beacon to 192.168.1.100. No disk artefacts. Linked to ALPHV/BlackCat."+ },+ {+ "id": "INC-EVAL-184",+ "template_id": "event-log-cleared",+ "template_index": 18,+ "adversary_intensity": "heavy",+ "title": "trace cleanup: Windows event audit history erased on LIN-EDGE-VPN02",+ "description": "Security event audit history erased on LIN-EDGE-VPN02 by [email protected]. win-log cli.exe cl Security observed in command-line telemetry.",+ "expected_tactics": [+ "TA0005"+ ],+ "expected_techniques": [+ "T1070.001"+ ],+ "severity": "high",+ "response_class": "escalate",+ "evidence_keywords": [+ "wevtutil",+ "log cleared",+ "indicator removal",+ "LIN-EDGE-VPN02",+ ],+ "original_title": "Indicator removal: Windows event log cleared on LIN-EDGE-VPN02",+ "original_description": "Security event log cleared on LIN-EDGE-VPN02 by [email protected]. wevtutil.exe cl Security observed in command-line telemetry."+ },+ {+ "id": "INC-EVAL-185",+ "template_id": "disable-edr-tooling",+ "template_index": 19,+ "adversary_intensity": "medium",+ "title": "Disable security tooling on LIN-K8S-n\u200bode.js01",+ "description": "[email protected] attempted to stop Defender, CrowdStrike, and Sysmon on LIN-K8S-n\u200bode.js01. Tampering telemetry triggered alert.",+ "expected_tactics": [+ "TA0005"+ ],+ "expected_techniques": [+ "T1562.001"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "defender",+ "crowdstrike",+ "sysmon",+ "tampering",+ "LIN-K8S-NODE01",+ ],+ "original_title": "Disable security tooling on LIN-K8S-NODE01",+ "original_description": "[email protected] attempted to stop Defender, CrowdStrike, and Sysmon on LIN-K8S-NODE01. Tampering telemetry triggered alert."+ },+ {+ "id": "INC-EVAL-186",+ "template_id": "lsass-memory-dump",+ "template_index": 20,+ "adversary_intensity": "medium",+ "title": "LSASS memory dump on K8S-PROD-CLUSTER by [email protected]",+ "description": "comsvcs.loadable code module MiniDump observed on K8S-PROD-CLUSTER. lsass.exe memory dumped to C:\\Windows\\Temp\\. Mimikatz signatures detected.",+ "expected_tactics": [+ "TA0006"+ ],+ "expected_techniques": [+ "T1003.001"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "lsass",+ "minidump",+ "comsvcs",+ "mimikatz",+ "K8S-PROD-CLUSTER",+ ],+ "original_title": "LSASS memory dump on K8S-PROD-CLUSTER by [email protected]",+ "original_description": "comsvcs.dll MiniDump observed on K8S-PROD-CLUSTER. lsass.exe memory dumped to C:\\Windows\\Temp\\. Mimikatz signatures detected."+ },+ {+ "id": "INC-EVAL-187",+ "template_id": "credential-spray",+ "template_index": 21,+ "adversary_intensity": "heavy",+ "title": "iterative-login auth-token probe spread against [email protected] from 198.51.100.23",+ "description": "auth-token probe spread from 198.51.100.23 against [email protected]. 1500 password attempts in 30 minutes. One success followed by anomalous Azure AD sign-in.",+ "expected_tactics": [+ "TA0006"+ ],+ "expected_techniques": [+ "T1110.003"+ ],+ "severity": "high",+ "response_class": "disable_account",+ "evidence_keywords": [+ "brute force",+ "credential spray",+ "[email protected]",+ "198.51.100.23",+ "azure ad"+ ],+ "original_title": "Brute-force credential spray against [email protected] from 198.51.100.23",+ "original_description": "Credential spray from 198.51.100.23 against [email protected]. 1500 password attempts in 30 minutes. One success followed by anomalous Azure AD sign-in."+ },+ {+ "id": "INC-EVAL-188",+ "template_id": "kerberoasting",+ "template_index": 22,+ "adversary_intensity": "medium",+ "title": "Kerberoasting from WIN-FIN-DB01",+ "description": "background unit account TGS tickets requested en-masse from WIN-FIN-DB01 by [email protected]. AES256 \u2192 RC4 downgrade observed. Mimikatz tooling indicators.",+ "expected_tactics": [+ "TA0006",+ "TA0008"+ ],+ "expected_techniques": [+ "T1558.003",+ "T1021.001"+ ],+ "severity": "critical",+ "response_class": "disable_account",+ "evidence_keywords": [+ "kerberoast",+ "TGS",+ "RC4",+ "mimikatz",+ "WIN-FIN-DB01",+ ],+ "original_title": "Kerberoasting from WIN-FIN-DB01",+ "original_description": "Service account TGS tickets requested en-masse from WIN-FIN-DB01 by [email protected]. AES256 \u2192 RC4 downgrade observed. Mimikatz tooling indicators."+ },+ {+ "id": "INC-EVAL-189",+ "template_id": "ad-dcsync",+ "template_index": 23,+ "adversary_intensity": "light",+ "title": "Active Directory DCSync from non-DC host LIN-OBS-LOGGER",+ "description": "Replication rights abused from LIN-OBS-LOGGER by [email protected]. All domain NTLM hashes replicated. Severe credentia1 exposure.",+ "expected_tactics": [+ "TA0006",+ "TA0004"+ ],+ "expected_techniques": [+ "T1003.006",+ "T1078.002"+ ],+ "severity": "critical",+ "response_class": "disable_account",+ "evidence_keywords": [+ "dcsync",+ "replication",+ "ntlm hash",+ "LIN-OBS-LOGGER",+ ],+ "original_title": "Active Directory DCSync from non-DC host LIN-OBS-LOGGER",+ "original_description": "Replication rights abused from LIN-OBS-LOGGER by [email protected]. All domain NTLM hashes replicated. Severe credential exposure."+ },+ {+ "id": "INC-EVAL-190",+ "template_id": "saml-golden-ticket",+ "template_index": 24,+ "adversary_intensity": "heavy",+ "title": "fed-assertion golden-ticket: forged assertion targeting [email protected]",+ "description": "Forged fed-assertion assertion detected for [email protected]. Attacker pivoted to Azure AD; account iterating acrossion followed from 198.51.100.23.",+ "expected_tactics": [+ "TA0006",+ "TA0007"+ ],+ "expected_techniques": [+ "T1606.002",+ "T1087.002"+ ],+ "severity": "critical",+ "response_class": "disable_account",+ "evidence_keywords": [+ "saml",+ "golden ticket",+ "forged",+ "azure ad",+ "[email protected]",+ "198.51.100.23"+ ],+ "original_title": "SAML golden-ticket: forged assertion targeting [email protected]",+ "original_description": "Forged SAML assertion detected for [email protected]. Attacker pivoted to Azure AD; account enumeration followed from 198.51.100.23."+ },+ {+ "id": "INC-EVAL-191",+ "template_id": "ldap-bloodhound-discovery",+ "template_index": 25,+ "adversary_intensity": "light",+ "title": "Domain enumeration from AWS-EC2-PROD-API",+ "description": "ldap discovery from AWS-EC2-PROD-API by [email protected]: BloodHound-style queries enumerating users, groups, ACLs.",+ "expected_tactics": [+ "TA0007"+ ],+ "expected_techniques": [+ "T1087.002"+ ],+ "severity": "medium",+ "response_class": "monitor",+ "evidence_keywords": [+ "ldap",+ "bloodhound",+ "domain enumeration",+ "AWS-EC2-PROD-API",+ ],+ "original_title": "Domain enumeration from AWS-EC2-PROD-API",+ "original_description": "ldap discovery from AWS-EC2-PROD-API by [email protected]: BloodHound-style queries enumerating users, groups, ACLs."+ },+ {+ "id": "INC-EVAL-192",+ "template_id": "smb-share-enumeration",+ "template_index": 26,+ "adversary_intensity": "heavy",+ "title": "remote folder iterating acrossion on LIN-DB-REPLICA",+ "description": "Mass SMB fileshare listingeration from LIN-DB-REPLICA by [email protected]; net.exe and p0wer$hell Get-SmbShare invocations across /24 subnet.",+ "expected_tactics": [+ "TA0007"+ ],+ "expected_techniques": [+ "T1135"+ ],+ "severity": "medium",+ "response_class": "monitor",+ "evidence_keywords": [+ "smb",+ "net.exe",+ "Get-SmbShare",+ "share enumeration",+ "LIN-DB-REPLICA",+ ],+ "original_title": "Network share enumeration on LIN-DB-REPLICA",+ "original_description": "Mass SMB share enumeration from LIN-DB-REPLICA by [email protected]; net.exe and PowerShell Get-SmbShare invocations across /24 subnet."+ },+ {+ "id": "INC-EVAL-193",+ "template_id": "pass-the-hash-lateral",+ "template_index": 27,+ "adversary_intensity": "heavy",+ "title": "hash-replay attack from WIN-EXCHANGE-01 to AWS-Eops channel-PROD-API",+ "description": "hash-replay attack east-west pivot from WIN-EXCHANGE-01 to AWS-Eops channel-PROD-API by [email protected]. Golden ticket indicators present. Linked to Lazarus.",+ "expected_tactics": [+ "TA0008",+ "TA0006"+ ],+ "expected_techniques": [+ "T1550.002",+ "T1558.001"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "pass-the-hash",+ "golden ticket",+ "WIN-EXCHANGE-01",+ "AWS-EC2-PROD-API",+ "[email protected]",+ "Lazarus"+ ],+ "original_title": "Pass-the-hash from WIN-EXCHANGE-01 to AWS-EC2-PROD-API",+ "original_description": "Pass-the-hash lateral movement from WIN-EXCHANGE-01 to AWS-EC2-PROD-API by [email protected]. Golden ticket indicators present. Linked to Lazarus."+ },+ {+ "id": "INC-EVAL-194",+ "template_id": "rdp-lateral-movement",+ "template_index": 28,+ "adversary_intensity": "heavy",+ "title": "remote desktop sess horizontal hop from WIN-DEVOPS-LT",+ "description": "Anomalous remote desktop sess session from WIN-DEVOPS-LT ([email protected]) to MAC-CFO-LAPTOP outside business hours. Source admin not normal for MAC-CFO-LAPTOP.",+ "expected_tactics": [+ "TA0008"+ ],+ "expected_techniques": [+ "T1021.001"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "rdp",+ "lateral movement",+ "outside hours",+ "WIN-DEVOPS-LT",+ "MAC-CFO-LAPTOP",+ ],+ "original_title": "RDP lateral movement from WIN-DEVOPS-LT",+ "original_description": "Anomalous RDP session from WIN-DEVOPS-LT ([email protected]) to MAC-CFO-LAPTOP outside business hours. Source admin not normal for MAC-CFO-LAPTOP."+ },+ {+ "id": "INC-EVAL-195",+ "template_id": "wmi-lateral-execution",+ "template_index": 29,+ "adversary_intensity": "medium",+ "title": "WMI horizontal execution from WIN-FILE-SHARE to LIN-DB-REPLICA",+ "description": "wmic.exe /node:LIN-DB-REPLICA process call create observed from WIN-FILE-SHARE by [email protected]. Remote command execution; payload from 91.134.231.15.",+ "expected_tactics": [+ "TA0008",+ "TA0002"+ ],+ "expected_techniques": [+ "T1047"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "wmic",+ "lateral",+ "WIN-FILE-SHARE",+ "LIN-DB-REPLICA",+ "[email protected]",+ "91.134.231.15"+ ],+ "original_title": "WMI lateral execution from WIN-FILE-SHARE to LIN-DB-REPLICA",+ "original_description": "wmic.exe /node:LIN-DB-REPLICA process call create observed from WIN-FILE-SHARE by [email protected]. Remote command execution; payload from 91.134.231.15."+ },+ {+ "id": "INC-EVAL-196",+ "template_id": "bulk-pii-download",+ "template_index": 30,+ "adversary_intensity": "medium",+ "title": "Bulk personal data download by [email protected]",+ "description": "[email protected] downloaded >10 GB of subscriber records from production database from LIN-K8S-n\u200bode.js01. Outside normal access p@ttern.",+ "expected_tactics": [+ "TA0009",+ "TA0010"+ ],+ "expected_techniques": [+ "T1005",+ "T1041"+ ],+ "severity": "critical",+ "response_class": "disable_account",+ "evidence_keywords": [+ "bulk download",+ "pii",+ "customer record",+ "LIN-K8S-NODE01",+ ],+ "original_title": "Bulk PII download by [email protected]",+ "original_description": "[email protected] downloaded >10 GB of customer records from production database from LIN-K8S-NODE01. Outside normal access pattern."+ },+ {+ "id": "INC-EVAL-197",+ "template_id": "clipboard-keylogger",+ "template_index": 31,+ "adversary_intensity": "medium",+ "title": "Clipboard logging long-residence agent on WIN-PROD-WEB02",+ "description": "Clipboard contents from WIN-PROD-WEB02 ([email protected]) being captured to %APPDATA%\\Local\\. Captures span 2 hours and include auth-tokens and crypto addresses.",+ "expected_tactics": [+ "TA0009"+ ],+ "expected_techniques": [+ "T1115"+ ],+ "severity": "high",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "clipboard",+ "keylog",+ "credentials",+ "WIN-PROD-WEB02",+ ],+ "original_title": "Clipboard logging implant on WIN-PROD-WEB02",+ "original_description": "Clipboard contents from WIN-PROD-WEB02 ([email protected]) being captured to %APPDATA%\\Local\\. Captures span 2 hours and include credentials and crypto addresses."+ },+ {+ "id": "INC-EVAL-198",+ "template_id": "dns-tunnel-exfil",+ "template_index": 32,+ "adversary_intensity": "heavy",+ "title": "dns covert trackling outbound siphonion from WIN-PROD-WEB02",+ "description": "d\u200bns query volume from WIN-PROD-WEB02 50\u00d7 baseline. TXT records contain base64-base64-wrapd payloads. Estimated exfil ~200 MB; destination 203.0.113.45.",+ "expected_tactics": [+ "TA0011",+ "TA0010"+ ],+ "expected_techniques": [+ "T1071.004",+ "T1048.003"+ ],+ "severity": "critical",+ "response_class": "isolate_host",+ "evidence_keywords": [+ "dns tunnel",+ "txt records",+ "base64",+ "exfiltrat",+ "WIN-PROD-WEB02",+ "203.0.113.45"+ ],+ "original_title": "DNS tunnelling exfiltration from WIN-PROD-WEB02",+ "original_description": "DNS query volume from WIN-PROD-WEB02 50\u00d7 baseline. TXT records contain base64-encoded payloads. Estimated exfil ~200 MB; destination 203.0.113.45."+ },+ {+ "id": "INC-EVAL-199",+ "template_id": "s3-exfil-cloud-storage",+ "template_index": 33,+ "adversary_intensity": "medium",+ "title": "Cloud storage exfil: data egress to attacker-controlled S3 from K8S-PROD-CLUSTER",+ "description": "Egress from K8S-PROD-CLUSTER to s3://atk-stage-45.142.122.111/d\u200bump/ by [email protected]. 8 GB transferred over 20 minutes. CloudTrail PutObject events match.",+ "expected_tactics": [+ "TA0010"+ ],+ "expected_techniques": [+ "T1567.002"+ ],+ "severity": "critical",+ "response_class": "block_indicator",+ "evidence_keywords": [+ "s3",+ "cloud storage",+ "egress",+ "exfiltrat",+ "K8S-PROD-CLUSTER",+ "45.142.122.111",+ ],+ "original_title": "Cloud storage exfil: data egress to attacker-controlled S3 from K8S-PROD-CLUSTER",+ "original_description": "Egress from K8S-PROD-CLUSTER to s3://atk-stage-45.142.122.111/dump/ by [email protected]. 8 GB transferred over 20 minutes. CloudTrail PutObject events match."+ },+ {+ "id": "INC-EVAL-200",+ "template_id": "personal-drive-exfil",+ "template_index": 34,+ "adversary_intensity": "light",+ "title": "Personal Drive exfil by [email protected]",+ "description": "[email protected] on LIN-K8S-NODE01 uploaded 4 GB to personal Google Drive. Files include source code and customer PII.",+ "expected_tactics": [+ "TA0009",+ "TA0010"+ ],+ "expected_techniques": [+ "T1567.002",+ "T1005"+ ],+ "severity": "critical",+ "response_class": "disable_account",+ "evidence_keywords": [+ "google drive",+ "personal",+ "exfiltrat",+ "source code",+ "pii",+ "LIN-K8S-NODE01",+ ],+ "original_title": "Personal Drive exfil by [email protected]",+ "original_description": "[email protected] on LIN-K8S-NODE01 uploaded 4 GB to personal Google Drive. Files include source code and customer PII."+ }+]diff --git a/services/agents/tests/eval_data/synthetic_hunt_telemetry.jsonl b/services/agents/tests/eval_data/synthetic_hunt_telemetry.jsonlnew file mode 100644index 000000000..c7f35e2bd--- /dev/null+++ b/services/agents/tests/eval_data/synthetic_hunt_telemetry.jsonl@@ -0,0 +1,15 @@+{"incident_id": "INC-HUNT-001", "template_id": "hunt-svc-account-after-hours", "event_index": 0, "source": "windows_security", "channel": "Security", "Provider": "Microsoft-Windows-Security-Auditing", "EventID": 4624, "Computer": "WIN-PROD-WEB02", "TargetUserName": "svc-deploy", "LogonType": 10, "IpAddress": "10.4.12.55", "LogonProcessName": "User32", "EventTimeUTC": "02:47:00Z"}+{"incident_id": "INC-HUNT-001", "template_id": "hunt-svc-account-after-hours", "event_index": 1, "source": "windows_security", "channel": "Security", "Provider": "Microsoft-Windows-Security-Auditing", "EventID": 4624, "Computer": "WIN-DC-PRIMARY", "TargetUserName": "svc-deploy", "LogonType": 2, "IpAddress": "10.4.12.55", "LogonProcessName": "User32", "EventTimeUTC": "02:51:00Z"}+{"incident_id": "INC-HUNT-001-NEG", "template_id": "hunt-svc-account-after-hours-neg", "event_index": 0, "source": "windows_security", "channel": "Security", "Provider": "Microsoft-Windows-Security-Auditing", "EventID": 4624, "Computer": "WIN-DC-PRIMARY", "TargetUserName": "svc-deploy", "LogonType": 5, "IpAddress": "-", "LogonProcessName": "Advapi", "EventTimeUTC": "02:50:00Z"}+{"incident_id": "INC-HUNT-002", "template_id": "hunt-dns-tunneling-large-txt", "event_index": 0, "source": "dns", "query_name": "QmFzZTY0RXh0cmFjdGVkUmVjb3JkSWQ9NTQzMjE3OTg3NjU0MzIxLnVzZXIuYWlzb2MuZGV2.exfil.45.142.122.111.in-addr.arpa", "query_type": "TXT", "query_length": 142, "src_host": "WIN-PROD-WEB02", "dst_ip": "45.142.122.111", "response_size": 512, "queries_per_hour": 187}+{"incident_id": "INC-HUNT-002", "template_id": "hunt-dns-tunneling-large-txt", "event_index": 1, "source": "dns", "query_name": "WW91U2hhbGxOb3RQYXNzVGhpc0lzREFUQVRyYW5zZmVyU3RyZWFtMQ.exfil.45.142.122.111.in-addr.arpa", "query_type": "TXT", "query_length": 121, "src_host": "WIN-PROD-WEB02", "dst_ip": "45.142.122.111", "response_size": 512, "queries_per_hour": 187}+{"incident_id": "INC-HUNT-002-NEG", "template_id": "hunt-dns-tunneling-large-txt-neg", "event_index": 0, "source": "dns", "query_name": "_dmarc.aisoc.dev", "query_type": "TXT", "query_length": 16, "src_host": "WIN-MAIL-RELAY", "dst_ip": "8.8.8.8", "response_size": 256, "queries_per_hour": 4}+{"incident_id": "INC-HUNT-003", "template_id": "hunt-oauth-app-mass-consent", "event_index": 0, "source": "m365_audit", "Workload": "AzureActiveDirectory", "Operation": "Consent to application.", "UserId": "[email protected]", "ApplicationId": "98765432-aaaa-bbbb-cccc-1234567890ab", "ApplicationName": "Mailbox Helper Pro", "ConsentedScopes": ["Mail.Read", "Mail.Send", "Files.Read.All", "offline_access"], "distinct_users_per_app_24h": 7}+{"incident_id": "INC-HUNT-003", "template_id": "hunt-oauth-app-mass-consent", "event_index": 1, "source": "m365_audit", "Workload": "AzureActiveDirectory", "Operation": "Consent to application.", "UserId": "[email protected]", "ApplicationId": "98765432-aaaa-bbbb-cccc-1234567890ab", "ApplicationName": "Mailbox Helper Pro", "ConsentedScopes": ["Mail.Read", "offline_access"], "distinct_users_per_app_24h": 7}+{"incident_id": "INC-HUNT-003-NEG", "template_id": "hunt-oauth-app-mass-consent-neg", "event_index": 0, "source": "m365_audit", "Workload": "AzureActiveDirectory", "Operation": "Consent to application.", "UserId": "[email protected]", "ApplicationId": "11111111-2222-3333-4444-555555555555", "ApplicationName": "Microsoft Teams", "ConsentedScopes": ["User.Read"], "distinct_users_per_app_24h": 1}+{"incident_id": "INC-HUNT-004", "template_id": "hunt-cloud-iam-role-anomalous-assume", "event_index": 0, "source": "cloudtrail", "eventName": "AssumeRole", "eventSource": "sts.amazonaws.com", "awsRegion": "us-east-1", "userIdentity": {"type": "AssumedRole", "principalId": "AROAEXTERNALACCT123:attacker"}, "sourceIPAddress": "45.142.122.111", "requestParameters": {"roleArn": "arn:aws:iam::123456789012:role/prod-readonly", "roleSessionName": "atk-session-001"}, "principal_first_seen_against_role": true, "privileged_calls_within_5min": 12}+{"incident_id": "INC-HUNT-004", "template_id": "hunt-cloud-iam-role-anomalous-assume", "event_index": 1, "source": "cloudtrail", "eventName": "ListBuckets", "eventSource": "s3.amazonaws.com", "awsRegion": "us-east-1", "userIdentity": {"type": "AssumedRole", "principalId": "AROAEXTERNALACCT123:attacker", "sessionContext": {"sessionIssuer": {"arn": "arn:aws:iam::123456789012:role/prod-readonly"}}}, "sourceIPAddress": "45.142.122.111", "privileged_calls_within_5min": 12}+{"incident_id": "INC-HUNT-004-NEG", "template_id": "hunt-cloud-iam-role-anomalous-assume-neg", "event_index": 0, "source": "cloudtrail", "eventName": "AssumeRole", "eventSource": "sts.amazonaws.com", "awsRegion": "us-east-1", "userIdentity": {"type": "AssumedRole", "principalId": "AROACI0123456:ci-deployer"}, "sourceIPAddress": "10.0.0.50", "requestParameters": {"roleArn": "arn:aws:iam::123456789012:role/ci-deploy", "roleSessionName": "github-action-deploy"}, "principal_first_seen_against_role": false}+{"incident_id": "INC-HUNT-005", "template_id": "hunt-lolbin-rundll32-network", "event_index": 0, "source": "sysmon", "channel": "Microsoft-Windows-Sysmon/Operational", "Provider": "Microsoft-Windows-Sysmon", "EventID": 3, "Computer": "WIN-PROD-WEB02", "User": "[email protected]", "Image": "C:\\Windows\\System32\\rundll32.exe", "DestinationIp": "91.134.231.15", "DestinationPort": 443, "DestinationIp_is_public": true, "DestinationIp_is_microsoft": false}+{"incident_id": "INC-HUNT-005", "template_id": "hunt-lolbin-rundll32-network", "event_index": 1, "source": "sysmon", "channel": "Microsoft-Windows-Sysmon/Operational", "Provider": "Microsoft-Windows-Sysmon", "EventID": 1, "Computer": "WIN-PROD-WEB02", "User": "[email protected]", "Image": "C:\\Windows\\System32\\rundll32.exe", "ParentImage": "C:\\Program Files\\Microsoft Office\\root\\Office16\\WINWORD.EXE", "CommandLine": "rundll32.exe C:\\Users\\Public\\x.dll,EntryPoint"}+{"incident_id": "INC-HUNT-005-NEG", "template_id": "hunt-lolbin-rundll32-network-neg", "event_index": 0, "source": "sysmon", "channel": "Microsoft-Windows-Sysmon/Operational", "Provider": "Microsoft-Windows-Sysmon", "EventID": 3, "Computer": "WIN-PROD-WEB02", "User": "SYSTEM", "Image": "C:\\Windows\\System32\\rundll32.exe", "DestinationIp": "20.190.190.35", "DestinationPort": 443, "DestinationIp_is_public": true, "DestinationIp_is_microsoft": true}diff --git a/services/agents/tests/test_adversary_eval.py b/services/agents/tests/test_adversary_eval.pynew file mode 100644index 000000000..abfe84262--- /dev/null+++ b/services/agents/tests/test_adversary_eval.py@@ -0,0 +1,262 @@+"""+Pillar-1 Evaluation: AI-vs-AI Adversary — Graceful-Degradation Gate (w2-aivai)+==============================================================================+Sixth CI-gated eval suite. Loads the deterministic adversary-mutated dataset+produced by `scripts/generate_adversary_incidents.py` and grades the same+keyword tactic extractor that powers `test_mitre_accuracy.py`.++The dataset rewrites every defender-known keyword into evasive synonyms,+character obfuscation, and fragmentation across three intensity buckets:++ heavy ≈ 45% every keyword swapped+ medium ≈ 35% one expected tactic preserved cleanly+ light ≈ 20% light leetspeak only (control bucket)++Two regression floors are enforced:++ * **Overall catch rate ≥ 0.40** — under heavy adversarial mutation the+ defender is expected to drop ~50pp from its 0.95 baseline. The floor+ of 0.40 keeps "graceful degradation" honest: the substrate must still+ catch a meaningful fraction, but not anywhere near the unmutated+ baseline.+ * **Light-bucket catch rate ≥ 0.85** — light-tier obfuscation is just+ leetspeak; if the defender silently fails this bucket too, then a+ heavy-tier failure is hiding a deeper regression.++Both floors are intentionally below the 0.80 floor of the unmutated+suite. The point of this suite is NOT to prove the defender is great+under adversarial pressure — it's to prove the defender doesn't fall+off a cliff and to give us a measurable graceful-degradation curve we+can watch over time.++Run:+ pytest services/agents/tests/test_adversary_eval.py -v+ # or via the public eval harness:+ python scripts/run_evals.py --out eval_report.json+"""++from __future__ import annotations++import json+import unittest+from pathlib import Path+from typing import Any++from .test_mitre_accuracy import extract_tactics_from_text # type: ignore++_TESTS_DIR = Path(__file__).parent+_ADVERSARY_PATH = _TESTS_DIR / "eval_data" / "adversary_incidents.json"+_BASE_PATH = _TESTS_DIR / "eval_data" / "synthetic_incidents.json"+++# Regression floors. See module docstring for rationale.+_OVERALL_FLOOR = 0.40+_LIGHT_BUCKET_FLOOR = 0.85+# Heavy-tier upper bound: if the heavy bucket starts catching too much,+# either the mutation grammar has drifted off the keyword catalogue or the+# defender has silently widened its substring matches. Either way it+# means the "adversarial" dataset isn't actually adversarial anymore.+_HEAVY_BUCKET_CEILING = 0.50+++class AdversaryEvalResult:+ def __init__(self) -> None:+ self.total = 0+ self.correct = 0+ self.bucket_counts: dict[str, int] = {"heavy": 0, "medium": 0, "light": 0}+ self.bucket_correct: dict[str, int] = {"heavy": 0, "medium": 0, "light": 0}+ self.lost_all_tactics = 0+ self.per_tactic_lost: dict[str, int] = {}+ self.details: list[dict[str, Any]] = []++ @property+ def accuracy(self) -> float:+ return self.correct / self.total if self.total else 0.0++ def bucket_accuracy(self, bucket: str) -> float:+ n = self.bucket_counts.get(bucket, 0)+ return (self.bucket_correct.get(bucket, 0) / n) if n else 0.0++ def to_summary(self) -> dict[str, Any]:+ return {+ "incidents": self.total,+ "correct": self.correct,+ "accuracy": round(self.accuracy, 4),+ "lost_all_tactics": self.lost_all_tactics,+ "buckets": {+ b: {+ "incidents": self.bucket_counts[b],+ "correct": self.bucket_correct[b],+ "accuracy": round(self.bucket_accuracy(b), 4),+ }+ for b in ("heavy", "medium", "light")+ },+ "per_tactic_lost": dict(sorted(self.per_tactic_lost.items())),+ }+++def _load_adversary_dataset() -> list[dict[str, Any]]:+ if not _ADVERSARY_PATH.exists():+ raise FileNotFoundError(+ f"Adversary dataset missing at {_ADVERSARY_PATH}. "+ "Generate with: python3 scripts/generate_adversary_incidents.py"+ )+ return json.loads(_ADVERSARY_PATH.read_text())+++def evaluate_adversary_accuracy() -> AdversaryEvalResult:+ """Run the keyword tactic extractor against the mutated dataset.++ Same scoring rule as `test_mitre_accuracy.py`: a case is correct if+ the predicted tactic set overlaps the expected set by at least one+ tactic. The point is graceful-degradation, not zero-error detection.+ """+ incidents = _load_adversary_dataset()+ result = AdversaryEvalResult()++ for inc in incidents:+ result.total += 1+ bucket = inc.get("adversary_intensity", "heavy")+ result.bucket_counts[bucket] = result.bucket_counts.get(bucket, 0) + 1++ expected = set(inc.get("expected_tactics", []))+ text = f"{inc['title']}\n{inc['description']}"+ predicted = extract_tactics_from_text(text)+ overlap = predicted & expected+ correct = bool(overlap)++ if correct:+ result.correct += 1+ result.bucket_correct[bucket] = result.bucket_correct.get(bucket, 0) + 1+ else:+ result.lost_all_tactics += 1++ for t in expected - predicted:+ result.per_tactic_lost[t] = result.per_tactic_lost.get(t, 0) + 1++ result.details.append(+ {+ "incident_id": inc.get("id"),+ "template_id": inc.get("template_id"),+ "adversary_intensity": bucket,+ "expected": sorted(expected),+ "predicted": sorted(predicted),+ "overlap": sorted(overlap),+ "correct": correct,+ }+ )++ return result+++# ---------------------------------------------------------------------------+# pytest tests+# ---------------------------------------------------------------------------+++class TestAdversaryEval(unittest.TestCase):+ """Sixth CI suite — graceful-degradation under adversarial mutation."""++ def test_dataset_present(self) -> None:+ self.assertTrue(+ _ADVERSARY_PATH.exists(),+ f"Adversary dataset missing at {_ADVERSARY_PATH}. "+ "Run scripts/generate_adversary_incidents.py to (re)generate it.",+ )+ # The mutated set must mirror the base set 1:1 so per-template+ # diffs are meaningful.+ base = json.loads(_BASE_PATH.read_text())+ mutated = json.loads(_ADVERSARY_PATH.read_text())+ self.assertEqual(+ len(base),+ len(mutated),+ f"Adversary dataset size {len(mutated)} != base dataset size {len(base)}",+ )++ def test_dataset_is_actually_mutated(self) -> None:+ """Make sure the generator actually changed the text — not a no-op.++ Some templates legitimately contain no defender keyword the grammar+ knows about (and the light bucket only applies leetspeak), so a+ meaningful fraction of the corpus will pass through unchanged. The+ floor here just guards against the grammar collapsing to a no-op.+ """+ mutated = _load_adversary_dataset()+ unchanged = sum(+ 1+ for inc in mutated+ if inc["title"] == inc.get("original_title")+ and inc["description"] == inc.get("original_description")+ )+ self.assertLess(+ unchanged,+ (len(mutated) * 35) // 100,+ f"{unchanged}/{len(mutated)} incidents unchanged — "+ "mutation grammar may have regressed.",+ )++ def test_overall_graceful_degradation(self) -> None:+ result = evaluate_adversary_accuracy()+ print(+ f"\n[eval] Adversary catch rate: {result.correct}/{result.total} = "+ f"{result.accuracy * 100:.1f}% "+ f"(heavy={result.bucket_accuracy('heavy') * 100:.1f}%, "+ f"medium={result.bucket_accuracy('medium') * 100:.1f}%, "+ f"light={result.bucket_accuracy('light') * 100:.1f}%)"+ )+ self.assertGreaterEqual(+ result.accuracy,+ _OVERALL_FLOOR,+ f"Adversary catch rate {result.accuracy:.1%} below "+ f"graceful-degradation floor of {_OVERALL_FLOOR:.0%}.\n"+ + json.dumps(result.to_summary(), indent=2)[:4000],+ )++ def test_light_bucket_still_caught(self) -> None:+ """Light-tier obfuscation is leetspeak only — defender should pass."""+ result = evaluate_adversary_accuracy()+ light_acc = result.bucket_accuracy("light")+ self.assertGreaterEqual(+ light_acc,+ _LIGHT_BUCKET_FLOOR,+ f"Light-bucket adversary accuracy {light_acc:.1%} below "+ f"control floor of {_LIGHT_BUCKET_FLOOR:.0%}. "+ "Defender keyword extractor may have regressed.",+ )++ def test_heavy_bucket_actually_evades(self) -> None:+ """Heavy-tier mutation must actually hurt the defender.++ If heavy catches too much, the dataset isn't adversarial anymore+ — either the grammar has regressed or the defender has silently+ widened its substring matches.+ """+ result = evaluate_adversary_accuracy()+ heavy_acc = result.bucket_accuracy("heavy")+ self.assertLessEqual(+ heavy_acc,+ _HEAVY_BUCKET_CEILING,+ f"Heavy-bucket adversary accuracy {heavy_acc:.1%} above "+ f"adversariality ceiling of {_HEAVY_BUCKET_CEILING:.0%}. "+ "Mutation grammar isn't actually evading detection — "+ "synonyms may be leaking defender keywords.",+ )++ def test_bucket_distribution(self) -> None:+ """Heavy bucket must be substantial — otherwise we're not testing it."""+ result = evaluate_adversary_accuracy()+ self.assertGreater(+ result.bucket_counts["heavy"],+ result.total // 4,+ f"Heavy bucket only {result.bucket_counts['heavy']}/{result.total} "+ "— mutation distribution may have drifted.",+ )+ self.assertGreater(+ result.bucket_counts["light"],+ 0,+ "Light bucket is empty — no control sample.",+ )+++if __name__ == "__main__":+ unittest.main()diff --git a/services/agents/tests/test_hunt_corpus.py b/services/agents/tests/test_hunt_corpus.pynew file mode 100644index 000000000..b8473480f--- /dev/null+++ b/services/agents/tests/test_hunt_corpus.py@@ -0,0 +1,314 @@+"""+Hunt Corpus Eval Gate (Wave 2 — w2-hac)+=======================================++Grades every YAML hunt under ``hunts/`` against the dedicated synthetic+hunt telemetry corpus at ``services/agents/tests/eval_data/synthetic_hunt_telemetry.jsonl``.++Each hunt declares two expectations in its YAML:++ * ``expected.positive_incident_id`` — the hunt MUST fire on these events,+ with a per-event match score at or above ``expected.min_match_score``.+ * ``expected.negative_incident_id`` — the hunt MUST NOT fire on these+ events. (False positives here block CI.)++This is the same eval-harness pattern used by detections in+``test_synthetic_telemetry.py`` and the alert-reduction / MITRE suites in+``apps/docs/docs/benchmark.md`` — every claim of new hunt coverage has to+extend the corpus and pass the gate.++Run:+ pytest services/agents/tests/test_hunt_corpus.py -v+"""++from __future__ import annotations++import json+import unittest+from collections import defaultdict+from dataclasses import dataclass, field+from pathlib import Path+from typing import Any++from app.hunt.engine import HuntEngine+from app.hunt.loader import HuntCorpus, HuntDefinition++_TESTS_DIR = Path(__file__).parent+_HUNT_TELEMETRY_PATH = _TESTS_DIR / "eval_data" / "synthetic_hunt_telemetry.jsonl"++# Per-hunt eval gates surfaced to ``scripts/run_evals.py``. The hunt corpus+# is small (every hunt is hand-authored), so we hold ourselves to perfect+# scenario coverage rather than a percentage floor.+_POSITIVE_FLOOR = 1.0 # every hunt MUST fire on its declared positive scenario+_NEGATIVE_CEILING = 0.0 # zero false positives on declared negative scenarios+++def _load_hunt_corpus() -> list[HuntDefinition]:+ """Load the YAML hunt corpus from ``hunts/`` (repo root)."""+ corpus = HuntCorpus()+ corpus.reload()+ hunts = corpus.list()+ if not hunts:+ raise FileNotFoundError(+ f"No hunt YAMLs found under {corpus.directory}. "+ "Add at least one hunt to `hunts/` before the gate can grade them."+ )+ return hunts+++def _load_hunt_telemetry() -> list[dict[str, Any]]:+ if not _HUNT_TELEMETRY_PATH.exists():+ raise FileNotFoundError(+ f"Missing {_HUNT_TELEMETRY_PATH}. "+ "Add positive and negative scenarios for each hunt before merging."+ )+ events: list[dict[str, Any]] = []+ with _HUNT_TELEMETRY_PATH.open() as f:+ for line_no, raw in enumerate(f, 1):+ line = raw.strip()+ if not line:+ continue+ try:+ events.append(json.loads(line))+ except json.JSONDecodeError as exc:+ raise AssertionError(+ f"{_HUNT_TELEMETRY_PATH.name}:{line_no} is not valid JSON: {exc}"+ ) from exc+ return events+++def _events_for_incident(events: list[dict[str, Any]], incident_id: str) -> list[dict[str, Any]]:+ return [e for e in events if e.get("incident_id") == incident_id]+++class TestHuntTelemetrySchema(unittest.TestCase):+ """The hunt telemetry corpus has its own minimal schema rules."""++ def setUp(self) -> None:+ self.events = _load_hunt_telemetry()++ def test_every_event_has_envelope_fields(self) -> None:+ """Every event needs at minimum an incident_id and a source."""+ for idx, event in enumerate(self.events):+ self.assertIn("incident_id", event, f"event #{idx} missing incident_id")+ self.assertIn("source", event, f"event #{idx} missing source")+ self.assertTrue(+ str(event["incident_id"]).startswith("INC-HUNT-"),+ f"event #{idx} has non-hunt incident_id {event['incident_id']!r}; "+ "hunt scenarios must use INC-HUNT-* ids to keep them isolated "+ "from the detection telemetry suite.",+ )+++class TestHuntCorpusEval(unittest.TestCase):+ """Grade every hunt against its declared positive + negative scenarios."""++ @classmethod+ def setUpClass(cls) -> None:+ cls.hunts = _load_hunt_corpus()+ cls.events = _load_hunt_telemetry()+ cls.engine = HuntEngine()++ def test_every_hunt_has_eval_scenarios(self) -> None:+ """A hunt without positive/negative scenarios cannot be graded."""+ for hunt in self.hunts:+ with self.subTest(hunt=hunt.id):+ self.assertTrue(+ hunt.expected.positive_incident_id,+ f"hunt {hunt.id} is missing expected.positive_incident_id; "+ "every hunt YAML must declare a positive synthetic scenario.",+ )++ def test_positive_scenarios_fire(self) -> None:+ """Hunt MUST fire on its declared positive incident."""+ misses: list[str] = []+ for hunt in self.hunts:+ pos_id = hunt.expected.positive_incident_id+ if not pos_id:+ continue+ pos_events = _events_for_incident(self.events, pos_id)+ with self.subTest(hunt=hunt.id, scenario=pos_id):+ self.assertTrue(+ pos_events,+ f"hunt {hunt.id} declares positive_incident_id={pos_id} "+ f"but no matching events exist in {_HUNT_TELEMETRY_PATH.name}.",+ )+ result = self.engine.run(hunt, pos_events)+ threshold = hunt.expected.min_match_score+ if not result.findings or result.match_score < threshold:+ misses.append(+ f" - {hunt.id}: scanned {result.events_scanned} events from "+ f"{pos_id}, got {len(result.findings)} findings, "+ f"best score {result.match_score:.2f} < {threshold:.2f}"+ )+ if misses:+ self.fail(+ "Positive-scenario miss — these hunts did not fire on their "+ "declared synthetic incident:\n" + "\n".join(misses)+ )++ def test_negative_scenarios_do_not_fire(self) -> None:+ """Hunt MUST NOT fire on its declared negative incident (false positive guard)."""+ false_positives: list[str] = []+ for hunt in self.hunts:+ neg_id = hunt.expected.negative_incident_id+ if not neg_id:+ continue+ neg_events = _events_for_incident(self.events, neg_id)+ with self.subTest(hunt=hunt.id, scenario=neg_id):+ self.assertTrue(+ neg_events,+ f"hunt {hunt.id} declares negative_incident_id={neg_id} "+ f"but no matching events exist in {_HUNT_TELEMETRY_PATH.name}.",+ )+ result = self.engine.run(hunt, neg_events)+ if result.findings:+ false_positives.append(+ f" - {hunt.id}: fired {len(result.findings)} time(s) "+ f"on negative scenario {neg_id} (best score "+ f"{result.match_score:.2f})"+ )+ if false_positives:+ self.fail(+ "False-positive regression — these hunts fired on their "+ "declared negative scenario:\n" + "\n".join(false_positives)+ )++ def test_every_hunt_telemetry_event_is_owned(self) -> None:+ """Every INC-HUNT-* event must be referenced by at least one hunt YAML.++ Catches drift in the other direction: telemetry left behind after a+ hunt is renamed or deleted.+ """+ owned: dict[str, set[str]] = defaultdict(set)+ for hunt in self.hunts:+ if hunt.expected.positive_incident_id:+ owned[hunt.expected.positive_incident_id].add(hunt.id)+ if hunt.expected.negative_incident_id:+ owned[hunt.expected.negative_incident_id].add(hunt.id)++ orphans = sorted(+ {+ e["incident_id"]+ for e in self.events+ if e["incident_id"] not in owned+ }+ )+ self.assertFalse(+ orphans,+ "These hunt-telemetry incident_ids are not referenced by any hunt "+ f"YAML under hunts/: {orphans}. Either add a hunt that owns them "+ f"or remove the events from {_HUNT_TELEMETRY_PATH.name}.",+ )+++@dataclass+class HuntCorpusEvalResult:+ """Aggregated grading result over the hunt corpus.++ Surfaces the same shape as the other suite result objects so the+ unified runner (`scripts/run_evals.py`) can format it consistently.+ """++ hunts_total: int+ positives_expected: int+ positives_caught: int+ negatives_expected: int+ false_positives: int+ orphan_incident_ids: list[str] = field(default_factory=list)+ misses: list[dict[str, Any]] = field(default_factory=list)+ false_positive_details: list[dict[str, Any]] = field(default_factory=list)++ @property+ def positive_rate(self) -> float:+ if self.positives_expected == 0:+ return 0.0+ return self.positives_caught / self.positives_expected++ @property+ def false_positive_rate(self) -> float:+ if self.negatives_expected == 0:+ return 0.0+ return self.false_positives / self.negatives_expected+++def evaluate_hunt_corpus() -> HuntCorpusEvalResult:+ """Grade the hunt corpus against the synthetic hunt telemetry.++ Mirrors the unittest gates above but returns a structured result so+ `scripts/run_evals.py` can surface hunt coverage as a CI suite without+ needing to re-run pytest.+ """+ hunts = _load_hunt_corpus()+ events = _load_hunt_telemetry()+ engine = HuntEngine()++ misses: list[dict[str, Any]] = []+ false_positives: list[dict[str, Any]] = []+ positives_expected = 0+ positives_caught = 0+ negatives_expected = 0+ false_positive_count = 0+ owned: set[str] = set()++ for hunt in hunts:+ pos_id = hunt.expected.positive_incident_id+ if pos_id:+ owned.add(pos_id)+ positives_expected += 1+ pos_events = _events_for_incident(events, pos_id)+ if not pos_events:+ misses.append({+ "hunt_id": hunt.id,+ "scenario": pos_id,+ "reason": "no_matching_events",+ })+ else:+ result = engine.run(hunt, pos_events)+ threshold = hunt.expected.min_match_score+ if result.findings and result.match_score >= threshold:+ positives_caught += 1+ else:+ misses.append({+ "hunt_id": hunt.id,+ "scenario": pos_id,+ "events_scanned": result.events_scanned,+ "findings": len(result.findings),+ "match_score": round(result.match_score, 4),+ "threshold": threshold,+ })++ neg_id = hunt.expected.negative_incident_id+ if neg_id:+ owned.add(neg_id)+ negatives_expected += 1+ neg_events = _events_for_incident(events, neg_id)+ if neg_events:+ result = engine.run(hunt, neg_events)+ if result.findings:+ false_positive_count += 1+ false_positives.append({+ "hunt_id": hunt.id,+ "scenario": neg_id,+ "findings": len(result.findings),+ "match_score": round(result.match_score, 4),+ })++ orphans = sorted(+ {e["incident_id"] for e in events if e["incident_id"] not in owned}+ )++ return HuntCorpusEvalResult(+ hunts_total=len(hunts),+ positives_expected=positives_expected,+ positives_caught=positives_caught,+ negatives_expected=negatives_expected,+ false_positives=false_positive_count,+ orphan_incident_ids=orphans,+ misses=misses,+ false_positive_details=false_positives,+ )+++if __name__ == "__main__":+ unittest.main()diff --git a/services/api/app/api/v1/endpoints/detection_proposals.py b/services/api/app/api/v1/endpoints/detection_proposals.pynew file mode 100644index 000000000..e5daf4dd2--- /dev/null+++ b/services/api/app/api/v1/endpoints/detection_proposals.py@@ -0,0 +1,547 @@+"""Detection-as-code proposal lifecycle endpoints (Wave 2 — w2-dac).++Surfaces the propose → review → eval-gated → promote flow that brings+detections under the same CI gate as agent prompts. The eval gate is+satisfied by `scripts/run_evals.py` running offline; the result of that+run is stored back on the proposal as ``eval_result`` and a candidate+that regresses MITRE accuracy by ≥ ``max_regression_pp`` percentage+points cannot be promoted.++Endpoints+---------+* ``GET /detection-proposals`` List proposals.+* ``POST /detection-proposals`` Create a proposal.+* ``GET /detection-proposals/{id}`` Proposal detail.+* ``POST /detection-proposals/{id}/comment`` Add a review comment.+* ``POST /detection-proposals/{id}/eval`` Attach eval result + verdict.+* ``POST /detection-proposals/{id}/decide`` Approve/reject a proposal.+* ``POST /detection-proposals/{id}/promote`` Materialise into ``detection_rules``.+* ``GET /detection-proposals/baselines`` List eval baselines.+* ``POST /detection-proposals/baselines`` Record a new baseline.+"""++from __future__ import annotations++import uuid+from datetime import UTC, datetime+from typing import Annotated, Any, Literal++from fastapi import APIRouter, Depends, HTTPException, Query, status+from pydantic import BaseModel, Field+from sqlalchemy import and_, or_, select, update++from app.api.v1.deps import AuthUser, DBSession, require_permission+from app.core.config import settings+from app.models.detection_proposal import (+ DetectionEvalBaseline,+ DetectionRuleProposal,+)+from app.models.detection_rule import DetectionRule++router = APIRouter(prefix="/detection-proposals", tags=["detection_rules", "dac"])+++# ────────────────────────────────────────────────────────────────────────────+# Pydantic schemas+# ────────────────────────────────────────────────────────────────────────────+++class ProposalResponse(BaseModel):+ id: uuid.UUID+ tenant_id: uuid.UUID | None+ base_rule_id: uuid.UUID | None+ promoted_rule_id: uuid.UUID | None+ name: str+ description: str | None+ rule_language: str+ rule_body: str+ category: str+ severity: str+ confidence: int+ mitre_tactics: list+ mitre_techniques: list+ tags: list+ status: str+ eval_result: dict+ review_comments: list+ proposed_by_id: uuid.UUID | None+ decided_by_id: uuid.UUID | None+ decision_comment: str | None+ decided_at: datetime | None+ created_at: datetime+ updated_at: datetime++ model_config = {"from_attributes": True}+++class CreateProposalRequest(BaseModel):+ name: str = Field(..., max_length=255)+ description: str | None = None+ rule_language: str = Field(..., max_length=30)+ rule_body: str+ category: str = Field(..., max_length=100)+ severity: str = "medium"+ confidence: int = Field(default=50, ge=0, le=100)+ mitre_tactics: list[str] = Field(default_factory=list)+ mitre_techniques: list[str] = Field(default_factory=list)+ tags: list[str] = Field(default_factory=list)+ base_rule_id: uuid.UUID | None = None+++class ReviewCommentRequest(BaseModel):+ comment: str = Field(..., min_length=1, max_length=4000)+++class EvalAttachRequest(BaseModel):+ """Attach a `run_evals.py` JSON report to a proposal."""++ eval_report: dict[str, Any] = Field(+ ...,+ description=(+ "Full JSON output of `python3 scripts/run_evals.py --baseline ... "+ "--max-regression-pp ...` for the candidate ruleset."+ ),+ )+ max_regression_pp: float = Field(+ default=1.0,+ ge=0.0,+ le=100.0,+ description="Allowed MITRE accuracy regression vs baseline, in pp.",+ )+++class DecisionRequest(BaseModel):+ decision: Literal["approve", "reject"]+ comment: str | None = Field(default=None, max_length=2000)+++class BaselineResponse(BaseModel):+ id: uuid.UUID+ tenant_id: uuid.UUID | None+ suite: str+ score: float+ payload: dict+ is_active: bool+ recorded_by_id: uuid.UUID | None+ created_at: datetime++ model_config = {"from_attributes": True}+++class CreateBaselineRequest(BaseModel):+ suite: str = Field(..., max_length=64)+ score: float+ payload: dict[str, Any] = Field(default_factory=dict)+++# ────────────────────────────────────────────────────────────────────────────+# Helpers+# ────────────────────────────────────────────────────────────────────────────+++def _ensure_dac_enabled() -> None:+ if not settings.AISOC_FEATURE_DAC:+ raise HTTPException(+ status_code=status.HTTP_404_NOT_FOUND,+ detail="Detection-as-code is disabled (AISOC_FEATURE_DAC=false)",+ )+++async def _load_proposal(+ db: Any,+ proposal_id: uuid.UUID,+ tenant_id: uuid.UUID,+) -> DetectionRuleProposal:+ result = await db.execute(+ select(DetectionRuleProposal).where(+ DetectionRuleProposal.id == proposal_id,+ or_(+ DetectionRuleProposal.tenant_id == tenant_id,+ DetectionRuleProposal.tenant_id.is_(None),+ ),+ )+ )+ proposal = result.scalar_one_or_none()+ if proposal is None:+ raise HTTPException(+ status_code=status.HTTP_404_NOT_FOUND,+ detail="Proposal not found",+ )+ return proposal+++def _evaluate_eval_report(+ eval_report: dict[str, Any],+ baseline_score: float | None,+ max_regression_pp: float,+) -> dict[str, Any]:+ """Compute the gate verdict from a `run_evals.py` JSON report."""+ suites = eval_report.get("suites", {}) or {}+ mitre = suites.get("mitre_accuracy", {}) or {}+ candidate_score = float(mitre.get("value", 0.0))++ # Prefer baseline_compare block if the runner already computed it.+ cmp = eval_report.get("baseline_compare") or {}+ if cmp.get("available"):+ regressed = bool(cmp.get("regressed"))+ drop_pp = float(cmp.get("mitre_drop_pp", 0.0))+ baseline = float(+ cmp.get("deltas", {}).get("mitre_accuracy", {}).get("baseline", baseline_score or candidate_score)+ )+ else:+ baseline = baseline_score if baseline_score is not None else candidate_score+ drop_pp = round(max(0.0, (baseline - candidate_score) * 100), 4)+ regressed = drop_pp >= max_regression_pp++ all_floors_passed = bool(eval_report.get("all_passed", False))+ passed = (not regressed) and all_floors_passed++ return {+ "ran_at": datetime.now(UTC).isoformat(),+ "candidate": {+ "mitre_accuracy": candidate_score,+ "all_passed": all_floors_passed,+ },+ "baseline": {+ "mitre_accuracy": baseline,+ },+ "drop_pp": drop_pp,+ "max_regression_pp": max_regression_pp,+ "regressed": regressed,+ "passed": passed,+ }+++# ────────────────────────────────────────────────────────────────────────────+# Proposal endpoints+# ────────────────────────────────────────────────────────────────────────────++[email protected]("", response_model=list[ProposalResponse])+async def list_proposals(+ current_user: Annotated[AuthUser, Depends(require_permission("rules:read"))],+ db: DBSession,+ proposal_status: str | None = Query(default=None, alias="status"),+ limit: int = Query(default=100, ge=1, le=500),+) -> list[ProposalResponse]:+ """List detection rule proposals visible to the caller."""+ _ensure_dac_enabled()+ filters = [+ or_(+ DetectionRuleProposal.tenant_id == current_user.tenant_id,+ DetectionRuleProposal.tenant_id.is_(None),+ )+ ]+ if proposal_status:+ filters.append(DetectionRuleProposal.status == proposal_status)+ result = await db.execute(+ select(DetectionRuleProposal)+ .where(and_(*filters))+ .order_by(DetectionRuleProposal.created_at.desc())+ .limit(limit)+ )+ return [ProposalResponse.model_validate(p) for p in result.scalars().all()]++[email protected]("", response_model=ProposalResponse, status_code=status.HTTP_201_CREATED)+async def create_proposal(+ request: CreateProposalRequest,+ current_user: Annotated[AuthUser, Depends(require_permission("rules:write"))],+ db: DBSession,+) -> ProposalResponse:+ """Open a new detection proposal in `proposed` state."""+ _ensure_dac_enabled()+ proposal = DetectionRuleProposal(+ tenant_id=current_user.tenant_id,+ base_rule_id=request.base_rule_id,+ name=request.name,+ description=request.description,+ rule_language=request.rule_language,+ rule_body=request.rule_body,+ category=request.category,+ severity=request.severity,+ confidence=request.confidence,+ mitre_tactics=request.mitre_tactics,+ mitre_techniques=request.mitre_techniques,+ tags=request.tags,+ status="proposed",+ proposed_by_id=current_user.user_id,+ )+ db.add(proposal)+ await db.commit()+ await db.refresh(proposal)+ return ProposalResponse.model_validate(proposal)++[email protected]("/baselines", response_model=list[BaselineResponse])+async def list_baselines(+ current_user: Annotated[AuthUser, Depends(require_permission("rules:read"))],+ db: DBSession,+ suite: str | None = Query(default=None),+) -> list[BaselineResponse]:+ """List eval baselines (most recent active baseline per suite is what we gate on)."""+ _ensure_dac_enabled()+ filters: list[Any] = [+ or_(+ DetectionEvalBaseline.tenant_id == current_user.tenant_id,+ DetectionEvalBaseline.tenant_id.is_(None),+ )+ ]+ if suite:+ filters.append(DetectionEvalBaseline.suite == suite)+ result = await db.execute(+ select(DetectionEvalBaseline)+ .where(and_(*filters))+ .order_by(DetectionEvalBaseline.created_at.desc())+ )+ return [BaselineResponse.model_validate(b) for b in result.scalars().all()]+++ "/baselines",+ response_model=BaselineResponse,+ status_code=status.HTTP_201_CREATED,+)+async def record_baseline(+ request: CreateBaselineRequest,+ current_user: Annotated[AuthUser, Depends(require_permission("rules:write"))],+ db: DBSession,+) -> BaselineResponse:+ """Record a new eval baseline and deactivate older entries for the same suite."""+ _ensure_dac_enabled()+ # Deactivate older baselines for the same scope+suite so the gate reads+ # exactly one "current" snapshot.+ await db.execute(+ update(DetectionEvalBaseline)+ .where(+ DetectionEvalBaseline.tenant_id == current_user.tenant_id,+ DetectionEvalBaseline.suite == request.suite,+ DetectionEvalBaseline.is_active.is_(True),+ )+ .values(is_active=False)+ )+ baseline = DetectionEvalBaseline(+ tenant_id=current_user.tenant_id,+ suite=request.suite,+ score=request.score,+ payload=request.payload,+ is_active=True,+ recorded_by_id=current_user.user_id,+ )+ db.add(baseline)+ await db.commit()+ await db.refresh(baseline)+ return BaselineResponse.model_validate(baseline)++[email protected]("/{proposal_id}", response_model=ProposalResponse)+async def get_proposal(+ proposal_id: uuid.UUID,+ current_user: Annotated[AuthUser, Depends(require_permission("rules:read"))],+ db: DBSession,+) -> ProposalResponse:+ """Get a proposal by id."""+ _ensure_dac_enabled()+ proposal = await _load_proposal(db, proposal_id, current_user.tenant_id)+ return ProposalResponse.model_validate(proposal)++[email protected]("/{proposal_id}/comment", response_model=ProposalResponse)+async def comment_on_proposal(+ proposal_id: uuid.UUID,+ request: ReviewCommentRequest,+ current_user: Annotated[AuthUser, Depends(require_permission("rules:write"))],+ db: DBSession,+) -> ProposalResponse:+ """Append a review comment and move the proposal into `in_review`."""+ _ensure_dac_enabled()+ proposal = await _load_proposal(db, proposal_id, current_user.tenant_id)+ if proposal.status in {"promoted", "rejected"}:+ raise HTTPException(+ status_code=status.HTTP_409_CONFLICT,+ detail=f"Proposal is {proposal.status}; cannot add comments",+ )+ comments = list(proposal.review_comments or [])+ comments.append(+ {+ "actor_id": str(current_user.user_id),+ "actor_email": current_user.email,+ "comment": request.comment,+ "at": datetime.now(UTC).isoformat(),+ }+ )+ proposal.review_comments = comments+ if proposal.status == "proposed":+ proposal.status = "in_review"+ await db.commit()+ await db.refresh(proposal)+ return ProposalResponse.model_validate(proposal)++[email protected]("/{proposal_id}/eval", response_model=ProposalResponse)+async def attach_eval_result(+ proposal_id: uuid.UUID,+ request: EvalAttachRequest,+ current_user: Annotated[AuthUser, Depends(require_permission("rules:write"))],+ db: DBSession,+) -> ProposalResponse:+ """Attach the run_evals.py output and compute the gate verdict.++ Reads the active MITRE accuracy baseline for the tenant (falling back+ to the platform-wide baseline) and stores ``eval_result.passed=True``+ only when MITRE accuracy regression is < ``max_regression_pp``.+ """+ _ensure_dac_enabled()+ proposal = await _load_proposal(db, proposal_id, current_user.tenant_id)+ if proposal.status in {"promoted", "rejected"}:+ raise HTTPException(+ status_code=status.HTTP_409_CONFLICT,+ detail=f"Proposal is {proposal.status}; eval cannot be re-attached",+ )++ # Resolve the most recent active MITRE accuracy baseline.+ baseline_q = await db.execute(+ select(DetectionEvalBaseline)+ .where(+ DetectionEvalBaseline.suite == "mitre_accuracy",+ DetectionEvalBaseline.is_active.is_(True),+ or_(+ DetectionEvalBaseline.tenant_id == current_user.tenant_id,+ DetectionEvalBaseline.tenant_id.is_(None),+ ),+ )+ .order_by(DetectionEvalBaseline.created_at.desc())+ .limit(1)+ )+ baseline = baseline_q.scalar_one_or_none()++ verdict = _evaluate_eval_report(+ eval_report=request.eval_report,+ baseline_score=baseline.score if baseline else None,+ max_regression_pp=request.max_regression_pp,+ )++ proposal.eval_result = verdict+ proposal.status = "eval_passed" if verdict["passed"] else "eval_failed"+ await db.commit()+ await db.refresh(proposal)+ return ProposalResponse.model_validate(proposal)++[email protected]("/{proposal_id}/decide", response_model=ProposalResponse)+async def decide_proposal(+ proposal_id: uuid.UUID,+ request: DecisionRequest,+ current_user: Annotated[AuthUser, Depends(require_permission("rules:write"))],+ db: DBSession,+) -> ProposalResponse:+ """Approve or reject a proposal. Approving requires the eval gate to have passed."""+ _ensure_dac_enabled()+ proposal = await _load_proposal(db, proposal_id, current_user.tenant_id)+ if proposal.status in {"promoted", "rejected"}:+ raise HTTPException(+ status_code=status.HTTP_409_CONFLICT,+ detail=f"Proposal already {proposal.status}",+ )++ if request.decision == "approve":+ eval_passed = bool(proposal.eval_result.get("passed")) if proposal.eval_result else False+ if not eval_passed:+ raise HTTPException(+ status_code=status.HTTP_412_PRECONDITION_FAILED,+ detail="Eval gate has not passed; cannot approve. Run the eval suite and attach the report first.",+ )+ proposal.status = "approved"+ else:+ proposal.status = "rejected"++ proposal.decided_by_id = current_user.user_id+ proposal.decided_at = datetime.now(UTC)+ proposal.decision_comment = request.comment+ await db.commit()+ await db.refresh(proposal)+ return ProposalResponse.model_validate(proposal)+++ "/{proposal_id}/promote",+ response_model=ProposalResponse,+ summary="Materialise an approved proposal into the detection_rules table",+)+async def promote_proposal(+ proposal_id: uuid.UUID,+ current_user: Annotated[AuthUser, Depends(require_permission("rules:write"))],+ db: DBSession,+) -> ProposalResponse:+ """Promote an approved proposal: create or update the linked detection rule."""+ _ensure_dac_enabled()+ proposal = await _load_proposal(db, proposal_id, current_user.tenant_id)+ if proposal.status != "approved":+ raise HTTPException(+ status_code=status.HTTP_412_PRECONDITION_FAILED,+ detail=f"Proposal must be approved before promotion (current status: {proposal.status})",+ )++ if proposal.base_rule_id is not None:+ # Edit of an existing rule — update in place, bump version.+ rule_q = await db.execute(+ select(DetectionRule).where(+ DetectionRule.id == proposal.base_rule_id,+ or_(+ DetectionRule.tenant_id == current_user.tenant_id,+ DetectionRule.tenant_id.is_(None),+ ),+ )+ )+ existing = rule_q.scalar_one_or_none()+ if existing is None:+ raise HTTPException(+ status_code=status.HTTP_404_NOT_FOUND,+ detail="Base rule no longer exists; cannot promote as edit",+ )+ await db.execute(+ update(DetectionRule)+ .where(DetectionRule.id == existing.id)+ .values(+ name=proposal.name,+ description=proposal.description,+ rule_language=proposal.rule_language,+ rule_body=proposal.rule_body,+ category=proposal.category,+ severity=proposal.severity,+ confidence=proposal.confidence,+ mitre_tactics=proposal.mitre_tactics,+ mitre_techniques=proposal.mitre_techniques,+ tags=proposal.tags,+ version=existing.version + 1,+ updated_at=datetime.now(UTC),+ )+ )+ promoted_id = existing.id+ else:+ new_rule = DetectionRule(+ tenant_id=current_user.tenant_id,+ name=proposal.name,+ description=proposal.description,+ rule_language=proposal.rule_language,+ rule_body=proposal.rule_body,+ category=proposal.category,+ severity=proposal.severity,+ confidence=proposal.confidence,+ mitre_tactics=proposal.mitre_tactics,+ mitre_techniques=proposal.mitre_techniques,+ tags=proposal.tags,+ created_by_id=current_user.user_id,+ )+ db.add(new_rule)+ await db.flush()+ promoted_id = new_rule.id++ proposal.promoted_rule_id = promoted_id+ proposal.status = "promoted"+ if proposal.decided_at is None:+ proposal.decided_at = datetime.now(UTC)+ proposal.decided_by_id = current_user.user_id+ await db.commit()+ await db.refresh(proposal)+ return ProposalResponse.model_validate(proposal)diff --git a/services/api/app/api/v1/endpoints/federated.py b/services/api/app/api/v1/endpoints/federated.pynew file mode 100644index 000000000..aa367b818--- /dev/null+++ b/services/api/app/api/v1/endpoints/federated.py@@ -0,0 +1,515 @@+"""Federated SIEM search — query Splunk / Sentinel / Elastic in one call.++This endpoint is the API-side half of the ``w3-fed`` federated search+capability. It accepts a single ``UnifiedQuery`` (free-text + indicator+list + time window), fans it out in parallel to every enabled connector+instance whose backend speaks SPL / KQL / ES|QL, and merges the rows.++Why fan out from the API service rather than the agent?++* The credential vault lives in the API service. Decryption needs to+ happen here so the connectors microservice never sees ciphertext.+* The connector instances table is here, with tenant-scoped RLS. The+ agent shouldn't know which tenant has which SIEM — it just submits a+ ``UnifiedQuery`` to ``/api/v1/federated/search`` and gets merged rows+ back tagged with their source.+* Splunk / Sentinel / Elastic each have their own quirks (KQL needs a+ workspace id, SPL needs a search endpoint). Hiding all of that behind+ one endpoint is the whole point.++Trust boundary mirrors ``test_existing_connector``: stored+``auth_config`` is decrypted via the vault and forwarded to the+stateless ``services/connectors`` ``POST /connectors/{type}/query``+endpoint over the internal Docker / VPC network. Plaintext credentials+never round-trip back to the caller.++Per-source isolation: a single misbehaving SIEM (slow, 5xx, 401) must+not block the rest of the federated answer. We run each backend call+inside its own try/except and return a ``sources[]`` array describing+the verdict per backend so the UI can show "Splunk OK · Sentinel+timeout · Elastic OK" rather than a single 502.+"""++from __future__ import annotations++import asyncio+import logging+import time+import uuid+from typing import Annotated, Any++import httpx+from fastapi import APIRouter, Depends, HTTPException, status+from pydantic import BaseModel, Field+from sqlalchemy import select++from app.api.v1.deps import AuthUser, DBSession, require_permission+from app.core.config import settings+from app.models.audit import AuditLog+from app.models.connector import Connector+from app.security.credential_vault import CredentialVaultError, get_vault++logger = logging.getLogger(__name__)++router = APIRouter(prefix="/federated", tags=["federated-search"])+++# Connector types whose ``BaseConnector.supports_federated_search`` is+# True in the connectors microservice today. We pre-filter on this set+# so we don't bother decrypting credentials for, say, an EDR connector+# that has nothing to do with SIEM search. The connectors microservice+# will still return 501 for any type that hasn't opted in, so this list+# is a performance hint, not a security boundary.+FEDERATED_CAPABLE_TYPES: frozenset[str] = frozenset(+ {+ "splunk",+ "microsoft_sentinel",+ "elastic",+ }+)+++# ---------------------------------------------------------------- request/response+++class IndicatorPayload(BaseModel):+ """One ``field <op> value`` triple in a federated query.++ Mirrors ``services.connectors.app.federated.query.Indicator`` but+ expressed as Pydantic so FastAPI can render OpenAPI for the wizard+ + the SDK. The connectors microservice re-validates with+ ``parse_unified_query`` before any translator runs, so this model+ is intentionally permissive on ``value``.+ """++ field: str = Field(min_length=1, max_length=200)+ operator: str = Field(min_length=1, max_length=20)+ value: Any+++class FederatedSearchRequest(BaseModel):+ """Top-level federated search payload.++ ``connector_ids`` lets the caller scope the fan-out to specific+ instances (e.g. "only my prod Splunk, not the staging Sentinel").+ Omit it to query every federated-capable connector the tenant has+ enabled.++ ``per_backend_timeout_seconds`` caps how long any one SIEM gets+ before we move on. Default is half the configured connectors-service+ timeout — long enough for a real SIEM round-trip, short enough that+ a single dead backend doesn't block the merged answer.+ """++ free_text: str = Field(default="", max_length=2_000)+ indicators: list[IndicatorPayload] = Field(default_factory=list)+ since_seconds: int = Field(default=3600, gt=0, le=7 * 24 * 3600)+ limit: int = Field(default=100, gt=0, le=1000)+ connector_ids: list[uuid.UUID] | None = None+ per_backend_timeout_seconds: float | None = Field(default=None, gt=0, le=120)+++class SourceVerdict(BaseModel):+ """Per-backend outcome for a federated call.++ ``status`` is one of:+ * ``ok`` — backend returned rows (possibly zero).+ * ``error`` — backend raised something we caught; ``error`` field+ carries the human message. Other backends may still have+ succeeded.+ * ``unsupported`` — connector type doesn't speak federated search+ (kept for forward-compat; today we pre-filter so this is rare).+ """++ connector_id: uuid.UUID+ connector_name: str+ connector_type: str+ status: str+ row_count: int = 0+ duration_ms: int = 0+ error: str | None = None+++class FederatedSearchResponse(BaseModel):+ rows: list[dict[str, Any]]+ row_count: int+ sources: list[SourceVerdict]+ truncated: bool = Field(+ default=False,+ description="True when the merged row count was capped at ``limit`` after fan-out.",+ )+++class FederatedBackend(BaseModel):+ """Read-only projection of a connector instance eligible for fan-out."""++ connector_id: uuid.UUID+ connector_type: str+ name: str+ health_status: str+ is_enabled: bool+++class FederatedBackendsResponse(BaseModel):+ backends: list[FederatedBackend]+++# ----------------------------------------------------------------------- helpers+++_QUERY_TIMEOUT = httpx.Timeout(+ settings.CONNECTORS_SERVICE_TIMEOUT_SECONDS,+ connect=min(5.0, settings.CONNECTORS_SERVICE_TIMEOUT_SECONDS),+)+++def _connectors_query_url(connector_type: str) -> str:+ base = settings.CONNECTORS_SERVICE_URL.rstrip("/")+ return f"{base}/api/v1/connectors/{connector_type}/query"+++def _ensure_feature_enabled() -> None:+ if not settings.AISOC_FEATURE_FED_SEARCH:+ raise HTTPException(+ status_code=status.HTTP_404_NOT_FOUND,+ detail="federated search is disabled (AISOC_FEATURE_FED_SEARCH=false)",+ )+++async def _fetch_target_connectors(+ db: DBSession,+ tenant_id: uuid.UUID,+ requested_ids: list[uuid.UUID] | None,+) -> list[Connector]:+ """Resolve which connector instances the request will fan out to.++ Filters: tenant-scoped, ``is_enabled=True``, and connector_type in+ the federated-capable set. If the caller passed ``connector_ids``,+ we further restrict to that subset and 404 the call if any of them+ is missing or ineligible (we don't silently drop, because a typo+ in a connector_id should be loud).+ """+ stmt = select(Connector).where(+ Connector.tenant_id == tenant_id,+ Connector.is_enabled.is_(True),+ Connector.connector_type.in_(FEDERATED_CAPABLE_TYPES),+ )+ if requested_ids:+ stmt = stmt.where(Connector.id.in_(requested_ids))++ result = await db.execute(stmt)+ rows = list(result.scalars().all())++ if requested_ids:+ # Loud failure on missing/ineligible IDs — see docstring.+ found_ids = {row.id for row in rows}+ missing = [str(rid) for rid in requested_ids if rid not in found_ids]+ if missing:+ raise HTTPException(+ status_code=status.HTTP_404_NOT_FOUND,+ detail=(+ "connector_ids not found, not enabled, or not federated-capable: "+ + ", ".join(missing)+ ),+ )++ return rows+++async def _query_one_backend(+ connector: Connector,+ query_payload: dict[str, Any],+ timeout: httpx.Timeout,+) -> tuple[SourceVerdict, list[dict[str, Any]]]:+ """Decrypt creds, POST to the connectors microservice, tag rows.++ Never raises — returns a verdict + (possibly empty) rows. The point+ is that one bad SIEM can't cancel the federated answer.+ """+ started = time.monotonic()++ try:+ decrypted_auth = get_vault().decrypt_dict(connector.auth_config or {})+ except CredentialVaultError as exc:+ return (+ SourceVerdict(+ connector_id=connector.id,+ connector_name=connector.name,+ connector_type=connector.connector_type,+ status="error",+ duration_ms=int((time.monotonic() - started) * 1000),+ error=f"credential decryption failed: {exc}",+ ),+ [],+ )++ payload = {+ "auth_config": decrypted_auth,+ "connector_config": connector.connector_config or {},+ "query": query_payload,+ }+ url = _connectors_query_url(connector.connector_type)++ try:+ async with httpx.AsyncClient(timeout=timeout) as client:+ resp = await client.post(url, json=payload)+ except httpx.HTTPError as exc:+ logger.warning(+ "federated.query.unreachable connector=%s url=%s err=%s",+ connector.id,+ url,+ exc,+ )+ return (+ SourceVerdict(+ connector_id=connector.id,+ connector_name=connector.name,+ connector_type=connector.connector_type,+ status="error",+ duration_ms=int((time.monotonic() - started) * 1000),+ error=f"connectors service unreachable: {exc}",+ ),+ [],+ )++ if resp.status_code == status.HTTP_501_NOT_IMPLEMENTED:+ return (+ SourceVerdict(+ connector_id=connector.id,+ connector_name=connector.name,+ connector_type=connector.connector_type,+ status="unsupported",+ duration_ms=int((time.monotonic() - started) * 1000),+ error=resp.text or "connector does not support federated search",+ ),+ [],+ )++ if resp.status_code >= 400:+ # Bubble up the backend's diagnostic but keep status=error so+ # the rest of the federated answer survives.+ try:+ detail = resp.json().get("detail") or resp.text+ except ValueError:+ detail = resp.text+ return (+ SourceVerdict(+ connector_id=connector.id,+ connector_name=connector.name,+ connector_type=connector.connector_type,+ status="error",+ duration_ms=int((time.monotonic() - started) * 1000),+ error=f"backend {resp.status_code}: {detail}",+ ),+ [],+ )++ body = resp.json() if resp.content else {}+ raw_rows = body.get("rows") or []+ if not isinstance(raw_rows, list):+ raw_rows = []++ # Tag each row with its source so the merged response is unambiguous.+ # We use a leading underscore so the field is unlikely to collide+ # with anything the SIEM emitted.+ source_tag = {+ "connector_id": str(connector.id),+ "connector_name": connector.name,+ "connector_type": connector.connector_type,+ }+ tagged_rows = []+ for row in raw_rows:+ if isinstance(row, dict):+ # Don't overwrite a real ``_aisoc_source`` — extremely+ # unlikely in practice but cheap to guard.+ row.setdefault("_aisoc_source", source_tag)+ tagged_rows.append(row)+ else:+ # Defensive: wrap non-dict rows so the merge stays homogeneous.+ tagged_rows.append({"value": row, "_aisoc_source": source_tag})++ return (+ SourceVerdict(+ connector_id=connector.id,+ connector_name=connector.name,+ connector_type=connector.connector_type,+ status="ok",+ row_count=len(tagged_rows),+ duration_ms=int((time.monotonic() - started) * 1000),+ ),+ tagged_rows,+ )+++def _audit_event(+ *,+ tenant_id: uuid.UUID,+ actor_id: uuid.UUID | None,+ actor_email: str | None,+ indicator_fields: list[str],+ sources: list[SourceVerdict],+ row_count: int,+ since_seconds: int,+) -> AuditLog:+ """Build an audit row for the search.++ We deliberately log only the *shape* of the query (which fields were+ filtered, which connectors were queried, how many rows came back),+ never the values. A federated query against a competitor's SaaS+ might contain regulated identifiers in the indicator values; the+ audit log is shared across the tenant and shouldn't carry them.+ """+ return AuditLog(+ tenant_id=tenant_id,+ actor_id=actor_id,+ actor_email=actor_email,+ action="federated_search",+ resource="federated",+ resource_id=None,+ changes=None,+ metadata_={+ "indicator_fields": indicator_fields,+ "since_seconds": since_seconds,+ "row_count": row_count,+ "sources": [+ {+ "connector_id": str(s.connector_id),+ "connector_type": s.connector_type,+ "status": s.status,+ "row_count": s.row_count,+ "duration_ms": s.duration_ms,+ }+ for s in sources+ ],+ },+ )+++# ---------------------------------------------------------------------- endpoints++[email protected]("/backends", response_model=FederatedBackendsResponse)+async def list_federated_backends(+ current_user: Annotated[AuthUser, Depends(require_permission("connectors:read"))],+ db: DBSession,+) -> FederatedBackendsResponse:+ """List the connector instances that ``POST /search`` would fan out to.++ Useful for the wizard preview ("you'll search 1 Splunk + 1 Elastic")+ and for the SDK to build sensible default ``connector_ids`` lists.+ """+ _ensure_feature_enabled()++ rows = await _fetch_target_connectors(db, current_user.tenant_id, requested_ids=None)+ return FederatedBackendsResponse(+ backends=[+ FederatedBackend(+ connector_id=row.id,+ connector_type=row.connector_type,+ name=row.name,+ health_status=row.health_status,+ is_enabled=row.is_enabled,+ )+ for row in rows+ ]+ )++[email protected]("/search", response_model=FederatedSearchResponse)+async def federated_search(+ request: FederatedSearchRequest,+ current_user: Annotated[AuthUser, Depends(require_permission("connectors:read"))],+ db: DBSession,+) -> FederatedSearchResponse:+ """Run a unified query across every federated-capable connector.++ Per-backend errors do not fail the call. The response always+ carries a ``sources[]`` array describing the verdict for each+ backend that was attempted; the merged ``rows[]`` only contains+ rows from the ``ok`` sources.+ """+ _ensure_feature_enabled()++ if not request.free_text.strip() and not request.indicators:+ raise HTTPException(+ status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,+ detail="query must include free_text or at least one indicator",+ )++ targets = await _fetch_target_connectors(+ db, current_user.tenant_id, request.connector_ids+ )+ if not targets:+ # No federated-capable connectors configured: don't 404, return+ # an empty merged result with empty sources[]. Lets the caller+ # treat "no SIEMs" the same as "no results" without a special+ # error path.+ return FederatedSearchResponse(rows=[], row_count=0, sources=[], truncated=False)++ query_payload = {+ "free_text": request.free_text,+ "indicators": [i.model_dump() for i in request.indicators],+ "since_seconds": request.since_seconds,+ "limit": request.limit,+ }++ timeout_seconds = (+ request.per_backend_timeout_seconds+ if request.per_backend_timeout_seconds is not None+ else settings.CONNECTORS_SERVICE_TIMEOUT_SECONDS+ )+ timeout = httpx.Timeout(+ timeout_seconds,+ connect=min(5.0, timeout_seconds),+ )++ fan_out = await asyncio.gather(+ *(+ _query_one_backend(connector, query_payload, timeout)+ for connector in targets+ ),+ return_exceptions=False,+ )++ sources: list[SourceVerdict] = []+ merged: list[dict[str, Any]] = []+ for verdict, rows in fan_out:+ sources.append(verdict)+ merged.extend(rows)++ truncated = False+ if len(merged) > request.limit:+ merged = merged[: request.limit]+ truncated = True++ # Audit (best-effort: a logging failure shouldn't fail the search).+ try:+ db.add(+ _audit_event(+ tenant_id=current_user.tenant_id,+ actor_id=current_user.user_id,+ actor_email=current_user.email,+ indicator_fields=[i.field for i in request.indicators],+ sources=sources,+ row_count=len(merged),+ since_seconds=request.since_seconds,+ )+ )+ await db.commit()+ except Exception:+ logger.exception("federated.search.audit_log_failed tenant=%s", current_user.tenant_id)+ await db.rollback()++ logger.info(+ "federated.search.completed tenant=%s sources=%d rows=%d truncated=%s",+ current_user.tenant_id,+ len(sources),+ len(merged),+ truncated,+ )+ return FederatedSearchResponse(+ rows=merged,+ row_count=len(merged),+ sources=sources,+ truncated=truncated,+ )diff --git a/services/api/app/api/v1/endpoints/sla.py b/services/api/app/api/v1/endpoints/sla.pyindex 0a407e5d5..697396fe8 100644--- a/services/api/app/api/v1/endpoints/sla.py+++ b/services/api/app/api/v1/endpoints/sla.py@@ -1,9 +1,11 @@"""SLA tracking API endpoints.-GET /api/v1/sla/metrics — Aggregated MTTD/MTTR/MTTC metrics-GET /api/v1/sla/config — Current per-severity SLA targets-PUT /api/v1/sla/config/{severity} — Update SLA target for a severity-POST /api/v1/sla/events — Record a lifecycle event for an alert+GET /api/v1/sla/metrics — Aggregated MTTD/MTTR/MTTC metrics (+ optional 2026 KPI bar)+GET /api/v1/sla/config — Current per-severity SLA targets+PUT /api/v1/sla/config/{severity} — Update SLA target for a severity+GET /api/v1/sla/kpi-targets — Tenant 2026 KPI bar targets (defaults + overrides)+PUT /api/v1/sla/kpi-targets — Patch KPI bar targets (deep-merge ``kpi_bar`` in tenant settings)+POST /api/v1/sla/events — Record a lifecycle event for an alert"""from __future__ import annotations@@ -17,9 +19,10 @@ from pydantic import BaseModel, Fieldfrom sqlalchemy import selectfrom app.api.v1.deps import AuthUser, require_permission+from app.core.config import get_settingsfrom app.db.rls import TenantDBSessionfrom app.models.sla import AlertSLAEvent, TenantSLAConfig-from app.services.sla import compute_sla_metrics+from app.services import sla as sla_servicerouter = APIRouter(prefix="/sla", tags=["sla"])@@ -70,6 +73,20 @@ class SLAEventOut(BaseModel):from_attributes = True+class KpiBarTargetsOut(BaseModel):+ false_positive_rate_max_pct: float = Field(..., ge=0, le=100)+ alert_to_incident_ratio_min: float = Field(..., ge=1)+ mitre_technique_tagging_min_pct: float = Field(..., ge=0, le=100)+ mitre_subtechnique_tagging_min_pct: float = Field(..., ge=0, le=100)+++class KpiBarTargetsUpdate(BaseModel):+ false_positive_rate_max_pct: float | None = Field(default=None, ge=0, le=100)+ alert_to_incident_ratio_min: float | None = Field(default=None, ge=1)+ mitre_technique_tagging_min_pct: float | None = Field(default=None, ge=0, le=100)+ mitre_subtechnique_tagging_min_pct: float | None = Field(default=None, ge=0, le=100)++# ---------------------------------------------------------------------------# Endpoints# ---------------------------------------------------------------------------@@ -82,7 +99,39 @@ async def get_sla_metrics(days: int = Query(default=30, ge=1, le=365, description="Look-back window in days"),):"""Return aggregated MTTD / MTTR / MTTC metrics for the tenant."""- return await compute_sla_metrics(db, current_user.tenant_id, days=days)+ return await sla_service.compute_sla_metrics(db, current_user.tenant_id, days=days)+++def _require_kpi_bar_feature() -> None:+ if not get_settings().AISOC_FEATURE_KPI_BAR:+ raise HTTPException(status_code=404, detail="2026 KPI bar feature is disabled")++[email protected]("/kpi-targets", response_model=KpiBarTargetsOut)+async def get_kpi_bar_targets(+ current_user: Annotated[AuthUser, Depends(require_permission("sla:read"))],+ db: TenantDBSession,+) -> KpiBarTargetsOut:+ """Return merged 2026 KPI bar targets (published defaults plus tenant ``settings.kpi_bar``)."""+ _require_kpi_bar_feature()+ merged = await sla_service.load_kpi_bar_targets(db, current_user.tenant_id)+ return KpiBarTargetsOut.model_validate(merged)++[email protected]("/kpi-targets", response_model=KpiBarTargetsOut)+async def put_kpi_bar_targets(+ body: KpiBarTargetsUpdate,+ current_user: Annotated[AuthUser, Depends(require_permission("sla:write"))],+ db: TenantDBSession,+) -> KpiBarTargetsOut:+ """Patch tenant KPI bar targets; unspecified fields keep previous values."""+ _require_kpi_bar_feature()+ patch = {k: float(v) for k, v in body.model_dump(exclude_unset=True).items() if v is not None}+ try:+ merged = await sla_service.patch_tenant_kpi_bar_targets(db, current_user.tenant_id, patch)+ except ValueError:+ raise HTTPException(status_code=404, detail="Tenant not found") from None+ return KpiBarTargetsOut.model_validate(merged)@router.get("/config", response_model=list[SLAConfigOut])diff --git a/services/api/app/api/v1/router.py b/services/api/app/api/v1/router.pyindex 3722fa16a..cddeb46ba 100644--- a/services/api/app/api/v1/router.py+++ b/services/api/app/api/v1/router.py@@ -12,7 +12,9 @@ from app.api.v1.endpoints import (community,compliance,connectors,+ detection_proposals,detection_rules,+ federated,graph,investigations,marketplace,@@ -35,6 +37,8 @@ api_router.include_router(cases.router)api_router.include_router(connectors.router)api_router.include_router(tenants.router)api_router.include_router(detection_rules.router)+api_router.include_router(detection_proposals.router)+api_router.include_router(federated.router)api_router.include_router(graph.router)api_router.include_router(playbooks.router)api_router.include_router(plugins.router)diff --git a/services/api/app/core/config.py b/services/api/app/core/config.pyindex 47b22eb7b..799cd15b6 100644--- a/services/api/app/core/config.py+++ b/services/api/app/core/config.py@@ -197,6 +197,42 @@ class Settings(BaseSettings):AISOC_DISABLE_NEO4J: bool = FalseAISOC_DISABLE_QDRANT: bool = False+ # ------------------------------------------------------------------+ # v6 capability flags (AiSOC v6 capability roadmap).+ # Every capability ships behind a flag so operators can stage rollout.+ # All default to True in development; production deployments can pin+ # individual flags via env vars (e.g. ``AISOC_FEATURE_RBA=false``).+ # ------------------------------------------------------------------+ # Wave 1 — close 2026 table-stakes+ AISOC_FEATURE_RBA: bool = True # Risk-Based Alerting + entity rollup+ AISOC_FEATURE_CONFIDENCE: bool = True # Detection confidence + explainability+ AISOC_FEATURE_CHATOPS_VERIFY: bool = True # Slack/Teams interactive user verification+ AISOC_FEATURE_DETECTION_DRIFT: bool = True # Weekly purple-team drift sweep+ AISOC_FEATURE_KPI_BAR: bool = True # 2026 KPI bar in SLA dashboard++ # Wave 2 — eval-graded differentiation+ AISOC_FEATURE_DAC: bool = True # Detection-as-code lifecycle+ AISOC_FEATURE_HUNT_AS_CODE: bool = True # YAML hunt corpus + scheduler+ AISOC_FEATURE_BENCHMARK_PUBLIC: bool = True # Public scoreboard+ AISOC_FEATURE_AIVAI_EVAL: bool = True # AI-vs-AI adversary suite++ # Wave 3 — operational maturity+ AISOC_FEATURE_FED_SEARCH: bool = True # Federated SIEM search+ AISOC_FEATURE_MSSP: bool = True # Parent-tenant console+ AISOC_FEATURE_ASSET_INVENTORY: bool = True # Asset table + KEV/EPSS+ AISOC_FEATURE_INSIDER_THREAT: bool = True # Insider-threat module+ AISOC_FEATURE_REMEDIATION_TIERS: bool = True # L0–L4 maturity tiers++ # Wave 4 — strategic moat+ AISOC_FEATURE_INTERNAL_TI: bool = True # Closed-case IOC extraction+ AISOC_FEATURE_CSPM: bool = True # Cloud security posture+ AISOC_FEATURE_IDENTITY_GRAPH: bool = True # Identity-first correlation graph+ AISOC_FEATURE_BOARD_REPORTS: bool = True # Auto-generated monthly board reports++ # Drift sweep cadence (hours). Used by services/purple-team scheduler when+ # AISOC_FEATURE_DETECTION_DRIFT is True. Defaults to 168h (weekly).+ AISOC_DRIFT_SWEEP_INTERVAL_HOURS: int = 168+@field_validator("CORS_ORIGINS", mode="before")@classmethoddef parse_cors(cls, v: Any) -> list[str]:diff --git a/services/api/app/models/__init__.py b/services/api/app/models/__init__.pyindex 1d70bc72f..04222b275 100644--- a/services/api/app/models/__init__.py+++ b/services/api/app/models/__init__.py@@ -4,6 +4,7 @@ from app.db.database import Basefrom app.models.alert import Alertfrom app.models.case import Case, CaseTask, CaseTimelinefrom app.models.connector import Connector+from app.models.detection_proposal import DetectionEvalBaseline, DetectionRuleProposalfrom app.models.detection_rule import DetectionRulefrom app.models.investigation import (InvestigationArtifact,@@ -29,6 +30,8 @@ __all__ = ["CaseTimeline","Connector","DetectionRule",+ "DetectionRuleProposal",+ "DetectionEvalBaseline","InvestigationRun","InvestigationEvent","InvestigationArtifact",diff --git a/services/api/app/models/compliance.py b/services/api/app/models/compliance.pyindex 952accb4a..e7b3e5fbe 100644--- a/services/api/app/models/compliance.py+++ b/services/api/app/models/compliance.py@@ -10,7 +10,6 @@ from sqlalchemy.types import TIMESTAMPfrom app.db.database import Base-# Aliased for readability; on Postgres this renders as TIMESTAMPTZ.# (The PG dialect never exported a `TIMESTAMPTZ` symbol — that's just SQL# syntax. The correct way to get a tz-aware column is `TIMESTAMP(timezone=True)`.)diff --git a/services/api/app/models/detection_proposal.py b/services/api/app/models/detection_proposal.pynew file mode 100644index 000000000..abcbcfcaa--- /dev/null+++ b/services/api/app/models/detection_proposal.py@@ -0,0 +1,65 @@+"""Detection-as-code proposal + eval baseline ORM models (Wave 2 — w2-dac).++Backs the propose → review → eval-gated → promote workflow that brings+detections under the same CI gate as agent prompts. A proposal owns the+candidate rule body; once promoted it materialises a row in+`detection_rules` and links back via `promoted_rule_id`.+"""++import uuid+from datetime import UTC, datetime++from sqlalchemy import Boolean, DateTime, Float, Integer, String, Text+from sqlalchemy.dialects.postgresql import JSONB, UUID+from sqlalchemy.orm import Mapped, mapped_column++from app.db.database import Base+++class DetectionRuleProposal(Base):+ __tablename__ = "detection_rule_proposals"++ id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)+ tenant_id: Mapped[uuid.UUID | None] = mapped_column(UUID(as_uuid=True), nullable=True, index=True)+ base_rule_id: Mapped[uuid.UUID | None] = mapped_column(UUID(as_uuid=True), nullable=True)+ promoted_rule_id: Mapped[uuid.UUID | None] = mapped_column(UUID(as_uuid=True), nullable=True)++ name: Mapped[str] = mapped_column(String(255), nullable=False)+ description: Mapped[str | None] = mapped_column(Text, nullable=True)+ rule_language: Mapped[str] = mapped_column(String(30), nullable=False)+ rule_body: Mapped[str] = mapped_column(Text, nullable=False)+ category: Mapped[str] = mapped_column(String(100), nullable=False)+ severity: Mapped[str] = mapped_column(String(20), default="medium")+ confidence: Mapped[int] = mapped_column(Integer, default=50)+ mitre_tactics: Mapped[list] = mapped_column(JSONB, default=list)+ mitre_techniques: Mapped[list] = mapped_column(JSONB, default=list)+ tags: Mapped[list] = mapped_column(JSONB, default=list)++ status: Mapped[str] = mapped_column(String(20), default="proposed", index=True)+ eval_result: Mapped[dict] = mapped_column(JSONB, default=dict)+ review_comments: Mapped[list] = mapped_column(JSONB, default=list)++ proposed_by_id: Mapped[uuid.UUID | None] = mapped_column(UUID(as_uuid=True), nullable=True)+ decided_by_id: Mapped[uuid.UUID | None] = mapped_column(UUID(as_uuid=True), nullable=True)+ decision_comment: Mapped[str | None] = mapped_column(Text, nullable=True)+ decided_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)++ created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=lambda: datetime.now(UTC))+ updated_at: Mapped[datetime] = mapped_column(+ DateTime(timezone=True),+ default=lambda: datetime.now(UTC),+ onupdate=lambda: datetime.now(UTC),+ )+++class DetectionEvalBaseline(Base):+ __tablename__ = "detection_eval_baselines"++ id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)+ tenant_id: Mapped[uuid.UUID | None] = mapped_column(UUID(as_uuid=True), nullable=True, index=True)+ suite: Mapped[str] = mapped_column(String(64), nullable=False, index=True)+ score: Mapped[float] = mapped_column(Float, nullable=False)+ payload: Mapped[dict] = mapped_column(JSONB, default=dict)+ is_active: Mapped[bool] = mapped_column(Boolean, default=True)+ recorded_by_id: Mapped[uuid.UUID | None] = mapped_column(UUID(as_uuid=True), nullable=True)+ created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=lambda: datetime.now(UTC))diff --git a/services/api/app/security/credential_vault.py b/services/api/app/security/credential_vault.pyindex 916068afe..54e76d83f 100644--- a/services/api/app/security/credential_vault.py+++ b/services/api/app/security/credential_vault.py@@ -218,7 +218,9 @@ def get_vault() -> CredentialVault:primary = Fernet.generate_key()logger.warning("AISOC_CREDENTIAL_KEY is not set; using ephemeral process-local key. Connector secrets will not survive a restart. "- "Generate a key with `python -c \"from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())\"` and set AISOC_CREDENTIAL_KEY."+ "Generate a key with "+ "`python -c \"from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())\"`"+ " and set AISOC_CREDENTIAL_KEY.")rotation = _split_keys(settings.AISOC_CREDENTIAL_KEY_ROTATION_FROM or "")_vault_singleton = CredentialVault(primary, historical_keys=rotation)diff --git a/services/api/app/services/sla.py b/services/api/app/services/sla.pyindex 529d0ad4d..182fbdde5 100644--- a/services/api/app/services/sla.py+++ b/services/api/app/services/sla.py@@ -8,13 +8,80 @@ per-severity SLA compliance summaries.from __future__ import annotationsimport uuid-from datetime import datetime, timedelta+from datetime import UTC, datetime, timedeltafrom typing import Any-from sqlalchemy import select+from sqlalchemy import Text, func, selectfrom sqlalchemy.ext.asyncio import AsyncSession+from sqlalchemy.orm.attributes import flag_modified+from app.core.config import get_settings+from app.models.alert import Alertfrom app.models.sla import AlertSLAEvent, TenantSLAConfig+from app.models.tenant import Tenant++# 2026 published KPI bar defaults (tenants can override via ``settings.kpi_bar``).+DEFAULT_KPI_BAR_TARGETS: dict[str, float] = {+ "false_positive_rate_max_pct": 5.0,+ "alert_to_incident_ratio_min": 50.0,+ "mitre_technique_tagging_min_pct": 85.0,+ "mitre_subtechnique_tagging_min_pct": 60.0,+}+++def merge_kpi_bar_dict(existing: dict | None, patch: dict[str, float]) -> dict[str, float]:+ """Merge ``patch`` into stored ``kpi_bar`` and coerce to the four known keys + defaults."""+ kb = {**(existing or {}), **patch}+ out = {**DEFAULT_KPI_BAR_TARGETS}+ for k in DEFAULT_KPI_BAR_TARGETS:+ if k in kb:+ try:+ out[k] = float(kb[k])+ except (TypeError, ValueError):+ pass+ return out+++def merge_tenant_settings_patch(existing: dict | None, patch: dict) -> dict:+ """Shallow-merge ``patch`` into tenant ``settings``; deep-merge only ``kpi_bar``."""+ out = dict(existing or {})+ for k, v in patch.items():+ if k == "kpi_bar" and isinstance(v, dict):+ prev = out.get("kpi_bar")+ base = prev if isinstance(prev, dict) else {}+ out["kpi_bar"] = merge_kpi_bar_dict(base, v)+ else:+ out[k] = v+ return out+++async def load_kpi_bar_targets(db: AsyncSession, tenant_id: uuid.UUID) -> dict[str, float]:+ row = await db.execute(select(Tenant.settings).where(Tenant.id == tenant_id))+ raw = row.scalar_one_or_none() or {}+ kb = (raw or {}).get("kpi_bar") if isinstance((raw or {}).get("kpi_bar"), dict) else {}+ return merge_kpi_bar_dict(kb, {})+++async def patch_tenant_kpi_bar_targets(+ db: AsyncSession,+ tenant_id: uuid.UUID,+ patch: dict[str, float],+) -> dict[str, float]:+ """Persist merged KPI bar targets on the tenant row."""+ result = await db.execute(select(Tenant).where(Tenant.id == tenant_id))+ tenant = result.scalar_one_or_none()+ if tenant is None:+ raise ValueError("tenant not found")+ settings = dict(tenant.settings or {})+ prev_bar = settings.get("kpi_bar") if isinstance(settings.get("kpi_bar"), dict) else {}+ merged_bar = merge_kpi_bar_dict(prev_bar, patch)+ settings["kpi_bar"] = merged_bar+ tenant.settings = settings+ tenant.updated_at = datetime.now(UTC)+ flag_modified(tenant, "settings")+ await db.commit()+ return merged_bar+# ---------------------------------------------------------------------------# Internal helpers@@ -79,9 +146,82 @@ def _compute_durations(}-# ----------------------------------------------------------------------------# Public API-# ---------------------------------------------------------------------------+async def _compute_kpi_bar(+ db: AsyncSession,+ tenant_id: uuid.UUID,+ since: datetime,+ targets: dict[str, float],+) -> dict[str, Any]:+ """Aggregate 2026 KPI bar metrics from ``alerts`` for the look-back window."""+ base = Alert.tenant_id == tenant_id, Alert.created_at >= since++ total_r = await db.execute(select(func.count()).select_from(Alert).where(*base))+ total = int(total_r.scalar_one() or 0)++ fp_r = await db.execute(+ select(func.count()).select_from(Alert).where(*base, Alert.status == "fp")+ )+ fp = int(fp_r.scalar_one() or 0)++ cases_r = await db.execute(+ select(func.count(func.distinct(Alert.case_id))).select_from(Alert).where(*base, Alert.case_id.is_not(None))+ )+ distinct_cases = int(cases_r.scalar_one() or 0)++ tagged_r = await db.execute(+ select(func.count())+ .select_from(Alert)+ .where(+ *base,+ func.coalesce(func.jsonb_array_length(Alert.mitre_techniques), 0) > 0,+ )+ )+ tagged = int(tagged_r.scalar_one() or 0)++ sub_r = await db.execute(+ select(func.count())+ .select_from(Alert)+ .where(+ *base,+ func.coalesce(func.jsonb_array_length(Alert.mitre_techniques), 0) > 0,+ Alert.mitre_techniques.cast(Text).like("%.%"),+ )+ )+ sub_tagged = int(sub_r.scalar_one() or 0)++ fp_rate_pct = round(fp / total * 100, 2) if total else 0.0+ if distinct_cases > 0:+ alert_to_incident = round(total / distinct_cases, 2)+ else:+ alert_to_incident = float(total) if total else 0.0++ mitre_tag_pct = round(tagged / total * 100, 2) if total else 0.0+ mitre_sub_pct = round(sub_tagged / total * 100, 2) if total else 0.0++ # Alert-to-incident: only evaluate when there is at least one incident;+ # alerts with zero linked cases are treated as meeting the ratio bar.+ breaches = {+ "false_positive_rate": fp_rate_pct > targets["false_positive_rate_max_pct"],+ "alert_to_incident_ratio": distinct_cases > 0+ and alert_to_incident < targets["alert_to_incident_ratio_min"],+ "mitre_technique_tagging": mitre_tag_pct < targets["mitre_technique_tagging_min_pct"],+ "mitre_subtechnique_tagging": mitre_sub_pct < targets["mitre_subtechnique_tagging_min_pct"],+ }++ return {+ "targets": targets,+ "observed": {+ "total_alerts": total,+ "false_positives": fp,+ "false_positive_rate_pct": fp_rate_pct,+ "distinct_cases": distinct_cases,+ "alert_to_incident_ratio": alert_to_incident,+ "mitre_technique_tagging_pct": mitre_tag_pct,+ "mitre_subtechnique_tagging_pct": mitre_sub_pct,+ },+ "breaches": breaches,+ "breach_count": sum(1 for v in breaches.values() if v),+ }async def compute_sla_metrics(@@ -170,9 +310,15 @@ async def compute_sla_metrics("mttc_avg": round(sum(all_mttc) / len(all_mttc), 1) if all_mttc else None,}- return {+ out: dict[str, Any] = {"period_days": days,"computed_at": datetime.utcnow().isoformat(),"overall": overall,"per_severity": per_severity,}+ if get_settings().AISOC_FEATURE_KPI_BAR:+ kpi_targets = await load_kpi_bar_targets(db, tenant_id)+ out["kpi_bar"] = await _compute_kpi_bar(db, tenant_id, since, kpi_targets)+ else:+ out["kpi_bar"] = None+ return outdiff --git a/services/api/migrations/010_detection_as_code.sql b/services/api/migrations/010_detection_as_code.sqlnew file mode 100644index 000000000..d688c0bfc--- /dev/null+++ b/services/api/migrations/010_detection_as_code.sql@@ -0,0 +1,122 @@+-- AiSOC Detection-as-Code lifecycle migration (Wave 2 — w2-dac)+--+-- Adds the `detection_rule_proposals` table that backs the+-- propose → review → eval-gated → promote flow. Every proposal carries+-- the candidate rule body, MITRE coverage, the eval baseline that will+-- be compared against, and the decision audit trail. When a proposal+-- is promoted it materialises a row in `detection_rules` and links back+-- via `promoted_rule_id` so the catalog UI can render lineage.+--+-- Multi-tenant RLS is applied: each tenant only sees its own proposals.+-- Platform-wide proposals (tenant_id IS NULL) are visible to operators+-- with the platform role and are how built-in detections get reviewed.++-- ============================================================+-- detection_rule_proposals+-- ============================================================+CREATE TABLE IF NOT EXISTS detection_rule_proposals (+ id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),+ tenant_id UUID REFERENCES tenants(id) ON DELETE CASCADE,+ -- Optional pointer to an existing rule when the proposal is an edit.+ base_rule_id UUID REFERENCES detection_rules(id) ON DELETE SET NULL,+ -- Materialised rule once the proposal is promoted.+ promoted_rule_id UUID REFERENCES detection_rules(id) ON DELETE SET NULL,++ -- Rule definition (uses the same naming convention as the ORM model).+ name VARCHAR(255) NOT NULL,+ description TEXT,+ rule_language VARCHAR(30) NOT NULL,+ rule_body TEXT NOT NULL,+ category VARCHAR(100) NOT NULL,+ severity VARCHAR(20) NOT NULL DEFAULT 'medium',+ confidence INTEGER NOT NULL DEFAULT 50,+ mitre_tactics JSONB NOT NULL DEFAULT '[]'::jsonb,+ mitre_techniques JSONB NOT NULL DEFAULT '[]'::jsonb,+ tags JSONB NOT NULL DEFAULT '[]'::jsonb,++ -- Lifecycle: proposed → in_review → eval_passed | eval_failed → promoted | rejected.+ status VARCHAR(20) NOT NULL DEFAULT 'proposed',+ -- The most recent eval result so the UI can render gate verdicts+ -- without re-running the suite. Shape:+ -- {"baseline": {...}, "candidate": {...}, "delta_pp": -1.2, "passed": false, "ran_at": "..."}+ eval_result JSONB NOT NULL DEFAULT '{}'::jsonb,+ -- Free-form review thread. Shape: [{"actor_id": "...", "comment": "...", "at": "..."}].+ review_comments JSONB NOT NULL DEFAULT '[]'::jsonb,++ -- Authoring + decision audit trail.+ proposed_by_id UUID REFERENCES users(id) ON DELETE SET NULL,+ decided_by_id UUID REFERENCES users(id) ON DELETE SET NULL,+ decision_comment TEXT,+ decided_at TIMESTAMPTZ,++ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),+ updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()+);++CREATE INDEX IF NOT EXISTS idx_detection_proposals_tenant+ ON detection_rule_proposals(tenant_id);+CREATE INDEX IF NOT EXISTS idx_detection_proposals_status+ ON detection_rule_proposals(status);+CREATE INDEX IF NOT EXISTS idx_detection_proposals_base+ ON detection_rule_proposals(base_rule_id)+ WHERE base_rule_id IS NOT NULL;++ALTER TABLE detection_rule_proposals ENABLE ROW LEVEL SECURITY;+ALTER TABLE detection_rule_proposals FORCE ROW LEVEL SECURITY;+DROP POLICY IF EXISTS detection_proposals_tenant ON detection_rule_proposals;+CREATE POLICY detection_proposals_tenant ON detection_rule_proposals+ USING (+ tenant_id = current_tenant_id()+ OR tenant_id IS NULL+ OR current_tenant_id() IS NULL+ );++-- updated_at touch trigger (mirrors the agent_approvals pattern).+CREATE OR REPLACE FUNCTION detection_proposals_touch_updated()+RETURNS TRIGGER LANGUAGE plpgsql AS $$+BEGIN+ NEW.updated_at = NOW();+ RETURN NEW;+END;+$$;++DROP TRIGGER IF EXISTS trg_detection_proposals_touch ON detection_rule_proposals;+CREATE TRIGGER trg_detection_proposals_touch+ BEFORE UPDATE ON detection_rule_proposals+ FOR EACH ROW EXECUTE FUNCTION detection_proposals_touch_updated();++-- ============================================================+-- detection_eval_baselines+-- ============================================================+-- Stores the snapshot of MITRE accuracy / alert reduction / completeness+-- / response_quality the gate compares candidate proposals against.+-- A new baseline row is written by `scripts/run_evals.py --record-baseline`+-- and the latest active row per tenant (NULL = platform) is what the+-- gating endpoint reads.++CREATE TABLE IF NOT EXISTS detection_eval_baselines (+ id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),+ tenant_id UUID REFERENCES tenants(id) ON DELETE CASCADE,+ -- Eval suite this baseline scopes (mitre_accuracy, alert_reduction, ...).+ suite VARCHAR(64) NOT NULL,+ -- Aggregate score (e.g. 0.823 for 82.3 % MITRE accuracy).+ score DOUBLE PRECISION NOT NULL,+ -- Full eval result for diffing — same shape produced by run_evals.py.+ payload JSONB NOT NULL DEFAULT '{}'::jsonb,+ is_active BOOLEAN NOT NULL DEFAULT TRUE,+ recorded_by_id UUID REFERENCES users(id) ON DELETE SET NULL,+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()+);++CREATE INDEX IF NOT EXISTS idx_eval_baselines_tenant_suite+ ON detection_eval_baselines(tenant_id, suite, is_active);++ALTER TABLE detection_eval_baselines ENABLE ROW LEVEL SECURITY;+ALTER TABLE detection_eval_baselines FORCE ROW LEVEL SECURITY;+DROP POLICY IF EXISTS eval_baselines_tenant ON detection_eval_baselines;+CREATE POLICY eval_baselines_tenant ON detection_eval_baselines+ USING (+ tenant_id = current_tenant_id()+ OR tenant_id IS NULL+ OR current_tenant_id() IS NULL+ );diff --git a/services/api/migrations/011_hunt_as_code.sql b/services/api/migrations/011_hunt_as_code.sqlnew file mode 100644index 000000000..32dcfb63b--- /dev/null+++ b/services/api/migrations/011_hunt_as_code.sql@@ -0,0 +1,170 @@+-- AiSOC Hunt-as-code migration (Wave 2 — w2-hac)+-- Stores the catalog of registered hunt hypotheses (loaded from the YAML+-- corpus in `hunts/`) plus first-class artifacts for every hunt run and+-- finding so they sit alongside the Investigation Ledger as queryable,+-- replayable evidence.+--+-- Tables:+-- hunt_hypotheses — one row per loaded YAML hunt (catalog)+-- hunt_runs — one row per scheduled execution of a hunt+-- hunt_findings — first-class artifacts emitted by a hunt run+--+-- All three tables enforce tenant isolation via Row-Level Security so+-- hunts that fire are scoped to a tenant the same way alerts and cases are.++-- ============================================================+-- 1. hunt_hypotheses (catalog)+-- ============================================================+CREATE TABLE IF NOT EXISTS hunt_hypotheses (+ id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),+ tenant_id UUID REFERENCES tenants(id) ON DELETE CASCADE,+ -- ``hunt_id`` is the slug from the YAML (e.g. "hunt-svc-account-after-hours").+ -- Unique per tenant so each tenant can override the corpus version.+ hunt_id VARCHAR(200) NOT NULL,+ name VARCHAR(300) NOT NULL,+ description TEXT,+ version VARCHAR(40) NOT NULL DEFAULT '1.0.0',+ severity VARCHAR(20) NOT NULL DEFAULT 'medium',+ category VARCHAR(40) NOT NULL DEFAULT 'other',+ tags TEXT[] NOT NULL DEFAULT '{}',+ log_sources TEXT[] NOT NULL DEFAULT '{}',+ schedule_enabled BOOLEAN NOT NULL DEFAULT TRUE,+ interval_minutes INTEGER NOT NULL DEFAULT 60,+ jitter_seconds INTEGER NOT NULL DEFAULT 60,+ hypothesis JSONB NOT NULL DEFAULT '{}'::jsonb,+ expected JSONB NOT NULL DEFAULT '{}'::jsonb,+ -- ``refs`` (renamed from "references" because that is a reserved word+ -- in PostgreSQL): list of URLs / docs the hunt cites.+ refs TEXT[] NOT NULL DEFAULT '{}',+ author VARCHAR(120),+ -- Hash of the YAML body — lets the loader detect when a hunt has changed.+ source_sha256 VARCHAR(64),+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),+ updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),+ UNIQUE (tenant_id, hunt_id)+);++CREATE INDEX IF NOT EXISTS idx_hunt_hyp_tenant ON hunt_hypotheses(tenant_id);+CREATE INDEX IF NOT EXISTS idx_hunt_hyp_category ON hunt_hypotheses(category);+CREATE INDEX IF NOT EXISTS idx_hunt_hyp_enabled ON hunt_hypotheses(schedule_enabled);++ALTER TABLE hunt_hypotheses ENABLE ROW LEVEL SECURITY;+ALTER TABLE hunt_hypotheses FORCE ROW LEVEL SECURITY;+DROP POLICY IF EXISTS hunt_hyp_tenant ON hunt_hypotheses;+CREATE POLICY hunt_hyp_tenant ON hunt_hypotheses+ USING (+ tenant_id = current_tenant_id()+ OR tenant_id IS NULL+ OR current_tenant_id() IS NULL+ );++CREATE OR REPLACE FUNCTION hunt_hypotheses_touch_updated()+RETURNS TRIGGER LANGUAGE plpgsql AS $$+BEGIN+ NEW.updated_at = NOW();+ RETURN NEW;+END;+$$;++DROP TRIGGER IF EXISTS trg_hunt_hyp_touch ON hunt_hypotheses;+CREATE TRIGGER trg_hunt_hyp_touch+ BEFORE UPDATE ON hunt_hypotheses+ FOR EACH ROW EXECUTE FUNCTION hunt_hypotheses_touch_updated();++-- ============================================================+-- 2. hunt_runs+-- ============================================================+CREATE TABLE IF NOT EXISTS hunt_runs (+ id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),+ tenant_id UUID NOT NULL REFERENCES tenants(id) ON DELETE CASCADE,+ -- references hunt_hypotheses.hunt_id (logical FK only, by slug)+ hunt_id VARCHAR(200) NOT NULL,+ hypothesis_id UUID REFERENCES hunt_hypotheses(id) ON DELETE SET NULL,+ -- Trigger source: scheduler|manual|backtest|ci-eval+ trigger_source VARCHAR(40) NOT NULL DEFAULT 'scheduler',+ -- running|completed|failed|skipped+ status VARCHAR(20) NOT NULL DEFAULT 'running',+ -- How many synthetic events the hunt looked at (input window)+ events_scanned INTEGER NOT NULL DEFAULT 0,+ -- How many findings the hunt emitted (rows in hunt_findings for this run)+ findings_count INTEGER NOT NULL DEFAULT 0,+ -- Aggregate match score for telemetry; range 0.0–1.0+ match_score NUMERIC(4,3) NOT NULL DEFAULT 0.0,+ error TEXT,+ started_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),+ completed_at TIMESTAMPTZ,+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()+);++CREATE INDEX IF NOT EXISTS idx_hunt_runs_tenant_started ON hunt_runs(tenant_id, started_at DESC);+CREATE INDEX IF NOT EXISTS idx_hunt_runs_hunt_id ON hunt_runs(hunt_id);+CREATE INDEX IF NOT EXISTS idx_hunt_runs_status ON hunt_runs(status);++ALTER TABLE hunt_runs ENABLE ROW LEVEL SECURITY;+ALTER TABLE hunt_runs FORCE ROW LEVEL SECURITY;+DROP POLICY IF EXISTS hunt_runs_tenant ON hunt_runs;+CREATE POLICY hunt_runs_tenant ON hunt_runs+ USING (+ tenant_id = current_tenant_id()+ OR current_tenant_id() IS NULL+ );++-- ============================================================+-- 3. hunt_findings (first-class artifacts)+-- ============================================================+CREATE TABLE IF NOT EXISTS hunt_findings (+ id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),+ tenant_id UUID NOT NULL REFERENCES tenants(id) ON DELETE CASCADE,+ hunt_run_id UUID NOT NULL REFERENCES hunt_runs(id) ON DELETE CASCADE,+ hunt_id VARCHAR(200) NOT NULL,+ severity VARCHAR(20) NOT NULL DEFAULT 'medium',+ -- Optional human-readable title; falls back to the hunt name if NULL.+ title TEXT,+ -- Free-form summary of what this finding is asserting.+ summary TEXT,+ -- The raw evidence: list of matched events (telemetry rows) plus indicator+ -- breakdown, indexed by indicator name.+ evidence JSONB NOT NULL DEFAULT '{}'::jsonb,+ -- Subset of fields lifted out for indexing / quick filters in the UI.+ primary_entity VARCHAR(200),+ primary_log_source VARCHAR(80),+ -- Match score for this finding specifically (range 0.0–1.0).+ match_score NUMERIC(4,3) NOT NULL DEFAULT 0.0,+ -- ATT&CK technique IDs (e.g. "T1078.002") so we can roll up to coverage.+ mitre_techniques TEXT[] NOT NULL DEFAULT '{}',+ -- open|triaged|promoted|dismissed+ status VARCHAR(20) NOT NULL DEFAULT 'open',+ promoted_alert_id UUID,+ promoted_case_id UUID,+ notes TEXT,+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),+ updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()+);++CREATE INDEX IF NOT EXISTS idx_hunt_findings_tenant_created ON hunt_findings(tenant_id, created_at DESC);+CREATE INDEX IF NOT EXISTS idx_hunt_findings_hunt_id ON hunt_findings(hunt_id);+CREATE INDEX IF NOT EXISTS idx_hunt_findings_run ON hunt_findings(hunt_run_id);+CREATE INDEX IF NOT EXISTS idx_hunt_findings_status ON hunt_findings(status);+CREATE INDEX IF NOT EXISTS idx_hunt_findings_severity ON hunt_findings(severity);++ALTER TABLE hunt_findings ENABLE ROW LEVEL SECURITY;+ALTER TABLE hunt_findings FORCE ROW LEVEL SECURITY;+DROP POLICY IF EXISTS hunt_findings_tenant ON hunt_findings;+CREATE POLICY hunt_findings_tenant ON hunt_findings+ USING (+ tenant_id = current_tenant_id()+ OR current_tenant_id() IS NULL+ );++CREATE OR REPLACE FUNCTION hunt_findings_touch_updated()+RETURNS TRIGGER LANGUAGE plpgsql AS $$+BEGIN+ NEW.updated_at = NOW();+ RETURN NEW;+END;+$$;++DROP TRIGGER IF EXISTS trg_hunt_findings_touch ON hunt_findings;+CREATE TRIGGER trg_hunt_findings_touch+ BEFORE UPDATE ON hunt_findings+ FOR EACH ROW EXECUTE FUNCTION hunt_findings_touch_updated();diff --git a/services/api/tests/test_credential_vault.py b/services/api/tests/test_credential_vault.pyindex bfaf55406..1fd12b9e8 100644--- a/services/api/tests/test_credential_vault.py+++ b/services/api/tests/test_credential_vault.py@@ -8,13 +8,12 @@ process env vars or the order other test modules import settings in.from __future__ import annotationsimport pytest-from cryptography.fernet import Fernet-from app.security.credential_vault import (+ _CIPHER_PREFIX,CredentialVault,CredentialVaultError,- _CIPHER_PREFIX,)+from cryptography.fernet import Fernet@pytest.fixturediff --git a/services/api/tests/test_federated_endpoint.py b/services/api/tests/test_federated_endpoint.pynew file mode 100644index 000000000..41c3f0d74--- /dev/null+++ b/services/api/tests/test_federated_endpoint.py@@ -0,0 +1,462 @@+"""Unit tests for the federated search API helpers.++The federated search endpoint is the API-side half of the ``w3-fed``+capability. Like ``test_connectors_endpoint``, we stay below the FastAPI+layer here — the endpoint's interesting logic lives in three helpers+that are pure-async and trivially mockable:++* ``_query_one_backend`` — decrypts creds via the vault, POSTs to the+ connectors microservice, and tags rows. Must never raise; instead it+ returns a per-source verdict so a single bad SIEM can't poison the+ merged response.+* ``_audit_event`` — builds the immutable audit row. We assert that+ indicator *values* never enter ``metadata_`` (a federated query may+ contain regulated identifiers; the audit log is tenant-shared).+* ``_connectors_query_url`` / ``_ensure_feature_enabled`` — small+ utilities, but they hold the URL contract with the connectors+ microservice and the feature-flag gate respectively.++We mock ``httpx.AsyncClient`` and the credential vault directly. Spinning+up a real DB / auth stack would add nothing — the proxy-and-merge layer+is already characterised by these unit tests, and the rest of the+endpoint is FastAPI dependency injection.+"""++from __future__ import annotations++import uuid+from typing import Any+from unittest.mock import AsyncMock, MagicMock, patch++import httpx+import pytest+from app.api.v1.endpoints.federated import (+ SourceVerdict,+ _audit_event,+ _connectors_query_url,+ _ensure_feature_enabled,+ _query_one_backend,+)+from app.models.connector import Connector+from app.security.credential_vault import CredentialVaultError+from fastapi import HTTPException++# ---------------------------------------------------------------- fixtures+++def _make_connector(+ *,+ connector_type: str = "splunk",+ name: str = "Prod Splunk",+ auth_config: dict[str, Any] | None = None,+ connector_config: dict[str, Any] | None = None,+) -> Connector:+ """Build a ``Connector`` instance without touching the database.++ SQLAlchemy lets us instantiate ORM objects with kwargs and pass them+ around as plain Python objects so long as we never call ``flush`` /+ ``commit``. That's exactly what we want here — the helper under test+ only reads attributes.+ """+ return Connector(+ id=uuid.uuid4(),+ tenant_id=uuid.uuid4(),+ name=name,+ connector_type=connector_type,+ category="siem",+ is_enabled=True,+ auth_config=auth_config or {"token": "vault:v1:abc"},+ connector_config=connector_config or {"base_url": "https://splunk.example.com"},+ health_status="healthy",+ )+++def _mock_response(status_code: int, json_body: Any, *, content: bytes | None = None) -> MagicMock:+ """Build a MagicMock that quacks like an httpx.Response."""+ resp = MagicMock(spec=httpx.Response)+ resp.status_code = status_code+ resp.json = MagicMock(return_value=json_body)+ resp.text = str(json_body) if not isinstance(json_body, str) else json_body+ # ``content`` controls the ``if resp.content`` truthiness branch.+ resp.content = content if content is not None else b'{"rows": []}'+ return resp+++def _patched_post(post_resp: MagicMock | Exception):+ """Patch ``httpx.AsyncClient`` so its async ``post`` returns/raises as configured."""+ client_instance = MagicMock()+ if isinstance(post_resp, Exception):+ client_instance.post = AsyncMock(side_effect=post_resp)+ else:+ client_instance.post = AsyncMock(return_value=post_resp)+ client_cm = MagicMock()+ client_cm.__aenter__ = AsyncMock(return_value=client_instance)+ client_cm.__aexit__ = AsyncMock(return_value=None)+ return patch(+ "app.api.v1.endpoints.federated.httpx.AsyncClient",+ return_value=client_cm,+ )+++def _patched_vault(decrypt_return: dict[str, Any] | None = None, *, raises: Exception | None = None):+ """Patch the credential vault so ``decrypt_dict`` is hermetic."""+ vault = MagicMock()+ if raises is not None:+ vault.decrypt_dict = MagicMock(side_effect=raises)+ else:+ vault.decrypt_dict = MagicMock(return_value=decrypt_return or {})+ return patch("app.api.v1.endpoints.federated.get_vault", return_value=vault)+++# ----------------------------------------------------- _connectors_query_url+++def test_connectors_query_url_uses_v1_prefix() -> None:+ """The connectors microservice mounts its router under ``/api/v1``;+ the federated endpoint must hit that exact path."""+ url = _connectors_query_url("splunk")+ assert url.endswith("/api/v1/connectors/splunk/query")+++def test_connectors_query_url_strips_trailing_slash() -> None:+ """``CONNECTORS_SERVICE_URL`` may or may not end with ``/`` depending on+ how operators set the env var. The helper must normalise it so we never+ emit a double slash that some upstream proxies treat as a 404."""+ with patch("app.api.v1.endpoints.federated.settings") as mock_settings:+ mock_settings.CONNECTORS_SERVICE_URL = "http://connectors:8003/"+ url = _connectors_query_url("microsoft_sentinel")+ assert url == "http://connectors:8003/api/v1/connectors/microsoft_sentinel/query"+++# ---------------------------------------------------- _ensure_feature_enabled+++def test_ensure_feature_enabled_passthrough_when_on() -> None:+ """When the flag is on, the helper is a no-op. Anything else means+ the feature is silently broken."""+ with patch("app.api.v1.endpoints.federated.settings") as mock_settings:+ mock_settings.AISOC_FEATURE_FED_SEARCH = True+ # Should not raise.+ _ensure_feature_enabled()+++def test_ensure_feature_enabled_404s_when_off() -> None:+ """Disabled feature → 404, not 403 or 500. We hide the route entirely+ rather than admitting it exists, which matches how the rest of the+ feature-flagged endpoints behave."""+ with patch("app.api.v1.endpoints.federated.settings") as mock_settings:+ mock_settings.AISOC_FEATURE_FED_SEARCH = False+ with pytest.raises(HTTPException) as exc_info:+ _ensure_feature_enabled()+ assert exc_info.value.status_code == 404+ assert "AISOC_FEATURE_FED_SEARCH" in exc_info.value.detail+++# ---------------------------------------------------------- _query_one_backend+++async def test_query_one_backend_decrypt_failure_returns_error_verdict() -> None:+ """A vault failure must NOT raise — it returns a per-source verdict+ so the rest of the federated answer still gets through."""+ connector = _make_connector()+ with _patched_vault(raises=CredentialVaultError("bad ciphertext")):+ verdict, rows = await _query_one_backend(+ connector,+ query_payload={"free_text": "x"},+ timeout=httpx.Timeout(5.0),+ )+ assert verdict.status == "error"+ assert "credential decryption failed" in (verdict.error or "")+ assert rows == []+++async def test_query_one_backend_unreachable_returns_error_verdict() -> None:+ """Network failure on the connectors microservice → status=error,+ not a raised exception. Other backends get to keep running."""+ connector = _make_connector()+ with (+ _patched_vault(decrypt_return={"token": "plaintext"}),+ _patched_post(httpx.ConnectError("conn refused")),+ ):+ verdict, rows = await _query_one_backend(+ connector,+ query_payload={"free_text": "x"},+ timeout=httpx.Timeout(5.0),+ )+ assert verdict.status == "error"+ assert "unreachable" in (verdict.error or "")+ assert rows == []+++async def test_query_one_backend_501_marked_unsupported() -> None:+ """501 from the connectors microservice means the connector class+ hasn't opted into ``supports_federated_search``. We surface this as+ ``unsupported`` (not ``error``) so the UI can render it differently."""+ connector = _make_connector(connector_type="splunk")+ resp = _mock_response(501, {}, content=b"")+ resp.text = "no federated support"+ with (+ _patched_vault(decrypt_return={"token": "plaintext"}),+ _patched_post(resp),+ ):+ verdict, rows = await _query_one_backend(+ connector,+ query_payload={"free_text": "x"},+ timeout=httpx.Timeout(5.0),+ )+ assert verdict.status == "unsupported"+ assert verdict.error == "no federated support"+ assert rows == []+++async def test_query_one_backend_4xx_surfaces_detail() -> None:+ """A 4xx from the backend (e.g. 401 because creds expired) must come+ back as ``status=error`` carrying the upstream detail, not as a+ generic 500."""+ connector = _make_connector()+ resp = _mock_response(401, {"detail": "invalid token"})+ with (+ _patched_vault(decrypt_return={"token": "expired"}),+ _patched_post(resp),+ ):+ verdict, rows = await _query_one_backend(+ connector,+ query_payload={"free_text": "x"},+ timeout=httpx.Timeout(5.0),+ )+ assert verdict.status == "error"+ assert "401" in (verdict.error or "")+ assert "invalid token" in (verdict.error or "")+ assert rows == []+++async def test_query_one_backend_5xx_surfaces_status() -> None:+ """500 from the backend behaves the same way — ``status=error``,+ other backends still get to run."""+ connector = _make_connector()+ resp = _mock_response(500, {"detail": "splunk indexer down"})+ with (+ _patched_vault(decrypt_return={"token": "ok"}),+ _patched_post(resp),+ ):+ verdict, _ = await _query_one_backend(+ connector,+ query_payload={"free_text": "x"},+ timeout=httpx.Timeout(5.0),+ )+ assert verdict.status == "error"+ assert "500" in (verdict.error or "")+++async def test_query_one_backend_4xx_with_non_json_body_falls_back_to_text() -> None:+ """Some backends return text/html error pages on auth failures.+ The helper must not blow up trying to ``.json()`` such responses."""+ connector = _make_connector()+ resp = _mock_response(403, "<html>Forbidden</html>")+ resp.json = MagicMock(side_effect=ValueError("not json"))+ resp.text = "<html>Forbidden</html>"+ with (+ _patched_vault(decrypt_return={"token": "x"}),+ _patched_post(resp),+ ):+ verdict, _ = await _query_one_backend(+ connector,+ query_payload={"free_text": "x"},+ timeout=httpx.Timeout(5.0),+ )+ assert verdict.status == "error"+ assert "403" in (verdict.error or "")+++async def test_query_one_backend_success_tags_rows_with_source() -> None:+ """The merge step relies on every row carrying its origin so the UI+ can render "Splunk OK · Sentinel timeout · Elastic OK" with row-level+ provenance. Confirm the tag is added to dict rows."""+ connector = _make_connector(name="Prod Splunk", connector_type="splunk")+ upstream_rows = [+ {"_time": "2026-05-05T00:00:00Z", "user": "alice"},+ {"_time": "2026-05-05T00:01:00Z", "user": "bob"},+ ]+ resp = _mock_response(200, {"rows": upstream_rows}, content=b'{"rows": []}')+ with (+ _patched_vault(decrypt_return={"token": "ok"}),+ _patched_post(resp),+ ):+ verdict, rows = await _query_one_backend(+ connector,+ query_payload={"free_text": "x"},+ timeout=httpx.Timeout(5.0),+ )+ assert verdict.status == "ok"+ assert verdict.row_count == 2+ assert len(rows) == 2+ for row in rows:+ assert "_aisoc_source" in row+ assert row["_aisoc_source"]["connector_type"] == "splunk"+ assert row["_aisoc_source"]["connector_name"] == "Prod Splunk"+ assert row["_aisoc_source"]["connector_id"] == str(connector.id)+++async def test_query_one_backend_does_not_overwrite_existing_aisoc_source() -> None:+ """If a SIEM somehow returns a row that already has ``_aisoc_source``+ we keep the original — overwriting silently would mask a real+ upstream bug. ``setdefault`` is the right primitive here."""+ connector = _make_connector()+ pre_tagged = {"existing": True, "_aisoc_source": {"connector_type": "weird"}}+ resp = _mock_response(200, {"rows": [pre_tagged]})+ with (+ _patched_vault(decrypt_return={"token": "ok"}),+ _patched_post(resp),+ ):+ _, rows = await _query_one_backend(+ connector,+ query_payload={"free_text": "x"},+ timeout=httpx.Timeout(5.0),+ )+ assert rows[0]["_aisoc_source"] == {"connector_type": "weird"}+++async def test_query_one_backend_wraps_non_dict_rows() -> None:+ """If the connector returns scalars instead of dicts (a real+ historical Elastic quirk for single-column ES|QL), the merge layer+ needs every row to be a dict so its keys don't blow up downstream+ consumers. The helper wraps non-dict rows in ``{"value": ...}``."""+ connector = _make_connector()+ resp = _mock_response(200, {"rows": ["just-a-string", 42]})+ with (+ _patched_vault(decrypt_return={"token": "ok"}),+ _patched_post(resp),+ ):+ _, rows = await _query_one_backend(+ connector,+ query_payload={"free_text": "x"},+ timeout=httpx.Timeout(5.0),+ )+ assert len(rows) == 2+ assert all(isinstance(r, dict) for r in rows)+ assert rows[0]["value"] == "just-a-string"+ assert rows[1]["value"] == 42+ # Every wrapped row still gets the source tag.+ assert "_aisoc_source" in rows[0]+++async def test_query_one_backend_handles_missing_rows_key() -> None:+ """Defensive: a 200 with a body that omits ``rows`` is treated as zero+ results, not an exception."""+ connector = _make_connector()+ resp = _mock_response(200, {"warnings": ["no data"]})+ with (+ _patched_vault(decrypt_return={"token": "ok"}),+ _patched_post(resp),+ ):+ verdict, rows = await _query_one_backend(+ connector,+ query_payload={"free_text": "x"},+ timeout=httpx.Timeout(5.0),+ )+ assert verdict.status == "ok"+ assert verdict.row_count == 0+ assert rows == []+++async def test_query_one_backend_handles_non_list_rows_field() -> None:+ """If ``rows`` comes back as a string (some misconfigured plugin), we+ treat it as zero rows rather than crashing the iteration."""+ connector = _make_connector()+ resp = _mock_response(200, {"rows": "not-a-list"})+ with (+ _patched_vault(decrypt_return={"token": "ok"}),+ _patched_post(resp),+ ):+ verdict, rows = await _query_one_backend(+ connector,+ query_payload={"free_text": "x"},+ timeout=httpx.Timeout(5.0),+ )+ assert verdict.status == "ok"+ assert rows == []+++# ----------------------------------------------------------------- _audit_event+++def test_audit_event_records_only_field_names_not_values() -> None:+ """A federated query against a customer's SIEM may contain regulated+ identifiers in the indicator values (e.g. an email, a username, a+ hash). The audit log is tenant-shared — we record the *shape* of the+ query, never the values themselves."""+ tenant_id = uuid.uuid4()+ actor_id = uuid.uuid4()+ sources = [+ SourceVerdict(+ connector_id=uuid.uuid4(),+ connector_name="Prod Splunk",+ connector_type="splunk",+ status="ok",+ row_count=5,+ duration_ms=42,+ ),+ SourceVerdict(+ connector_id=uuid.uuid4(),+ connector_name="Prod Sentinel",+ connector_type="microsoft_sentinel",+ status="error",+ row_count=0,+ duration_ms=11,+ error="401 Unauthorized",+ ),+ ]++ event = _audit_event(+ tenant_id=tenant_id,+ actor_id=actor_id,+ actor_email="[email protected]",+ indicator_fields=["user.name", "src_ip"],+ sources=sources,+ row_count=5,+ since_seconds=3600,+ )++ assert event.action == "federated_search"+ assert event.resource == "federated"+ assert event.tenant_id == tenant_id+ assert event.actor_id == actor_id++ # Only field names are recorded; values would be a privacy leak.+ assert event.metadata_["indicator_fields"] == ["user.name", "src_ip"]+ assert event.metadata_["since_seconds"] == 3600+ assert event.metadata_["row_count"] == 5+ assert len(event.metadata_["sources"]) == 2+ # Verdict shape carries through intact.+ assert event.metadata_["sources"][0]["connector_type"] == "splunk"+ assert event.metadata_["sources"][0]["status"] == "ok"+ assert event.metadata_["sources"][1]["status"] == "error"+++def test_audit_event_handles_empty_indicator_list() -> None:+ """A pure free-text federated query is still valid; the audit row+ must not blow up on an empty ``indicator_fields`` list."""+ event = _audit_event(+ tenant_id=uuid.uuid4(),+ actor_id=None,+ actor_email=None,+ indicator_fields=[],+ sources=[],+ row_count=0,+ since_seconds=600,+ )+ assert event.metadata_["indicator_fields"] == []+ assert event.metadata_["sources"] == []+ assert event.actor_id is None+ assert event.actor_email is Nonediff --git a/services/connectors/app/api/router.py b/services/connectors/app/api/router.pyindex 4e544e3f1..8df4e2777 100644--- a/services/connectors/app/api/router.py+++ b/services/connectors/app/api/router.py@@ -29,9 +29,11 @@ from typing import Anyimport structlogfrom fastapi import APIRouter, HTTPException, status-from pydantic import BaseModel, Field as PydField+from pydantic import BaseModel+from pydantic import Field as PydFieldfrom app.connectors import CONNECTOR_REGISTRY, list_connector_schemas+from app.federated.query import QueryError, parse_unified_querylogger = structlog.get_logger()router = APIRouter()@@ -56,6 +58,22 @@ class TestConnectionRequest(BaseModel):)+class FederatedQueryRequest(BaseModel):+ """Run a unified query against a single connector instance.++ Same trust model as ``TestConnectionRequest``: the API service+ decrypts ``auth_config`` before forwarding here. ``query`` is the+ JSON-shaped ``UnifiedQuery`` (see ``app.federated.query``).+ """++ auth_config: dict[str, Any] = PydField(default_factory=dict)+ connector_config: dict[str, Any] = PydField(default_factory=dict)+ query: dict[str, Any] = PydField(+ ...,+ description="UnifiedQuery payload: free_text, indicators[], since_seconds, limit.",+ )++@router.get("/connectors")async def list_connectors():"""List every connector registered with this build."""@@ -155,6 +173,68 @@ async def test_connector_connection(connector_id: str, payload: TestConnectionRereturn result[email protected]("/connectors/{connector_id}/query")+async def run_federated_query(connector_id: str, payload: FederatedQueryRequest):+ """Translate a ``UnifiedQuery`` and run it against the connector's backend.++ Trust boundary mirrors ``/connectors/{id}/test``: the API service has+ already decrypted ``auth_config`` against the credential vault before+ we see it, and the connector instance lives only for the duration of+ this request — we never persist credentials in the connectors+ microservice.++ Connectors that haven't opted into federated search return 501 via+ the ``NotImplementedError`` raised by ``BaseConnector.query``'s+ default. Translation failures (un-translatable operator, malformed+ payload) become 422 so the API layer can surface the offending field.+ """+ cls = CONNECTOR_REGISTRY.get(connector_id)+ if cls is None:+ raise HTTPException(status_code=404, detail=f"Connector '{connector_id}' not found")++ if not getattr(cls, "supports_federated_search", False):+ raise HTTPException(+ status_code=status.HTTP_501_NOT_IMPLEMENTED,+ detail=f"connector '{connector_id}' does not support federated search",+ )++ try:+ unified = parse_unified_query(payload.query)+ except QueryError as exc:+ raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=str(exc)) from exc++ kwargs = {**payload.auth_config, **payload.connector_config}+ try:+ connector = cls(**kwargs)+ except TypeError as exc:+ raise HTTPException(+ status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,+ detail=f"connector config does not match schema: {exc}",+ ) from exc++ try:+ rows = await connector.query(unified)+ except NotImplementedError as exc:+ # Defensive: a connector class can advertise supports_federated_search+ # but a future refactor could leave query() unimplemented. Map to+ # the same 501 we'd return up top.+ raise HTTPException(status_code=status.HTTP_501_NOT_IMPLEMENTED, detail=str(exc)) from exc+ except QueryError as exc:+ raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=str(exc)) from exc+ except Exception as exc:+ logger.exception("connector.query.runtime_error", connector_id=connector_id)+ raise HTTPException(+ status_code=status.HTTP_502_BAD_GATEWAY,+ detail=f"backend query failed: {exc}",+ ) from exc++ return {+ "connector_id": connector_id,+ "row_count": len(rows),+ "rows": rows,+ }++@router.get("/health")async def health():return {"status": "healthy", "service": "aisoc-connectors"}diff --git a/services/connectors/app/connectors/__init__.py b/services/connectors/app/connectors/__init__.pyindex b25cfecc8..d2db8e02b 100644--- a/services/connectors/app/connectors/__init__.py+++ b/services/connectors/app/connectors/__init__.py@@ -23,6 +23,7 @@ from app.connectors.azure_entra import AzureEntraConnectorfrom app.connectors.base import BaseConnector, ConnectorSchema, Field, OAuthHintsfrom app.connectors.cloudflare import CloudflareConnectorfrom app.connectors.crowdstrike import CrowdStrikeConnector+from app.connectors.elastic import ElasticConnectorfrom app.connectors.gcp_cloud_audit import GCPCloudAuditConnectorfrom app.connectors.gcp_scc import GCPSCCConnectorfrom app.connectors.github import GitHubConnector@@ -45,6 +46,7 @@ _CONNECTOR_CLASSES: tuple[type[BaseConnector], ...] = (AzureEntraConnector,CloudflareConnector,CrowdStrikeConnector,+ ElasticConnector,GCPCloudAuditConnector,GCPSCCConnector,GitHubConnector,@@ -95,6 +97,7 @@ __all__ = ["CloudflareConnector","ConnectorSchema","CrowdStrikeConnector",+ "ElasticConnector","Field","GCPCloudAuditConnector","GCPSCCConnector",diff --git a/services/connectors/app/connectors/base.py b/services/connectors/app/connectors/base.pyindex 0b2c03496..5c248dc13 100644--- a/services/connectors/app/connectors/base.py+++ b/services/connectors/app/connectors/base.py@@ -20,7 +20,10 @@ from __future__ import annotationsfrom abc import ABC, abstractmethodfrom dataclasses import asdict, dataclass, field-from typing import Any, Literal+from typing import TYPE_CHECKING, Any, Literal++if TYPE_CHECKING:+ from app.federated.query import UnifiedQuery# ---------------------------------------------------------------------------# Schema dataclasses@@ -166,3 +169,22 @@ class BaseConnector(ABC):def normalize(self, raw: dict[str, Any]) -> dict[str, Any]:"""Normalize a raw event to a common AiSOC alert schema."""return raw++ # ----------------------------- federated search --------------------------++ # Connectors that opt into federated search override ``supports_federated_search``+ # to True and implement ``query()``. Keeping it opt-in means a brand new+ # connector author doesn't have to think about query translation on day one.+ supports_federated_search: bool = False++ async def query(self, unified: UnifiedQuery) -> list[dict[str, Any]]:+ """Translate a ``UnifiedQuery`` and return matching rows.++ Default behaviour is to refuse, so a connector that hasn't been+ wired for federated search returns a clear error to the API layer+ rather than silently returning an empty result set (which would+ be indistinguishable from "no matches" and is a footgun).+ """+ raise NotImplementedError(+ f"connector '{self.connector_id}' does not support federated search"+ )diff --git a/services/connectors/app/connectors/elastic.py b/services/connectors/app/connectors/elastic.pynew file mode 100644index 000000000..0d41ac0fa--- /dev/null+++ b/services/connectors/app/connectors/elastic.py@@ -0,0 +1,177 @@+"""+Elastic SIEM connector.++Federated-search-first: the Elastic deployments most AiSOC customers run today+already have their own native dashboards and pipelines for alert ingestion, so+this connector exists primarily to give the federated layer a way to run ES|QL+against the customer's existing Elasticsearch cluster without exfiltrating logs+into AiSOC's own data plane.++``fetch_alerts`` is intentionally a thin wrapper over ES|QL on the+``.alerts-security.alerts-*`` index pattern so a tenant who *does* want+Elastic-side alerts to flow into the fusion engine can opt in by enabling the+connector's poll schedule.+"""++from __future__ import annotations++import base64+from typing import Any++import httpx+import structlog++from app.connectors.base import BaseConnector, ConnectorSchema, Field+from app.federated.query import UnifiedQuery+from app.federated.translators import to_esql++logger = structlog.get_logger()+++class ElasticConnector(BaseConnector):+ connector_id = "elastic"+ connector_name = "Elastic SIEM"+ connector_category = "siem"+ supports_federated_search = True++ @classmethod+ def schema(cls) -> ConnectorSchema:+ return ConnectorSchema(+ connector_id=cls.connector_id,+ connector_name=cls.connector_name,+ category=cls.connector_category,+ description="Elastic Security via the ES|QL search API. Federated-search ready.",+ docs_url="/docs/connectors/elastic",+ fields=[+ Field(+ "base_url",+ "string",+ "Elasticsearch URL",+ placeholder="https://elastic.example.com:9200",+ help_text="Cluster endpoint, not Kibana.",+ ),+ Field("api_key", "secret", "API Key", required=False),+ Field("username", "string", "Username", required=False),+ Field("password", "secret", "Password", required=False),+ Field(+ "index",+ "string",+ "Default Index Pattern",+ required=False,+ default="logs-*",+ ),+ ],+ )++ def __init__(+ self,+ base_url: str,+ api_key: str | None = None,+ username: str | None = None,+ password: str | None = None,+ index: str = "logs-*",+ ):+ if not api_key and not (username and password):+ raise ValueError(+ "Elastic connector requires either api_key or username+password"+ )+ self._base_url = base_url.rstrip("/")+ self._api_key = api_key+ self._username = username+ self._password = password+ self._index = index++ def _headers(self) -> dict[str, str]:+ if self._api_key:+ return {+ "Authorization": f"ApiKey {self._api_key}",+ "Content-Type": "application/json",+ }+ # Basic auth fallback for older self-hosted deployments.+ token = base64.b64encode(f"{self._username}:{self._password}".encode()).decode()+ return {+ "Authorization": f"Basic {token}",+ "Content-Type": "application/json",+ }++ async def test_connection(self) -> dict[str, Any]:+ async with httpx.AsyncClient(timeout=15.0, verify=False) as client:+ try:+ resp = await client.get(f"{self._base_url}/", headers=self._headers())+ resp.raise_for_status()+ info = resp.json()+ return {+ "success": True,+ "connector": self.connector_id,+ "version": info.get("version", {}).get("number"),+ "cluster_name": info.get("cluster_name"),+ }+ except Exception as exc:+ return {"success": False, "connector": self.connector_id, "error": str(exc)}++ async def fetch_alerts(self, since_seconds: int = 300) -> list[dict[str, Any]]:+ # Elastic Security stores detection rule alerts in this hidden index pattern.+ esql = (+ f'FROM .alerts-security.alerts-* '+ f'| WHERE @timestamp > NOW() - {since_seconds} seconds '+ f'| LIMIT 100'+ )+ async with httpx.AsyncClient(timeout=60.0, verify=False) as client:+ resp = await client.post(+ f"{self._base_url}/_query",+ headers=self._headers(),+ json={"query": esql},+ )+ resp.raise_for_status()+ data = resp.json()++ rows = self._rows_from_esql(data)+ return [self.normalize(r) for r in rows]++ async def query(self, unified: UnifiedQuery) -> list[dict[str, Any]]:+ """Run a translated ES|QL query and return raw rows.++ Mirrors the Splunk and Sentinel implementations: rows go back to the+ API layer untouched so the federated merger can tag each one with the+ originating connector id.+ """+ esql = to_esql(unified, index=self._index)+ async with httpx.AsyncClient(timeout=60.0, verify=False) as client:+ resp = await client.post(+ f"{self._base_url}/_query",+ headers=self._headers(),+ json={"query": esql},+ )+ resp.raise_for_status()+ data = resp.json()+ return self._rows_from_esql(data)++ @staticmethod+ def _rows_from_esql(data: dict[str, Any]) -> list[dict[str, Any]]:+ """Flatten the ES|QL ``columns``/``values`` shape into row dicts.++ ES|QL responses look like::++ {+ "columns": [{"name": "@timestamp", "type": "date"}, ...],+ "values": [["2026-05-01T00:00:00Z", ...], ...]+ }++ We zip them together so the API layer never has to know the shape.+ """+ columns = [c.get("name") for c in data.get("columns", [])]+ values = data.get("values", [])+ return [dict(zip(columns, row, strict=False)) for row in values]++ def normalize(self, raw: dict[str, Any]) -> dict[str, Any]:+ severity_map = {"low": "low", "medium": "medium", "high": "high", "critical": "high"}+ severity = str(raw.get("kibana.alert.severity") or raw.get("severity") or "medium").lower()+ return {+ "source": self.connector_id,+ "external_id": raw.get("kibana.alert.uuid") or raw.get("_id", ""),+ "title": raw.get("kibana.alert.rule.name") or raw.get("rule.name") or "Elastic Alert",+ "description": raw.get("kibana.alert.reason") or raw.get("message", ""),+ "severity": severity_map.get(severity, "medium"),+ "raw_event": raw,+ "created_at": raw.get("@timestamp"),+ }diff --git a/services/connectors/app/connectors/microsoft_sentinel.py b/services/connectors/app/connectors/microsoft_sentinel.pyindex 2b969bd9f..b29f340b8 100644--- a/services/connectors/app/connectors/microsoft_sentinel.py+++ b/services/connectors/app/connectors/microsoft_sentinel.py@@ -12,17 +12,21 @@ import httpximport structlogfrom app.connectors.base import BaseConnector, ConnectorSchema, Field+from app.federated.query import UnifiedQuery+from app.federated.translators import to_kqllogger = structlog.get_logger()_TOKEN_URL = "https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token"_SENTINEL_API = "https://management.azure.com/subscriptions/{sub_id}/resourceGroups/{rg}/providers/Microsoft.OperationalInsights/workspaces/{workspace}/providers/Microsoft.SecurityInsights/incidents"+_LOGS_API = "https://api.loganalytics.io/v1/workspaces/{workspace_id}/query"class MicrosoftSentinelConnector(BaseConnector):connector_id = "microsoft_sentinel"connector_name = "Microsoft Sentinel"connector_category = "siem"+ supports_federated_search = True@classmethoddef schema(cls) -> ConnectorSchema:@@ -110,6 +114,39 @@ class MicrosoftSentinelConnector(BaseConnector):return [self.normalize(i) for i in incidents]+ async def query(self, unified: UnifiedQuery) -> list[dict[str, Any]]:+ """Run a translated KQL query against Log Analytics.++ Sentinel KQL runs against the workspace's Log Analytics endpoint,+ which uses a different API base than the Security Insights REST+ endpoint used by ``fetch_alerts``. The federated layer scopes auth+ to ``api.loganalytics.io`` separately from the management API.+ """+ if not self._access_token:+ await self._authenticate()++ kql = to_kql(unified, table="CommonSecurityLog")+ async with httpx.AsyncClient(timeout=60.0) as client:+ url = _LOGS_API.format(workspace_id=self._workspace)+ headers = {+ "Authorization": f"Bearer {self._access_token}",+ "Content-Type": "application/json",+ }+ resp = await client.post(url, headers=headers, json={"query": kql})+ resp.raise_for_status()+ data = resp.json()++ # Log Analytics returns { "tables": [ { "columns": [...], "rows": [[...]] } ] }+ # Flatten the first table into a list of column-keyed dicts so the API+ # layer doesn't need to know the wire shape.+ tables = data.get("tables") or []+ if not tables:+ return []+ primary = tables[0]+ columns = [c.get("name") for c in primary.get("columns", [])]+ rows = primary.get("rows", [])+ return [dict(zip(columns, row, strict=False)) for row in rows]+def normalize(self, raw: dict[str, Any]) -> dict[str, Any]:props = raw.get("properties", {})severity_map = {"Informational": "info", "Low": "low", "Medium": "medium", "High": "high"}diff --git a/services/connectors/app/connectors/splunk.py b/services/connectors/app/connectors/splunk.pyindex 7f3aaadcf..69f392f28 100644--- a/services/connectors/app/connectors/splunk.py+++ b/services/connectors/app/connectors/splunk.py@@ -11,6 +11,8 @@ import httpximport structlogfrom app.connectors.base import BaseConnector, ConnectorSchema, Field+from app.federated.query import UnifiedQuery+from app.federated.translators import to_spllogger = structlog.get_logger()@@ -19,6 +21,7 @@ class SplunkConnector(BaseConnector):connector_id = "splunk"connector_name = "Splunk SIEM"connector_category = "siem"+ supports_federated_search = True@classmethoddef schema(cls) -> ConnectorSchema:@@ -113,6 +116,25 @@ class SplunkConnector(BaseConnector):return [self.normalize(r) for r in results]+ async def query(self, unified: UnifiedQuery) -> list[dict[str, Any]]:+ """Run a translated SPL search and return raw rows.++ We deliberately do *not* call ``normalize`` here because federated+ search returns rows for analyst pivoting, not alerts that should+ flow into the fusion engine. The API layer wraps each row with+ connector identity so downstream consumers can tell sources apart.+ """+ index = self._saved_search if self._saved_search.startswith("index=") else "notable"+ spl = to_spl(unified, index=index)+ async with httpx.AsyncClient(timeout=60.0, verify=False) as client:+ resp = await client.post(+ f"{self._base_url}/services/search/jobs",+ headers=self._headers(),+ data={"search": spl, "output_mode": "json", "exec_mode": "oneshot"},+ )+ resp.raise_for_status()+ return list(resp.json().get("results", []))+def normalize(self, raw: dict[str, Any]) -> dict[str, Any]:urgency_map = {"critical": "critical", "high": "high", "medium": "medium", "low": "low", "informational": "info"}return {diff --git a/services/connectors/app/db/connector_repo.py b/services/connectors/app/db/connector_repo.pyindex 5d0455e92..86ac5cb2c 100644--- a/services/connectors/app/db/connector_repo.py+++ b/services/connectors/app/db/connector_repo.py@@ -29,7 +29,6 @@ from sqlalchemy import (MetaData,String,Table,- and_,select,update,)diff --git a/services/connectors/app/db/engine.py b/services/connectors/app/db/engine.pyindex 173f3ee5d..1eeaff093 100644--- a/services/connectors/app/db/engine.py+++ b/services/connectors/app/db/engine.py@@ -16,7 +16,6 @@ from __future__ import annotationsimport osfrom threading import Lock-from typing import Anyfrom sqlalchemy.ext.asyncio import AsyncEngine, create_async_enginediff --git a/services/connectors/app/federated/__init__.py b/services/connectors/app/federated/__init__.pynew file mode 100644index 000000000..68c9b2b3e--- /dev/null+++ b/services/connectors/app/federated/__init__.py@@ -0,0 +1,31 @@+"""Federated search across SIEM backends.++The federated layer translates a single ``UnifiedQuery`` into the native+query languages of every backend SIEM AiSOC has a connector for (today:+Splunk SPL, Microsoft Sentinel KQL, Elastic ES|QL). Each connector that+opts into federated search implements ``BaseConnector.query`` against+this model.++This package owns the *shape* of a unified query and the pure-function+translators. Orchestration (fan-out, merge, ranking) lives in the API+service so it can apply tenant-scoped credential decryption and per-row+RBAC before results leave the data plane.+"""++from __future__ import annotations++from app.federated.query import (+ Indicator,+ Operator,+ QueryError,+ UnifiedQuery,+ parse_unified_query,+)++__all__ = [+ "Indicator",+ "Operator",+ "QueryError",+ "UnifiedQuery",+ "parse_unified_query",+]diff --git a/services/connectors/app/federated/query.py b/services/connectors/app/federated/query.pynew file mode 100644index 000000000..f964f9d84--- /dev/null+++ b/services/connectors/app/federated/query.py@@ -0,0 +1,171 @@+"""Unified query model for federated SIEM search.++A ``UnifiedQuery`` is the single in-memory representation that can be+translated into Splunk SPL, Microsoft Sentinel KQL, or Elastic ES|QL.+The model is intentionally small — we resist the urge to model every+backend's full grammar because the goal is *cross-SIEM pivot*, not+"replace your SIEM's query language".++Three building blocks:++* ``Indicator`` — a single ``field <op> value`` triple. Stacking+ indicators implies AND-conjunction; OR is expressed by composing+ multiple queries client-side and merging the result sets.+* ``UnifiedQuery`` — the top-level envelope: free-text search, indicator+ list, time window, and a result cap.+* ``parse_unified_query`` — accepts a JSON-shaped dict from the wire and+ validates it into the dataclass form. We do not depend on Pydantic+ here so this module stays usable from the connectors microservice+ without dragging the whole API stack.++Trust boundary: this module never sees plaintext credentials. It only+shapes the query that gets handed to a connector instance the API+service has already constructed with decrypted auth_config.+"""++from __future__ import annotations++from dataclasses import dataclass, field+from typing import Any, Literal++# Operator vocabulary kept deliberately narrow. Adding a new operator+# means updating every translator, so we keep the surface tight.+Operator = Literal[+ "eq", # field == value+ "ne", # field != value+ "contains", # substring match (case-insensitive when the backend supports it)+ "starts_with", # prefix match+ "ends_with", # suffix match+ "gt", # field > value (numeric / timestamp)+ "gte", # field >= value+ "lt", # field < value+ "lte", # field <= value+ "in", # field is one of [...]+]++_VALID_OPERATORS: frozenset[str] = frozenset(+ [+ "eq",+ "ne",+ "contains",+ "starts_with",+ "ends_with",+ "gt",+ "gte",+ "lt",+ "lte",+ "in",+ ]+)+++class QueryError(ValueError):+ """Raised when an incoming query payload fails validation.++ Distinct from ``ValueError`` so the API layer can map it to a 422+ without swallowing other validation errors.+ """+++@dataclass(frozen=True)+class Indicator:+ """A single ``field <op> value`` triple."""++ field: str+ operator: Operator+ value: Any++ def __post_init__(self) -> None:+ if not isinstance(self.field, str) or not self.field.strip():+ raise QueryError("indicator.field must be a non-empty string")+ if self.operator not in _VALID_OPERATORS:+ raise QueryError(+ f"indicator.operator '{self.operator}' is not one of {sorted(_VALID_OPERATORS)}"+ )+ if self.operator == "in":+ if not isinstance(self.value, (list, tuple)) or not self.value:+ raise QueryError("indicator with operator='in' requires a non-empty list value")+ elif self.value is None:+ raise QueryError(f"indicator.value must not be None for operator '{self.operator}'")+++@dataclass(frozen=True)+class UnifiedQuery:+ """A SIEM-agnostic query.++ ``free_text`` is a substring (or full-text) search executed against+ the backend's default search field. ``indicators`` are AND-joined+ field/op/value filters. ``since_seconds`` is a relative-from-now+ window, kept simple to match how alerts are typically queried in+ SOC pivots; absolute time ranges can be added later if the eval+ harness needs them.++ ``limit`` caps the number of rows returned per backend; the API+ service then merges and re-caps at the federated level.+ """++ free_text: str = ""+ indicators: tuple[Indicator, ...] = field(default_factory=tuple)+ since_seconds: int = 3600+ limit: int = 100++ def __post_init__(self) -> None:+ if not isinstance(self.since_seconds, int) or self.since_seconds <= 0:+ raise QueryError("since_seconds must be a positive integer")+ if self.since_seconds > 7 * 24 * 3600:+ raise QueryError("since_seconds must be ≤ 7 days; use a SIEM-native search for longer windows")+ if not isinstance(self.limit, int) or self.limit <= 0:+ raise QueryError("limit must be a positive integer")+ if self.limit > 1000:+ raise QueryError("limit must be ≤ 1000")+ if not self.free_text.strip() and not self.indicators:+ raise QueryError("query must include free_text or at least one indicator")++ def to_dict(self) -> dict[str, Any]:+ return {+ "free_text": self.free_text,+ "indicators": [+ {"field": i.field, "operator": i.operator, "value": i.value}+ for i in self.indicators+ ],+ "since_seconds": self.since_seconds,+ "limit": self.limit,+ }+++def parse_unified_query(payload: dict[str, Any]) -> UnifiedQuery:+ """Turn a JSON-shaped dict into a validated ``UnifiedQuery``.++ Accepts both ``indicators`` (preferred) and ``filters`` (alias kept+ so older clients don't break) for the indicator list.+ """+ if not isinstance(payload, dict):+ raise QueryError("query payload must be a JSON object")++ raw_indicators = payload.get("indicators")+ if raw_indicators is None:+ raw_indicators = payload.get("filters", [])+ if not isinstance(raw_indicators, list):+ raise QueryError("indicators must be a list")++ parsed: list[Indicator] = []+ for entry in raw_indicators:+ if not isinstance(entry, dict):+ raise QueryError("each indicator must be an object with field/operator/value")+ try:+ parsed.append(+ Indicator(+ field=entry["field"],+ operator=entry["operator"],+ value=entry["value"],+ )+ )+ except KeyError as exc:+ raise QueryError(f"indicator missing key: {exc.args[0]}") from exc++ return UnifiedQuery(+ free_text=str(payload.get("free_text", "") or "").strip(),+ indicators=tuple(parsed),+ since_seconds=int(payload.get("since_seconds", 3600) or 3600),+ limit=int(payload.get("limit", 100) or 100),+ )diff --git a/services/connectors/app/federated/translators/__init__.py b/services/connectors/app/federated/translators/__init__.pynew file mode 100644index 000000000..1d4c1f1bc--- /dev/null+++ b/services/connectors/app/federated/translators/__init__.py@@ -0,0 +1,15 @@+"""Pure-function translators from ``UnifiedQuery`` to backend dialects.++Each translator takes a validated ``UnifiedQuery`` and returns a string+the corresponding connector can pass straight to its SIEM. Translators+are pure: no I/O, no global state, no exceptions other than+``QueryError`` for un-translatable shapes.+"""++from __future__ import annotations++from app.federated.translators.esql import to_esql+from app.federated.translators.kql import to_kql+from app.federated.translators.spl import to_spl++__all__ = ["to_esql", "to_kql", "to_spl"]diff --git a/services/connectors/app/federated/translators/esql.py b/services/connectors/app/federated/translators/esql.pynew file mode 100644index 000000000..219f8ecbf--- /dev/null+++ b/services/connectors/app/federated/translators/esql.py@@ -0,0 +1,74 @@+"""Translate ``UnifiedQuery`` → Elastic ES|QL.++ES|QL is Elastic's piped query language; the shape we emit:++ FROM <index>+ | WHERE @timestamp > NOW() - <Ns>+ | WHERE <free_text predicate>+ | WHERE <indicator>+ ...+ | LIMIT <limit>++Indices are chosen by the caller from ``connector_config`` — typically+``logs-*`` for Beats-shipped data or ``security-*`` for Elastic SIEM.+"""++from __future__ import annotations++from typing import Any++from app.federated.query import Indicator, QueryError, UnifiedQuery+++def _esql_quote(value: Any) -> str:+ if isinstance(value, bool):+ return "true" if value else "false"+ if isinstance(value, (int, float)):+ return str(value)+ text = str(value)+ escaped = text.replace("\\", "\\\\").replace('"', '\\"')+ return f'"{escaped}"'+++def _indicator_to_esql(indicator: Indicator) -> str:+ field_token = indicator.field+ op = indicator.operator+ value = indicator.value++ if op == "eq":+ return f"{field_token} == {_esql_quote(value)}"+ if op == "ne":+ return f"{field_token} != {_esql_quote(value)}"+ if op == "contains":+ # ES|QL has no native CONTAINS; LIKE with %...% is the canonical port.+ return f'{field_token} LIKE "%{value}%"'+ if op == "starts_with":+ return f'{field_token} LIKE "{value}%"'+ if op == "ends_with":+ return f'{field_token} LIKE "%{value}"'+ if op == "gt":+ return f"{field_token} > {_esql_quote(value)}"+ if op == "gte":+ return f"{field_token} >= {_esql_quote(value)}"+ if op == "lt":+ return f"{field_token} < {_esql_quote(value)}"+ if op == "lte":+ return f"{field_token} <= {_esql_quote(value)}"+ if op == "in":+ joined = ", ".join(_esql_quote(v) for v in value)+ return f"{field_token} IN ({joined})"+ raise QueryError(f"unsupported operator for ES|QL: {op}")+++def to_esql(query: UnifiedQuery, *, index: str = "logs-*") -> str:+ """Render a ``UnifiedQuery`` as an ES|QL pipeline."""+ lines: list[str] = [+ f"FROM {index}",+ f"| WHERE @timestamp > NOW() - {query.since_seconds} seconds",+ ]+ if query.free_text:+ lines.append(f'| WHERE message LIKE "%{query.free_text}%"')+ for indicator in query.indicators:+ lines.append(f"| WHERE {_indicator_to_esql(indicator)}")+ lines.append(f"| LIMIT {query.limit}")+ return "\n".join(lines)diff --git a/services/connectors/app/federated/translators/kql.py b/services/connectors/app/federated/translators/kql.pynew file mode 100644index 000000000..09e158ebf--- /dev/null+++ b/services/connectors/app/federated/translators/kql.py@@ -0,0 +1,77 @@+"""Translate ``UnifiedQuery`` → Microsoft Sentinel / Azure Monitor KQL.++The emitted KQL targets ``CommonSecurityLog`` by default since that's+the broadest cross-source table in a typical Sentinel deployment, but+the table name is parameterized so a connector can scope to+``SecurityIncident``, ``SigninLogs``, etc.++Shape:++ <table>+ | where TimeGenerated > ago(Ns)+ | where <free_text>+ | where <indicator>+ ...+ | take <limit>+"""++from __future__ import annotations++from typing import Any++from app.federated.query import Indicator, QueryError, UnifiedQuery+++def _kql_quote(value: Any) -> str:+ if isinstance(value, bool):+ return "true" if value else "false"+ if isinstance(value, (int, float)):+ return str(value)+ text = str(value)+ escaped = text.replace("\\", "\\\\").replace('"', '\\"')+ return f'"{escaped}"'+++def _indicator_to_kql(indicator: Indicator) -> str:+ field_token = indicator.field+ op = indicator.operator+ value = indicator.value++ if op == "eq":+ return f"{field_token} == {_kql_quote(value)}"+ if op == "ne":+ return f"{field_token} != {_kql_quote(value)}"+ if op == "contains":+ return f"{field_token} contains {_kql_quote(value)}"+ if op == "starts_with":+ return f"{field_token} startswith {_kql_quote(value)}"+ if op == "ends_with":+ return f"{field_token} endswith {_kql_quote(value)}"+ if op == "gt":+ return f"{field_token} > {_kql_quote(value)}"+ if op == "gte":+ return f"{field_token} >= {_kql_quote(value)}"+ if op == "lt":+ return f"{field_token} < {_kql_quote(value)}"+ if op == "lte":+ return f"{field_token} <= {_kql_quote(value)}"+ if op == "in":+ joined = ", ".join(_kql_quote(v) for v in value)+ return f"{field_token} in ({joined})"+ raise QueryError(f"unsupported operator for KQL: {op}")+++def to_kql(query: UnifiedQuery, *, table: str = "CommonSecurityLog") -> str:+ """Render a ``UnifiedQuery`` as a KQL pipeline."""+ lines: list[str] = [+ table,+ f"| where TimeGenerated > ago({query.since_seconds}s)",+ ]+ if query.free_text:+ # KQL's "search" verb does free-text across all string columns;+ # we use it as a where-clause so the pipeline shape stays uniform.+ lines.append(f"| where * contains {_kql_quote(query.free_text)}")+ for indicator in query.indicators:+ lines.append(f"| where {_indicator_to_kql(indicator)}")+ lines.append(f"| take {query.limit}")+ return "\n".join(lines)diff --git a/services/connectors/app/federated/translators/spl.py b/services/connectors/app/federated/translators/spl.pynew file mode 100644index 000000000..338dd32f4--- /dev/null+++ b/services/connectors/app/federated/translators/spl.py@@ -0,0 +1,80 @@+"""Translate ``UnifiedQuery`` → Splunk SPL.++The SPL we emit is intentionally vanilla — no transforming commands,+no subsearches — so it composes well with whatever index, sourcetype,+or saved-search prefix the tenant's Splunk admin layered on top via+the connector's ``connector_config``.++Shape:++ search index=<index> earliest=-Ns latest=now <filters> | head <limit>++Field/operator semantics map onto Splunk's standard search syntax.+String values are quoted and any embedded double quotes are escaped.+"""++from __future__ import annotations++from typing import Any++from app.federated.query import Indicator, QueryError, UnifiedQuery+++def _spl_quote(value: Any) -> str:+ """Quote a value for safe inclusion in an SPL filter.++ Splunk's search language treats most characters literally inside+ double quotes; escape embedded quotes and backslashes.+ """+ if isinstance(value, bool):+ return "true" if value else "false"+ if isinstance(value, (int, float)):+ return str(value)+ text = str(value)+ escaped = text.replace("\\", "\\\\").replace('"', '\\"')+ return f'"{escaped}"'+++def _indicator_to_spl(indicator: Indicator) -> str:+ field_token = indicator.field+ op = indicator.operator+ value = indicator.value++ if op == "eq":+ return f"{field_token}={_spl_quote(value)}"+ if op == "ne":+ return f"NOT {field_token}={_spl_quote(value)}"+ if op == "contains":+ return f"{field_token}=*{value}*"+ if op == "starts_with":+ return f"{field_token}={value}*"+ if op == "ends_with":+ return f"{field_token}=*{value}"+ if op == "gt":+ return f"{field_token}>{_spl_quote(value)}"+ if op == "gte":+ return f"{field_token}>={_spl_quote(value)}"+ if op == "lt":+ return f"{field_token}<{_spl_quote(value)}"+ if op == "lte":+ return f"{field_token}<={_spl_quote(value)}"+ if op == "in":+ joined = " OR ".join(f"{field_token}={_spl_quote(v)}" for v in value)+ return f"({joined})"+ raise QueryError(f"unsupported operator for SPL: {op}")+++def to_spl(query: UnifiedQuery, *, index: str = "main") -> str:+ """Render a ``UnifiedQuery`` as a Splunk search string.++ ``index`` is supplied by the caller from the connector's+ ``connector_config`` (typically ``notable`` for ES customers,+ ``main`` for self-hosted indexes).+ """+ parts: list[str] = [f"search index={index} earliest=-{query.since_seconds}s latest=now"]+ if query.free_text:+ parts.append(_spl_quote(query.free_text))+ for indicator in query.indicators:+ parts.append(_indicator_to_spl(indicator))+ parts.append(f"| head {query.limit}")+ return " ".join(parts)diff --git a/services/connectors/app/ingest_client.py b/services/connectors/app/ingest_client.pyindex 12c9bad41..44826d765 100644--- a/services/connectors/app/ingest_client.py+++ b/services/connectors/app/ingest_client.py@@ -131,8 +131,8 @@ class IngestClient:try:data = resp.json()- except ValueError:- raise IngestClientError("ingest service returned non-JSON response")+ except ValueError as err:+ raise IngestClientError("ingest service returned non-JSON response") from errreturn datadiff --git a/services/connectors/app/main.py b/services/connectors/app/main.pyindex 4bda6740a..e97c1444f 100644--- a/services/connectors/app/main.py+++ b/services/connectors/app/main.py@@ -18,8 +18,8 @@ running this app without spinning up a polling loop.from __future__ import annotationsimport logging+from collections.abc import AsyncIteratorfrom contextlib import asynccontextmanager-from typing import AsyncIteratorfrom fastapi import FastAPIfrom fastapi.middleware.cors import CORSMiddlewarediff --git a/services/connectors/tests/test_azure_connectors.py b/services/connectors/tests/test_azure_connectors.pyindex c0c9f789b..f15509a2c 100644--- a/services/connectors/tests/test_azure_connectors.py+++ b/services/connectors/tests/test_azure_connectors.py@@ -16,7 +16,6 @@ from __future__ import annotationsimport httpximport pytestimport respx-from app.connectors.azure_activity import AzureActivityConnectorfrom app.connectors.azure_defender import AzureDefenderConnectorfrom app.connectors.azure_entra import AzureEntraConnectordiff --git a/services/connectors/tests/test_federated.py b/services/connectors/tests/test_federated.pynew file mode 100644index 000000000..55c14529b--- /dev/null+++ b/services/connectors/tests/test_federated.py@@ -0,0 +1,366 @@+"""+Tests for the federated-search layer (``app.federated``).++These run as the eval-harness scenario for the ``w3-fed`` capability:+the unified-query model and its three translators (SPL/KQL/ES|QL) all+need to round-trip a representative query into syntactically+plausible backend strings, and the ``ElasticConnector.query()`` method+needs to flatten an ES|QL ``columns``/``values`` response shape into+plain dicts that the merging layer in ``services/api`` can consume.++We don't talk to a real Splunk/Sentinel/Elastic here — the goal is to+prove that the translation surface is safe (no operator silently+dropped, no value silently un-quoted) and that the connector glue+correctly assembles the request and parses the response. End-to-end+backend smoke tests live with the integration suite.+"""++from __future__ import annotations++from typing import Any++import httpx+import pytest+from app.connectors import CONNECTOR_REGISTRY+from app.connectors.elastic import ElasticConnector+from app.connectors.microsoft_sentinel import MicrosoftSentinelConnector+from app.connectors.splunk import SplunkConnector+from app.federated.query import (+ Indicator,+ QueryError,+ UnifiedQuery,+ parse_unified_query,+)+from app.federated.translators import to_esql, to_kql, to_spl++# ------------------------------------------------------------------ query model+++def test_parse_unified_query_accepts_minimal_payload():+ q = parse_unified_query({"free_text": "lateral movement"})+ assert q.free_text == "lateral movement"+ assert q.indicators == ()+ # Defaults from the contract.+ assert q.since_seconds == 3600+ assert q.limit == 100+++def test_parse_unified_query_accepts_indicators_alias():+ # ``filters`` is the legacy key; the model accepts either name.+ q = parse_unified_query(+ {+ "filters": [+ {"field": "user.name", "operator": "eq", "value": "alice"},+ {"field": "src_ip", "operator": "eq", "value": "10.0.0.5"},+ ]+ }+ )+ assert len(q.indicators) == 2+ assert q.indicators[0].field == "user.name"+ assert q.indicators[1].operator == "eq"+++def test_parse_unified_query_rejects_non_object_payload():+ with pytest.raises(QueryError):+ parse_unified_query("not an object") # type: ignore[arg-type]+++def test_parse_unified_query_rejects_missing_indicator_fields():+ with pytest.raises(QueryError):+ parse_unified_query({"indicators": [{"field": "user.name", "operator": "eq"}]})+++# ------------------------------------------------------------------- translators+++_SAMPLE_QUERY = UnifiedQuery(+ free_text="kerberoasting",+ indicators=(+ Indicator(field="user.name", operator="eq", value="alice"),+ Indicator(field="event.code", operator="in", value=[4769, 4770]),+ Indicator(field="process.name", operator="contains", value="mimikatz"),+ ),+ since_seconds=900,+ limit=50,+)+++def test_spl_translator_renders_indicators_and_time_window():+ spl = to_spl(_SAMPLE_QUERY)++ # All three indicators must appear; we don't assert exact whitespace,+ # only that no operator was silently dropped.+ assert "user.name" in spl+ assert "event.code" in spl+ assert "process.name" in spl+ # SPL renders an "in" operator as IN(...) with the value list intact.+ assert "4769" in spl and "4770" in spl+ # Time window must collapse to an SPL-native earliest specifier.+ assert "earliest" in spl.lower()+ # The free_text should appear somewhere as a search term.+ assert "kerberoasting" in spl+++def test_kql_translator_renders_pipeline_form():+ kql = to_kql(_SAMPLE_QUERY)++ # KQL is pipeline-shaped; we should see the | take/limit clause and a where.+ lowered = kql.lower()+ assert "where" in lowered+ assert "user.name" in kql+ assert "event.code" in kql+ # ``in`` becomes ``in (4769, 4770)`` — both values must survive.+ assert "4769" in kql and "4770" in kql+ # ``take`` or ``limit`` caps the rows. (Translator may pick either.)+ assert "take" in lowered or "limit" in lowered+++def test_esql_translator_renders_from_and_where():+ esql = to_esql(_SAMPLE_QUERY)++ # ES|QL queries always start with FROM and pipe through WHERE/LIMIT.+ assert esql.strip().upper().startswith("FROM")+ assert "user.name" in esql+ assert "event.code" in esql+ assert "process.name" in esql+ # ``contains`` on ES|QL maps to ``LIKE "%value%"``; check that the value+ # made it through somewhere in the rendered string.+ assert "mimikatz" in esql+ assert "LIKE" in esql.upper()+++def test_translators_handle_empty_indicators_safely():+ # Free-text-only query — translators must still produce *some* valid output,+ # not crash. The merge layer relies on this for natural-language pivots.+ q = UnifiedQuery(+ free_text="brute force",+ indicators=(),+ since_seconds=300,+ limit=10,+ )+ assert "brute force" in to_spl(q)+ assert "brute force" in to_kql(q)+ assert "brute force" in to_esql(q)+++# ------------------------------------------------------------- connector wiring+++def test_federated_capable_connectors_are_registered_and_advertised():+ """``services/api`` pre-filters by ``supports_federated_search``; if a+ connector is supposed to be queryable, it must opt in *and* be in the+ registry. This test catches both halves at once."""+ for connector_id in ("splunk", "microsoft_sentinel", "elastic"):+ cls = CONNECTOR_REGISTRY.get(connector_id)+ assert cls is not None, f"connector '{connector_id}' missing from registry"+ assert getattr(cls, "supports_federated_search", False), (+ f"connector '{connector_id}' must opt into federated search"+ )+++def test_elastic_connector_flattens_esql_columns_and_values():+ """ES|QL responses come back as ``{"columns": [...], "values": [[...]]}``.+ The fan-out merge in ``services/api`` only knows how to consume rows of+ dicts, so the connector has to flatten before returning."""+ sample_response: dict[str, Any] = {+ "columns": [+ {"name": "@timestamp", "type": "date"},+ {"name": "user.name", "type": "keyword"},+ {"name": "event.code", "type": "long"},+ ],+ "values": [+ ["2026-05-05T12:00:00Z", "alice", 4769],+ ["2026-05-05T12:01:00Z", "bob", 4770],+ ],+ }++ rows = ElasticConnector._rows_from_esql(sample_response)+ assert rows == [+ {"@timestamp": "2026-05-05T12:00:00Z", "user.name": "alice", "event.code": 4769},+ {"@timestamp": "2026-05-05T12:01:00Z", "user.name": "bob", "event.code": 4770},+ ]+++def test_elastic_connector_flatten_handles_empty_response():+ # Edge case: empty ES|QL result must produce an empty list, not crash.+ assert ElasticConnector._rows_from_esql({"columns": [], "values": []}) == []+ # And missing keys must also be handled defensively.+ assert ElasticConnector._rows_from_esql({}) == []+++# --------------------------------------------------------------- live-call shape+++async def test_splunk_query_assembles_post_body(monkeypatch):+ """Confirm ``SplunkConnector.query()`` builds the right Splunk REST call:+ the SPL string lands in the body, the time window survives, and we read+ rows out of the JSON ``results`` array. We patch the HTTP layer so this+ stays hermetic."""+ captured: dict[str, Any] = {}++ class _StubResponse:+ status_code = 200++ @staticmethod+ def raise_for_status() -> None:+ return None++ @staticmethod+ def json() -> dict[str, Any]:+ return {"results": [{"_time": "2026-05-05T00:00:00Z", "user": "alice"}]}++ class _StubAsyncClient:+ def __init__(self, *args, **kwargs):+ pass++ async def __aenter__(self):+ return self++ async def __aexit__(self, *args):+ return None++ async def post(self, url, **kwargs):+ captured["url"] = url+ captured["data"] = kwargs.get("data") or kwargs.get("params") or {}+ return _StubResponse()++ monkeypatch.setattr(httpx, "AsyncClient", _StubAsyncClient)++ connector = SplunkConnector(+ base_url="https://splunk.example.com:8089",+ token="fake-token",+ saved_search="AiSOC_Alerts",+ )++ rows = await connector.query(_SAMPLE_QUERY)+ assert rows == [{"_time": "2026-05-05T00:00:00Z", "user": "alice"}]+ # Splunk REST search lands at /services/search/jobs.+ assert "search" in captured["url"]+ # The translated SPL must have made it into the request body.+ body = captured["data"]+ body_str = str(body)+ assert "user.name" in body_str+ assert "kerberoasting" in body_str+++async def test_sentinel_query_assembles_loganalytics_call(monkeypatch):+ captured: dict[str, Any] = {}++ class _StubResponse:+ status_code = 200++ @staticmethod+ def raise_for_status() -> None:+ return None++ @staticmethod+ def json() -> dict[str, Any]:+ # Log Analytics API shape: tables[].columns[] + rows[].+ return {+ "tables": [+ {+ "columns": [+ {"name": "TimeGenerated"},+ {"name": "UserPrincipalName"},+ ],+ "rows": [["2026-05-05T00:00:00Z", "[email protected]"]],+ }+ ]+ }++ class _StubAsyncClient:+ def __init__(self, *args, **kwargs):+ pass++ async def __aenter__(self):+ return self++ async def __aexit__(self, *args):+ return None++ async def post(self, url, **kwargs):+ captured["url"] = url+ captured["json"] = kwargs.get("json") or {}+ return _StubResponse()++ async def get(self, url, **kwargs):+ # Token-mint or workspace-info call — return empty body to keep+ # the auth path happy without modeling the full OAuth dance.+ return _StubResponse()++ monkeypatch.setattr(httpx, "AsyncClient", _StubAsyncClient)++ connector = MicrosoftSentinelConnector(+ tenant_id="tenant-uuid",+ client_id="client-uuid",+ client_secret="fake-secret",+ subscription_id="sub-uuid",+ resource_group="rg",+ workspace="workspace-uuid",+ )+ # Bypass the OAuth token mint so we go straight to the query.+ connector._access_token = "fake-bearer" # noqa: SLF001++ rows = await connector.query(_SAMPLE_QUERY)+ assert rows == [+ {"TimeGenerated": "2026-05-05T00:00:00Z", "UserPrincipalName": "[email protected]"}+ ]+ # Log Analytics API path; workspace id must appear in the URL.+ assert "loganalytics" in captured["url"].lower()+ assert "workspace-uuid" in captured["url"]+ # The KQL string must be in the request body.+ body = captured["json"]+ assert "query" in body+ assert "user.name" in body["query"]+++async def test_elastic_query_assembles_esql_call(monkeypatch):+ captured: dict[str, Any] = {}++ class _StubResponse:+ status_code = 200++ @staticmethod+ def raise_for_status() -> None:+ return None++ @staticmethod+ def json() -> dict[str, Any]:+ return {+ "columns": [{"name": "@timestamp"}, {"name": "user.name"}],+ "values": [["2026-05-05T00:00:00Z", "alice"]],+ }++ class _StubAsyncClient:+ def __init__(self, *args, **kwargs):+ pass++ async def __aenter__(self):+ return self++ async def __aexit__(self, *args):+ return None++ async def post(self, url, **kwargs):+ captured["url"] = url+ captured["json"] = kwargs.get("json") or {}+ return _StubResponse()++ monkeypatch.setattr(httpx, "AsyncClient", _StubAsyncClient)++ connector = ElasticConnector(+ base_url="https://elastic.example.com:9200",+ api_key="fake-key",+ )++ rows = await connector.query(_SAMPLE_QUERY)+ assert rows == [{"@timestamp": "2026-05-05T00:00:00Z", "user.name": "alice"}]+ assert "_query" in captured["url"]+ body = captured["json"]+ assert "query" in body+ # Translated ES|QL must have survived into the request body.+ assert "FROM" in body["query"].upper()+ assert "user.name" in body["query"]diff --git a/services/connectors/tests/test_gcp_connectors.py b/services/connectors/tests/test_gcp_connectors.pyindex 4a3fbdbc5..411d25113 100644--- a/services/connectors/tests/test_gcp_connectors.py+++ b/services/connectors/tests/test_gcp_connectors.py@@ -17,11 +17,10 @@ import jsonimport httpximport pytestimport respx-from cryptography.hazmat.primitives import serialization-from cryptography.hazmat.primitives.asymmetric import rsa-from app.connectors.gcp_cloud_audit import GCPCloudAuditConnectorfrom app.connectors.gcp_scc import GCPSCCConnector+from cryptography.hazmat.primitives import serialization+from cryptography.hazmat.primitives.asymmetric import rsa_PROJECT = "aisoc-test-project"_ORG = "1234567890"diff --git a/services/connectors/tests/test_saas_connectors.py b/services/connectors/tests/test_saas_connectors.pyindex 87ad7f951..e05fc0a30 100644--- a/services/connectors/tests/test_saas_connectors.py+++ b/services/connectors/tests/test_saas_connectors.py@@ -23,13 +23,12 @@ import jsonimport httpximport pytestimport respx-from cryptography.hazmat.primitives import serialization-from cryptography.hazmat.primitives.asymmetric import rsa-from app.connectors.cloudflare import CloudflareConnectorfrom app.connectors.github import GitHubConnectorfrom app.connectors.google_workspace import GoogleWorkspaceConnectorfrom app.connectors.m365_audit import M365AuditConnector+from cryptography.hazmat.primitives import serialization+from cryptography.hazmat.primitives.asymmetric import rsa_TENANT = "00000000-0000-0000-0000-000000000000"_CLIENT_ID = "11111111-1111-1111-1111-111111111111"diff --git a/services/connectors/tests/test_scheduler.py b/services/connectors/tests/test_scheduler.pyindex 400f5f53a..5fdaa99fd 100644--- a/services/connectors/tests/test_scheduler.py+++ b/services/connectors/tests/test_scheduler.py@@ -20,7 +20,6 @@ from typing import Anyfrom unittest.mock import AsyncMock, MagicMockimport pytest-from app.db.connector_repo import ConnectorInstancefrom app.scheduler import ConnectorScheduler, _coerce_poll_intervaldiff --git a/services/connectors/tests/test_schemas.py b/services/connectors/tests/test_schemas.pyindex 13d455478..d0ccb03d9 100644--- a/services/connectors/tests/test_schemas.py+++ b/services/connectors/tests/test_schemas.py@@ -9,7 +9,6 @@ without a well-formed schema.from __future__ import annotationsimport pytest-from app.connectors import CONNECTOR_REGISTRY, list_connector_schemasfrom app.connectors.base import BaseConnector, ConnectorSchema, Fielddiff --git a/services/fusion/app/api/router.py b/services/fusion/app/api/router.pyindex f21c3fbb0..5eec5be21 100644--- a/services/fusion/app/api/router.py+++ b/services/fusion/app/api/router.py@@ -1,8 +1,10 @@from __future__ import annotations-from fastapi import APIRouter, HTTPException+from uuid import UUID-from app.models.alert import AnalystFeedback+from fastapi import APIRouter, HTTPException, Query++from app.models.alert import AnalystFeedback, FusedAlert, FusionDecision, RawAlertfrom app.workers.consumer import FusionWorkerrouter = APIRouter()@@ -51,3 +53,102 @@ async def trigger_retrain():raise HTTPException(status_code=503, detail="Fusion worker not ready")result = await _worker_ref.engine.ml_scorer.retrain()return result+++# ─────────────────────────────────────────────────────────────────────────────+# Risk-Based Alerting (entity rollup)+# ─────────────────────────────────────────────────────────────────────────────+++def _require_entity_risk():+ if _worker_ref is None or _worker_ref.engine is None:+ raise HTTPException(status_code=503, detail="Fusion worker not ready")+ eng = _worker_ref.engine.entity_risk+ if eng is None:+ raise HTTPException(status_code=503, detail="Entity risk engine not configured")+ if not eng.enabled:+ raise HTTPException(status_code=404, detail="Entity risk engine is disabled")+ return eng++[email protected]("/entity-risk/queue")+async def entity_risk_queue(+ tenant_id: UUID,+ limit: int = Query(default=25, ge=1, le=200),+ promoted_only: bool = False,+):+ """Return the top entities by current decayed risk score for a tenant.++ The entity-centric queue replaces the per-alert queue when RBA is+ enabled — analysts work the highest-risk entities and the contributing+ alerts are surfaced as evidence. Closes the 2026 KPI bar of+ ``alert-to-incident ratio ≥ 50:1``.+ """+ eng = _require_entity_risk()+ records = await eng.top_entities(tenant_id, limit=limit, promoted_only=promoted_only)+ return {+ "tenant_id": str(tenant_id),+ "threshold": eng.threshold,+ "entities": [r.to_dict() for r in records],+ }++[email protected]("/entity-risk/stats")+async def entity_risk_stats(tenant_id: UUID):+ """Tenant-scoped queue stats for dashboards (banding, totals, threshold)."""+ eng = _require_entity_risk()+ return {"tenant_id": str(tenant_id), **(await eng.stats(tenant_id))}++[email protected]("/entity-risk/{entity_type}/{entity_value}")+async def entity_risk_detail(entity_type: str, entity_value: str, tenant_id: UUID):+ """Return the full risk record (contributing alerts + severity histogram)+ for a single entity, used by the alert-detail drawer."""+ if entity_type == "ip":+ entity_type = "src_ip"+ eng = _require_entity_risk()+ record = await eng.get(tenant_id, entity_type, entity_value)+ if record is None:+ raise HTTPException(status_code=404, detail="entity_not_found")+ return record.to_dict()+++# ─────────────────────────────────────────────────────────────────────────────+# Detection confidence + explainability (Wave 1)+# ─────────────────────────────────────────────────────────────────────────────++[email protected]("/confidence/score")+async def score_confidence(alert: RawAlert):+ """Run an alert through the confidence + explainability scorer in+ isolation and return the rationale chain.++ This is the same ``ConfidenceScorer`` that the live fusion pipeline+ uses, exposed here so the UI / detection lab can preview a confidence+ score without round-tripping through Kafka. The scorer is pure and+ stateless — no side effects on dedup / correlation / RBA state.++ Returns the projection of the alert as a ``FusedAlert``-shaped object+ where ``confidence_label`` / ``confidence_score`` /+ ``confidence_rationale`` are populated and other downstream fields+ are left at their defaults.+ """+ if _worker_ref is None or _worker_ref.engine is None:+ raise HTTPException(status_code=503, detail="Fusion worker not ready")+ scorer = _worker_ref.engine.confidence_scorer++ fused = FusedAlert(+ id=alert.id,+ tenant_id=alert.tenant_id,+ incident_id=None,+ fusion_decision=FusionDecision.NEW_INCIDENT,+ duplicate_of=None,+ alert=alert,+ )+ scored = scorer.score(fused)+ return {+ "alert_id": str(scored.id),+ "confidence_label": scored.confidence_label.value,+ "confidence_score": scored.confidence_score,+ "rationale": [f.model_dump() for f in scored.confidence_rationale],+ }diff --git a/services/fusion/app/core/config.py b/services/fusion/app/core/config.pyindex 20e0b7150..2db20dd8a 100644--- a/services/fusion/app/core/config.py+++ b/services/fusion/app/core/config.py@@ -31,6 +31,29 @@ class Settings(BaseSettings):max_alerts_per_incident: int = Field(default=500, alias="MAX_ALERTS_PER_INCIDENT")incident_auto_close_hours: int = Field(default=72, alias="INCIDENT_AUTO_CLOSE_HOURS")+ # Risk-Based Alerting (RBA) — accumulates signals onto entities (user / host /+ # ip / domain) before promotion. Targets the published 2026 KPI bar of+ # alert-to-incident ratio ≥ 50:1.+ rba_enabled: bool = Field(default=True, alias="AISOC_FEATURE_RBA")+ rba_promotion_threshold: float = Field(default=80.0, alias="RBA_PROMOTION_THRESHOLD")+ rba_window_seconds: int = Field(default=86400, alias="RBA_WINDOW_SECONDS") # 24h decay window+ rba_decay_half_life_seconds: int = Field(+ default=14400, alias="RBA_DECAY_HALF_LIFE_SECONDS"+ ) # 4h half-life+ # Severity points contributed by each correlated alert. Keep additive and+ # capped so a single noisy detection can't promote on its own.+ rba_severity_weights_critical: float = Field(default=40.0, alias="RBA_W_CRITICAL")+ rba_severity_weights_high: float = Field(default=20.0, alias="RBA_W_HIGH")+ rba_severity_weights_medium: float = Field(default=8.0, alias="RBA_W_MEDIUM")+ rba_severity_weights_low: float = Field(default=3.0, alias="RBA_W_LOW")+ rba_severity_weights_info: float = Field(default=1.0, alias="RBA_W_INFO")+ rba_max_top_entities: int = Field(default=100, alias="RBA_MAX_TOP_ENTITIES")++ # Detection confidence + explainability — every fused alert carries a+ # high/medium/low label and an evidence chain. Disabled only as a+ # break-glass; the UI degrades gracefully (no chip / no rationale panel).+ confidence_enabled: bool = Field(default=True, alias="AISOC_FEATURE_CONFIDENCE")+# Enrichment serviceenrichment_service_url: str = Field(default="http://localhost:8082", alias="ENRICHMENT_SERVICE_URL")diff --git a/services/fusion/app/main.py b/services/fusion/app/main.pyindex eb48f6449..f2bd4bb83 100644--- a/services/fusion/app/main.py+++ b/services/fusion/app/main.py@@ -7,8 +7,10 @@ from fastapi import FastAPIfrom app.api.router import router, set_workerfrom app.core.config import settingsfrom app.core.logging import configure_logging, logger+from app.services.confidence import ConfidenceScorerfrom app.services.correlator import Correlatorfrom app.services.deduplicator import Deduplicator+from app.services.entity_risk import EntityRiskEnginefrom app.services.fusion_engine import FusionEnginefrom app.workers.consumer import FusionWorker@@ -22,7 +24,14 @@ async def lifespan(app: FastAPI):dedup = Deduplicator(redis_client)correlator = Correlator(redis_client)- engine = FusionEngine(dedup, correlator)+ entity_risk = EntityRiskEngine(redis_client)+ confidence_scorer = ConfidenceScorer(enabled=settings.confidence_enabled)+ engine = FusionEngine(+ dedup,+ correlator,+ entity_risk=entity_risk,+ confidence_scorer=confidence_scorer,+ )worker = FusionWorker(engine)set_worker(worker)diff --git a/services/fusion/app/models/alert.py b/services/fusion/app/models/alert.pyindex 34f1cba12..16a143203 100644--- a/services/fusion/app/models/alert.py+++ b/services/fusion/app/models/alert.py@@ -95,6 +95,35 @@ class RawAlert(BaseModel):return f"{self.tenant_id}:{entity}:{tactic}"+class ConfidenceLabel(str, Enum):+ """High/medium/low confidence label surfaced on every alert.++ Wave 1 of the AiSOC v6 capability roadmap — every alert ships with a+ transparent confidence label and a chain of contributing factors so the+ analyst can decide whether to action it without re-deriving the score.+ """++ HIGH = "high"+ MEDIUM = "medium"+ LOW = "low"+++class ConfidenceFactor(BaseModel):+ """One row of the explainability chain attached to a fused alert.++ The frontend renders these as a stack of evidence pills in the alert+ detail drawer. ``contribution`` is signed in [-1.0, +1.0] — positive+ increases confidence, negative decreases it. ``weight`` is the relative+ importance of the factor inside the model (sums to ~1.0 across factors).+ """++ factor: str # short machine-friendly name, e.g. "ml_anomaly"+ label: str # human-readable label, e.g. "ML anomaly score"+ value: str # observed value, e.g. "0.82" or "3 techniques"+ contribution: float = Field(ge=-1.0, le=1.0) # signed effect on confidence+ weight: float = Field(ge=0.0, le=1.0) # relative importance++class FusedAlert(BaseModel):"""Alert after fusion processing, ready for downstream consumption."""@@ -112,6 +141,14 @@ class FusedAlert(BaseModel):anomaly_score: float = 0.0 # 0.0 = normal, 1.0 = highly anomalous (Isolation Forest)priority_score: float = 0.0 # 0.0–1.0 priority rank (LightGBM ranker)+ # Detection confidence + explainability — Wave 1 of v6 roadmap.+ # ``confidence_score`` is the raw [0.0, 1.0] number used to derive the+ # human-readable ``confidence_label``. ``confidence_rationale`` is the+ # ordered evidence chain rendered in the alert detail drawer.+ confidence_label: ConfidenceLabel = ConfidenceLabel.MEDIUM+ confidence_score: float = Field(default=0.5, ge=0.0, le=1.0)+ confidence_rationale: list[ConfidenceFactor] = Field(default_factory=list)+fused_at: datetime = Field(default_factory=datetime.utcnow)diff --git a/services/fusion/app/services/confidence.py b/services/fusion/app/services/confidence.pynew file mode 100644index 000000000..429654cb2--- /dev/null+++ b/services/fusion/app/services/confidence.py@@ -0,0 +1,302 @@+"""+Detection confidence + explainability surface.++Wave 1 of the AiSOC v6 capability roadmap. Every fused alert leaves the+fusion service with a high/medium/low confidence label and an ordered+evidence chain (``ConfidenceFactor[]``) that the UI renders in the alert+detail drawer. The label is **derived**, not assigned — analysts can+reproduce the score from the rationale alone.++Contribution model+==================++The score lives in [0.0, 1.0]. Each factor contributes a signed amount in+[-1.0, +1.0] weighted by its relative importance. The final score is++ score = sum(w_i * c_i) + 0.5++clamped to [0, 1]. Bands map to labels:++ score ≥ 0.70 → HIGH (action this without further verification)+ 0.40–0.70 → MEDIUM (analyst review recommended)+ score < 0.40 → LOW (likely noise, suppress or downgrade)++Factors and weights+-------------------++================== ====== ==========================================+factor w signal+================== ====== ==========================================+severity 0.20 alert severity (critical / high / med / low)+ml_anomaly 0.18 IsolationForest anomaly_score (0–1)+ml_priority 0.18 LightGBM priority_score (0–1)+mitre_coverage 0.14 number of mapped MITRE techniques+threat_intel 0.16 enrichment hits (TI feed match)+upstream_risk 0.08 raw_alert.risk_score (0–1, vendor-provided)+ioc_density 0.06 distinct populated IOC fields+================== ====== ==========================================++Sum of weights = 1.0. The factor list is *also* what's persisted on the+``FusedAlert`` so the UI can render the same evidence chain that the+score was derived from — no magic numbers.++AiSOC — open-source AI Security Operations Center (MIT License)+"""++from __future__ import annotations++import structlog++from app.models.alert import (+ AlertSeverity,+ ConfidenceFactor,+ ConfidenceLabel,+ FusedAlert,+)++logger = structlog.get_logger()+++# ─── Constants ───────────────────────────────────────────────────────────────++# Score bands → label. Tuned so that "high" requires multiple positive+# signals together (severity alone is not enough) and "low" is reserved for+# alerts whose rationale is mostly noise.+HIGH_THRESHOLD = 0.70+LOW_THRESHOLD = 0.40++# Factor weights — keep summing to 1.0 if you tweak.+WEIGHT_SEVERITY = 0.20+WEIGHT_ML_ANOMALY = 0.18+WEIGHT_ML_PRIORITY = 0.18+WEIGHT_MITRE = 0.14+WEIGHT_THREAT_INTEL = 0.16+WEIGHT_UPSTREAM_RISK = 0.08+WEIGHT_IOC_DENSITY = 0.06++_SEVERITY_CONTRIBUTION = {+ AlertSeverity.CRITICAL: 1.0,+ AlertSeverity.HIGH: 0.6,+ AlertSeverity.MEDIUM: 0.0,+ AlertSeverity.LOW: -0.5,+ AlertSeverity.INFO: -1.0,+}+++# ─── Helpers ─────────────────────────────────────────────────────────────────+++def _band(score: float) -> ConfidenceLabel:+ if score >= HIGH_THRESHOLD:+ return ConfidenceLabel.HIGH+ if score < LOW_THRESHOLD:+ return ConfidenceLabel.LOW+ return ConfidenceLabel.MEDIUM+++def _ml_contribution(value: float) -> float:+ """ML scores are already in [0, 1]. Centre on 0.5 → contribution in [-1, +1]."""+ return max(-1.0, min(1.0, (value - 0.5) * 2.0))+++def _mitre_contribution(num_techniques: int) -> float:+ """0 techniques → mild negative; 1 → neutral; 3+ → strongly positive."""+ if num_techniques == 0:+ return -0.4+ if num_techniques == 1:+ return 0.0+ if num_techniques == 2:+ return 0.4+ return min(1.0, 0.4 + (num_techniques - 2) * 0.2)+++def _ti_contribution(enrichments: dict | None) -> tuple[float, str]:+ """Threat-intel hits are the strongest binary signal we have."""+ if not enrichments:+ return -0.3, "no TI match"+ hits = 0+ sources: list[str] = []+ for source in ("misp", "otx", "taxii", "kev", "virustotal"):+ match = enrichments.get(source)+ if isinstance(match, dict) and (match.get("hit") or match.get("matches")):+ hits += 1+ sources.append(source.upper())+ elif isinstance(match, list) and match:+ hits += 1+ sources.append(source.upper())+ if hits == 0:+ return -0.3, "no TI match"+ if hits == 1:+ return 0.6, sources[0]+ return 1.0, " + ".join(sources)+++def _ioc_density_contribution(alert) -> tuple[float, int]:+ """More populated IOC fields → more concrete signal."""+ fields = [+ alert.src_ip,+ alert.dst_ip,+ alert.hostname,+ alert.username,+ alert.file_hash,+ alert.domain,+ alert.url,+ ]+ populated = sum(1 for f in fields if f)+ if populated == 0:+ contribution = -0.6+ elif populated <= 2:+ contribution = 0.0+ elif populated <= 4:+ contribution = 0.5+ else:+ contribution = 1.0+ return contribution, populated+++# ─── ConfidenceScorer ────────────────────────────────────────────────────────+++class ConfidenceScorer:+ """Pure, stateless scorer — safe to share across requests.++ The contract is intentionally synchronous: confidence is a *projection*+ of values already present on the ``FusedAlert``, not an asynchronous+ enrichment step. If new signals are added (e.g. UEBA z-score, RBA+ entity score) extend ``score`` and add a row to the rationale.++ The scorer carries an ``enabled`` flag so the capability can be feature-+ flagged at the deployment level (``AISOC_FEATURE_CONFIDENCE``) without+ having to pass ``None`` through the pipeline. When disabled, ``score``+ returns the alert unchanged — the model defaults (MEDIUM / 0.5 / [])+ keep the API and UI rendering safely.+ """++ def __init__(self, enabled: bool = True) -> None:+ self._enabled = enabled++ @property+ def enabled(self) -> bool:+ return self._enabled++ def score(self, fused: FusedAlert) -> FusedAlert:+ if not self._enabled:+ # Break-glass path. Leave the model defaults in place so the+ # frontend can degrade gracefully (no chip, no rationale panel)+ # without raising on missing fields.+ return fused++ """Attach ``confidence_label`` / ``confidence_score`` /+ ``confidence_rationale`` to the fused alert and return it."""+ alert = fused.alert+ rationale: list[ConfidenceFactor] = []++ # 1. Severity+ sev_contribution = _SEVERITY_CONTRIBUTION.get(alert.severity, 0.0)+ rationale.append(+ ConfidenceFactor(+ factor="severity",+ label="Alert severity",+ value=alert.severity.value if hasattr(alert.severity, "value") else str(alert.severity),+ contribution=sev_contribution,+ weight=WEIGHT_SEVERITY,+ )+ )++ # 2. ML anomaly score+ anomaly_contribution = _ml_contribution(fused.anomaly_score)+ rationale.append(+ ConfidenceFactor(+ factor="ml_anomaly",+ label="ML anomaly score",+ value=f"{fused.anomaly_score:.2f}",+ contribution=anomaly_contribution,+ weight=WEIGHT_ML_ANOMALY,+ )+ )++ # 3. ML priority score+ priority_contribution = _ml_contribution(fused.priority_score)+ rationale.append(+ ConfidenceFactor(+ factor="ml_priority",+ label="ML priority rank",+ value=f"{fused.priority_score:.2f}",+ contribution=priority_contribution,+ weight=WEIGHT_ML_PRIORITY,+ )+ )++ # 4. MITRE coverage+ n_tech = len(alert.mitre_techniques)+ mitre_contribution = _mitre_contribution(n_tech)+ rationale.append(+ ConfidenceFactor(+ factor="mitre_coverage",+ label="MITRE technique coverage",+ value=f"{n_tech} techniques" if n_tech != 1 else "1 technique",+ contribution=mitre_contribution,+ weight=WEIGHT_MITRE,+ )+ )++ # 5. Threat-intel+ ti_contribution, ti_value = _ti_contribution(fused.enrichments)+ rationale.append(+ ConfidenceFactor(+ factor="threat_intel",+ label="Threat-intel match",+ value=ti_value,+ contribution=ti_contribution,+ weight=WEIGHT_THREAT_INTEL,+ )+ )++ # 6. Upstream vendor risk score+ upstream = max(0.0, min(1.0, alert.risk_score or 0.0))+ upstream_contribution = _ml_contribution(upstream)+ rationale.append(+ ConfidenceFactor(+ factor="upstream_risk",+ label="Upstream vendor risk score",+ value=f"{upstream:.2f}",+ contribution=upstream_contribution,+ weight=WEIGHT_UPSTREAM_RISK,+ )+ )++ # 7. IOC density+ ioc_contribution, populated = _ioc_density_contribution(alert)+ rationale.append(+ ConfidenceFactor(+ factor="ioc_density",+ label="IOC density",+ value=f"{populated} populated fields",+ contribution=ioc_contribution,+ weight=WEIGHT_IOC_DENSITY,+ )+ )++ # Combine: score = 0.5 + Σ(w_i * c_i), clamped to [0, 1]+ delta = sum(f.contribution * f.weight for f in rationale)+ # Map [-0.5, +0.5] possible range onto a full [0, 1] using the same+ # sigmoid-like recentring; the test suite verifies the bands.+ raw = 0.5 + delta+ score = max(0.0, min(1.0, raw))+ label = _band(score)++ fused.confidence_score = round(score, 4)+ fused.confidence_label = label+ # Sort rationale by absolute contribution, descending — UI shows the+ # most-impactful evidence first.+ fused.confidence_rationale = sorted(+ rationale, key=lambda f: abs(f.contribution * f.weight), reverse=True+ )++ logger.debug(+ "confidence_scored",+ alert_id=str(fused.id),+ label=label.value,+ score=fused.confidence_score,+ )+ return fuseddiff --git a/services/fusion/app/services/entity_risk.py b/services/fusion/app/services/entity_risk.pynew file mode 100644index 000000000..7c7d990c9--- /dev/null+++ b/services/fusion/app/services/entity_risk.py@@ -0,0 +1,368 @@+"""+Risk-Based Alerting (RBA) — entity rollup with time-decayed risk scores.++The Splunk-pioneered RBA pattern: alerts contribute *points* to the entities+they touch (user, host, src_ip, domain). Points decay exponentially with a+half-life so stale signal naturally drops out. Once an entity's score crosses+``rba_promotion_threshold`` AiSOC promotes the entity to an incident with the+contributing alerts attached — and the entity-centric queue surfaces the+top-N highest-risk entities to the analyst, not raw alerts.++Why entity-first+----------------+The 2026 buyer-side scoring bar mandates ``alert-to-incident ratio ≥ 50:1``+(SANS 2025 + AI-SOC 30-item checklist). Per-alert correlation alone caps+collapse at the entity boundary; entity-rollup compounds across detections+so one user with five medium signals lands above one with a single+high-severity false positive.++Storage+-------+Redis hashes per entity, namespaced by tenant. Cheap, atomic, and TTLs match+``rba_window_seconds`` so cold entities self-evict. Two ZSETs keep top-N+entities sorted (by score, by last_seen) for O(log N) queue reads. All+keys are RLS-safe because the tenant_id is part of the key prefix and the+API service re-checks tenant on read.+"""++from __future__ import annotations++import json+import math+import time+from dataclasses import dataclass+from datetime import datetime+from uuid import UUID++import redis.asyncio as aioredis+import structlog++from app.core.config import settings+from app.models.alert import AlertSeverity, RawAlert++logger = structlog.get_logger()++# Key layout (all prefixed by tenant for RLS at the cache layer):+# aisoc:fusion:rba:entity:{tenant}:{entity_type}:{entity_value} → hash+# aisoc:fusion:rba:topn:{tenant} → zset (score)+# aisoc:fusion:rba:promoted:{tenant} → zset (last seen)+_ENTITY_PREFIX = "aisoc:fusion:rba:entity:"+_TOPN_KEY = "aisoc:fusion:rba:topn:"+_PROMOTED_KEY = "aisoc:fusion:rba:promoted:"++ENTITY_TYPES: tuple[str, ...] = ("user", "host", "src_ip", "domain")+++@dataclass(frozen=True)+class EntitySignal:+ """A single alert's contribution to one entity."""++ entity_type: str+ entity_value: str+ points: float+ alert_id: str+ severity: str+ detection: str+ occurred_at: datetime+++@dataclass+class EntityRiskRecord:+ """The current decayed risk picture for one entity."""++ tenant_id: str+ entity_type: str+ entity_value: str+ score: float+ alert_count: int+ last_seen: datetime+ contributing_alerts: list[str]+ severities: dict[str, int]+ promoted_at: datetime | None+ contributors: list[dict] | None = None++ def to_dict(self) -> dict:+ return {+ "tenant_id": self.tenant_id,+ "entity_type": self.entity_type,+ "entity_value": self.entity_value,+ "score": round(self.score, 2),+ "alert_count": self.alert_count,+ "last_seen": self.last_seen.isoformat() + "Z",+ "contributing_alerts": self.contributing_alerts,+ "severities": self.severities,+ "promoted_at": (self.promoted_at.isoformat() + "Z") if self.promoted_at else None,+ "contributors": self.contributors or [],+ }+++class EntityRiskEngine:+ """Time-decaying entity risk accumulator + entity-centric queue."""++ def __init__(self, redis_client: aioredis.Redis) -> None:+ self._redis = redis_client+ self._enabled = settings.rba_enabled+ self._threshold = settings.rba_promotion_threshold+ self._window = settings.rba_window_seconds+ self._half_life = max(60, settings.rba_decay_half_life_seconds)+ self._max_top = max(10, settings.rba_max_top_entities)+ self._weights: dict[AlertSeverity, float] = {+ AlertSeverity.CRITICAL: settings.rba_severity_weights_critical,+ AlertSeverity.HIGH: settings.rba_severity_weights_high,+ AlertSeverity.MEDIUM: settings.rba_severity_weights_medium,+ AlertSeverity.LOW: settings.rba_severity_weights_low,+ AlertSeverity.INFO: settings.rba_severity_weights_info,+ }++ @property+ def enabled(self) -> bool:+ return self._enabled++ @property+ def threshold(self) -> float:+ return self._threshold++ # ------------------------------------------------------------------+ # Ingest path+ # ------------------------------------------------------------------+ async def observe(self, alert: RawAlert) -> list[EntityRiskRecord]:+ """+ Apply ``alert`` against every entity it touches.++ Returns the list of entity records that crossed the promotion+ threshold *as a result of this alert*. The fusion engine uses the+ return value to log promotions and emit downstream signals.+ """+ if not self._enabled:+ return []++ signals = self._build_signals(alert)+ if not signals:+ return []++ promoted: list[EntityRiskRecord] = []+ for sig in signals:+ record = await self._apply_signal(alert.tenant_id, sig)+ if record.score >= self._threshold and record.promoted_at is None:+ record = await self._promote(alert.tenant_id, record)+ promoted.append(record)++ return promoted++ # ------------------------------------------------------------------+ # Read path+ # ------------------------------------------------------------------+ async def top_entities(+ self,+ tenant_id: UUID | str,+ *,+ limit: int = 25,+ promoted_only: bool = False,+ ) -> list[EntityRiskRecord]:+ """Return the top-N entities by current decayed score."""+ key = _TOPN_KEY + str(tenant_id)+ raw = await self._redis.zrevrange(key, 0, max(0, limit - 1), withscores=True)+ records: list[EntityRiskRecord] = []+ for member, _zscore in raw:+ entity = member.decode() if isinstance(member, (bytes, bytearray)) else member+ entity_type, _, entity_value = entity.partition("::")+ rec = await self._load(str(tenant_id), entity_type, entity_value)+ if rec is None:+ continue+ if promoted_only and rec.promoted_at is None:+ continue+ records.append(rec)+ return records++ async def get(+ self, tenant_id: UUID | str, entity_type: str, entity_value: str+ ) -> EntityRiskRecord | None:+ return await self._load(str(tenant_id), entity_type, entity_value)++ async def stats(self, tenant_id: UUID | str) -> dict:+ """Return queue-level metrics for the dashboard."""+ topn_key = _TOPN_KEY + str(tenant_id)+ promoted_key = _PROMOTED_KEY + str(tenant_id)+ total = await self._redis.zcard(topn_key)+ promoted = await self._redis.zcard(promoted_key)+ # Score histogram (≥80, 50–80, 20–50, <20).+ bands = {"critical": 0, "high": 0, "medium": 0, "low": 0}+ members = await self._redis.zrevrange(topn_key, 0, self._max_top - 1, withscores=True)+ for _m, score in members:+ if score >= 80:+ bands["critical"] += 1+ elif score >= 50:+ bands["high"] += 1+ elif score >= 20:+ bands["medium"] += 1+ else:+ bands["low"] += 1+ return {+ "tracked_entities": total,+ "promoted_entities": promoted,+ "score_bands": bands,+ "threshold": self._threshold,+ }++ # ------------------------------------------------------------------+ # Internals+ # ------------------------------------------------------------------+ def _build_signals(self, alert: RawAlert) -> list[EntitySignal]:+ weight = self._weights.get(alert.severity, self._weights[AlertSeverity.MEDIUM])+ # Detection-confidence boost: higher upstream risk_score amplifies points.+ confidence_factor = 1.0 + min(max(alert.risk_score, 0.0), 1.0)+ points = round(weight * confidence_factor, 2)+ detection = alert.title or alert.source+ occurred = alert.event_time or alert.created_at++ candidates: list[tuple[str, str | None]] = [+ ("user", alert.username),+ ("host", alert.hostname),+ ("src_ip", alert.src_ip),+ ("domain", alert.domain),+ ]+ signals: list[EntitySignal] = []+ for entity_type, value in candidates:+ if not value:+ continue+ signals.append(+ EntitySignal(+ entity_type=entity_type,+ entity_value=str(value),+ points=points,+ alert_id=str(alert.id),+ severity=alert.severity.value,+ detection=detection,+ occurred_at=occurred,+ )+ )+ return signals++ async def _apply_signal(self, tenant_id: UUID, sig: EntitySignal) -> EntityRiskRecord:+ record = await self._load(str(tenant_id), sig.entity_type, sig.entity_value)+ now = datetime.utcnow()++ if record is None:+ record = EntityRiskRecord(+ tenant_id=str(tenant_id),+ entity_type=sig.entity_type,+ entity_value=sig.entity_value,+ score=0.0,+ alert_count=0,+ last_seen=now,+ contributing_alerts=[],+ severities={},+ promoted_at=None,+ contributors=[],+ )++ record.score = self._decay(record.score, record.last_seen, now) + sig.points+ record.alert_count += 1+ record.last_seen = now+ if sig.alert_id not in record.contributing_alerts:+ record.contributing_alerts.append(sig.alert_id)+ # Cap contributing list to keep payload small in the queue UI.+ if len(record.contributing_alerts) > 50:+ record.contributing_alerts = record.contributing_alerts[-50:]+ record.severities[sig.severity] = record.severities.get(sig.severity, 0) + 1+ contributors = record.contributors or []+ contributors.append(+ {+ "alert_id": sig.alert_id,+ "severity": sig.severity,+ "detection": sig.detection,+ "points": sig.points,+ "at": sig.occurred_at.isoformat() + "Z",+ }+ )+ if len(contributors) > 25:+ contributors = contributors[-25:]+ record.contributors = contributors++ await self._save(record)+ return record++ def _decay(self, prior: float, prior_seen: datetime, now: datetime) -> float:+ if prior <= 0:+ return 0.0+ elapsed = max(0.0, (now - prior_seen).total_seconds())+ if elapsed <= 0:+ return prior+ decay = math.pow(0.5, elapsed / float(self._half_life))+ decayed = prior * decay+ return decayed if decayed > 0.05 else 0.0++ async def _promote(self, tenant_id: UUID, record: EntityRiskRecord) -> EntityRiskRecord:+ record.promoted_at = datetime.utcnow()+ await self._save(record)+ promoted_key = _PROMOTED_KEY + str(tenant_id)+ await self._redis.zadd(promoted_key, {self._member(record): time.time()})+ await self._redis.expire(promoted_key, self._window)+ logger.info(+ "rba_entity_promoted",+ tenant_id=str(tenant_id),+ entity_type=record.entity_type,+ entity_value=record.entity_value,+ score=round(record.score, 2),+ alert_count=record.alert_count,+ contributing_alerts=record.contributing_alerts[-10:],+ )+ return record++ @staticmethod+ def _member(record: EntityRiskRecord) -> str:+ return f"{record.entity_type}::{record.entity_value}"++ async def _save(self, record: EntityRiskRecord) -> None:+ key = _ENTITY_PREFIX + f"{record.tenant_id}:{record.entity_type}:{record.entity_value}"+ payload = {+ "score": str(record.score),+ "alert_count": str(record.alert_count),+ "last_seen": record.last_seen.isoformat(),+ "contributing_alerts": json.dumps(record.contributing_alerts),+ "severities": json.dumps(record.severities),+ "promoted_at": record.promoted_at.isoformat() if record.promoted_at else "",+ "contributors": json.dumps(record.contributors or []),+ }+ await self._redis.hset(key, mapping=payload)+ await self._redis.expire(key, self._window)+ topn_key = _TOPN_KEY + record.tenant_id+ await self._redis.zadd(topn_key, {self._member(record): record.score})+ await self._redis.zremrangebyrank(topn_key, 0, -(self._max_top + 1))+ await self._redis.expire(topn_key, self._window)++ async def _load(+ self, tenant_id: str, entity_type: str, entity_value: str+ ) -> EntityRiskRecord | None:+ key = _ENTITY_PREFIX + f"{tenant_id}:{entity_type}:{entity_value}"+ data = await self._redis.hgetall(key)+ if not data:+ return None+ decoded = {+ (k.decode() if isinstance(k, (bytes, bytearray)) else k): (+ v.decode() if isinstance(v, (bytes, bytearray)) else v+ )+ for k, v in data.items()+ }+ promoted_at = None+ if decoded.get("promoted_at"):+ try:+ promoted_at = datetime.fromisoformat(decoded["promoted_at"])+ except ValueError:+ promoted_at = None+ try:+ last_seen = datetime.fromisoformat(decoded["last_seen"])+ except (KeyError, ValueError):+ last_seen = datetime.utcnow()+ return EntityRiskRecord(+ tenant_id=tenant_id,+ entity_type=entity_type,+ entity_value=entity_value,+ score=float(decoded.get("score", "0")),+ alert_count=int(decoded.get("alert_count", "0")),+ last_seen=last_seen,+ contributing_alerts=json.loads(decoded.get("contributing_alerts", "[]")),+ severities=json.loads(decoded.get("severities", "{}")),+ promoted_at=promoted_at,+ contributors=json.loads(decoded.get("contributors", "[]")),+ )diff --git a/services/fusion/app/services/fusion_engine.py b/services/fusion/app/services/fusion_engine.pyindex bfedd6554..932257d95 100644--- a/services/fusion/app/services/fusion_engine.py+++ b/services/fusion/app/services/fusion_engine.py@@ -9,8 +9,10 @@ from uuid import UUIDimport structlogfrom app.models.alert import FusedAlert, FusionDecision, RawAlert+from app.services.confidence import ConfidenceScorerfrom app.services.correlator import Correlatorfrom app.services.deduplicator import Deduplicator+from app.services.entity_risk import EntityRiskEnginefrom app.services.ml_scorer import MLScorerlogger = structlog.get_logger()@@ -24,10 +26,17 @@ class FusionEngine:deduplicator: Deduplicator,correlator: Correlator,ml_scorer: MLScorer | None = None,+ entity_risk: EntityRiskEngine | None = None,+ confidence_scorer: ConfidenceScorer | None = None,) -> None:self._dedup = deduplicatorself._correlator = correlatorself._ml_scorer = ml_scorer or MLScorer()+ self._entity_risk = entity_risk+ # Confidence + explainability is intrinsic to a fused alert — every+ # alert leaves the engine with a high/med/low label and an evidence+ # chain. The scorer is pure / stateless so we instantiate a default.+ self._confidence_scorer = confidence_scorer or ConfidenceScorer()async def process(self, alert: RawAlert) -> FusedAlert:"""@@ -78,6 +87,33 @@ class FusionEngine:except Exception as exc:logger.warning("ML scoring failed; using defaults", error=str(exc))+ # --- Step 3b: Detection confidence + explainability ---+ # Pure, synchronous projection of the values already on ``fused``.+ # Runs after ML scoring so the rationale picks up anomaly / priority.+ try:+ fused = self._confidence_scorer.score(fused)+ except Exception as exc:+ logger.warning("confidence_scoring_failed", error=str(exc))++ # --- Step 4: Risk-Based Alerting (entity rollup) ---+ # RBA accumulates points on the entities this alert touches and may+ # promote one or more of them to an entity-incident. Failures here+ # never block the alert pipeline — RBA is additive signal, not+ # the primary correlation path.+ if self._entity_risk is not None and self._entity_risk.enabled:+ try:+ promotions = await self._entity_risk.observe(alert)+ if promotions:+ logger.info(+ "rba_promotions",+ alert_id=str(alert.id),+ promoted=[+ f"{p.entity_type}:{p.entity_value}" for p in promotions+ ],+ )+ except Exception as exc:+ logger.warning("rba_observation_failed", error=str(exc))+logger.info("Alert fusion complete",alert_id=str(alert.id),@@ -86,6 +122,7 @@ class FusionEngine:incident_alert_count=incident.alert_count,anomaly_score=fused.anomaly_score,priority_score=fused.priority_score,+ confidence=fused.confidence_label.value,)return fused@@ -93,3 +130,11 @@ class FusionEngine:@propertydef ml_scorer(self) -> MLScorer:return self._ml_scorer++ @property+ def entity_risk(self) -> EntityRiskEngine | None:+ return self._entity_risk++ @property+ def confidence_scorer(self) -> ConfidenceScorer:+ return self._confidence_scorerdiff --git a/services/fusion/tests/conftest.py b/services/fusion/tests/conftest.pynew file mode 100644index 000000000..201f2824f--- /dev/null+++ b/services/fusion/tests/conftest.py@@ -0,0 +1,22 @@+"""+Pytest config for the fusion service test suite.++Sets ``asyncio_mode = auto`` so the ``@pytest.mark.asyncio`` decorators in+``test_entity_risk.py`` resolve without per-test event-loop boilerplate. The+existing ``test_alert_model.py`` is sync and unaffected.+"""++from __future__ import annotations++import pytest+++def pytest_collection_modifyitems(items):+ # Apply asyncio mark to every coroutine test function — keeps the suite+ # working without a [tool.pytest.ini_options] block in pyproject.toml.+ for item in items:+ if isinstance(item, pytest.Function) and item.get_closest_marker("asyncio") is None:+ if callable(item.function):+ import asyncio+ if asyncio.iscoroutinefunction(item.function):+ item.add_marker(pytest.mark.asyncio)diff --git a/services/fusion/tests/test_confidence.py b/services/fusion/tests/test_confidence.pynew file mode 100644index 000000000..ec5528b37--- /dev/null+++ b/services/fusion/tests/test_confidence.py@@ -0,0 +1,331 @@+"""+Tests for the detection-confidence + explainability scorer.++Wave 1 contract:++* every fused alert leaves the engine with a ``confidence_label`` of+ high / medium / low **and** a non-empty ``confidence_rationale``+ containing the factors that produced the score;+* the rationale is reproducible — the same input always produces the same+ score and the same ordering of factors;+* "high confidence" requires multiple positive signals (severity alone is+ not enough to clear the bar) so the analyst can trust the label;+* "low confidence" reliably surfaces the weak / suspicious / informational+ alerts so the queue stays clean.+"""++from __future__ import annotations++from uuid import uuid4++import pytest+from app.models.alert import (+ AlertSeverity,+ ConfidenceLabel,+ FusedAlert,+ FusionDecision,+ RawAlert,+)+from app.services.confidence import (+ HIGH_THRESHOLD,+ LOW_THRESHOLD,+ ConfidenceScorer,+)++# ─── Helpers ─────────────────────────────────────────────────────────────────+++def _alert(+ *,+ severity: AlertSeverity = AlertSeverity.MEDIUM,+ techniques: list[str] | None = None,+ risk_score: float = 0.0,+ src_ip: str | None = None,+ dst_ip: str | None = None,+ hostname: str | None = None,+ username: str | None = None,+ file_hash: str | None = None,+ domain: str | None = None,+ url: str | None = None,+) -> RawAlert:+ return RawAlert(+ tenant_id=uuid4(),+ source="unit-test",+ title="Test alert",+ severity=severity,+ mitre_techniques=techniques or [],+ risk_score=risk_score,+ src_ip=src_ip,+ dst_ip=dst_ip,+ hostname=hostname,+ username=username,+ file_hash=file_hash,+ domain=domain,+ url=url,+ )+++def _fused(+ alert: RawAlert,+ *,+ anomaly_score: float = 0.0,+ priority_score: float = 0.0,+ enrichments: dict | None = None,+) -> FusedAlert:+ return FusedAlert(+ id=alert.id,+ tenant_id=alert.tenant_id,+ incident_id=uuid4(),+ fusion_decision=FusionDecision.NEW_INCIDENT,+ alert=alert,+ anomaly_score=anomaly_score,+ priority_score=priority_score,+ enrichments=enrichments or {},+ )+++def scorer() -> ConfidenceScorer:+ return ConfidenceScorer()+++# ─── Rationale shape ─────────────────────────────────────────────────────────+++def test_score_attaches_complete_rationale(scorer: ConfidenceScorer) -> None:+ """Every alert leaves the scorer with a non-empty rationale chain+ that names every weighted factor — no silent drops."""+ fused = _fused(_alert())+ scored = scorer.score(fused)+ factors = {f.factor for f in scored.confidence_rationale}+ assert factors == {+ "severity",+ "ml_anomaly",+ "ml_priority",+ "mitre_coverage",+ "threat_intel",+ "upstream_risk",+ "ioc_density",+ }+++def test_rationale_is_sorted_by_impact(scorer: ConfidenceScorer) -> None:+ """The UI renders the rationale top-down, so the most impactful+ factor must come first."""+ fused = _fused(+ _alert(+ severity=AlertSeverity.CRITICAL,+ techniques=["T1078", "T1098", "T1556"],+ src_ip="10.0.0.1",+ hostname="prod-1",+ username="alice",+ ),+ anomaly_score=0.95,+ priority_score=0.95,+ enrichments={"misp": {"hit": True}, "kev": {"matches": ["CVE-2024-1234"]}},+ )+ scored = scorer.score(fused)+ impacts = [abs(f.contribution * f.weight) for f in scored.confidence_rationale]+ assert impacts == sorted(impacts, reverse=True)+++def test_rationale_weights_sum_to_one(scorer: ConfidenceScorer) -> None:+ """Weights are the model's *relative importance*; they must sum to 1.0+ so that a 100%-positive contribution maps to a full +0.5 delta."""+ scored = scorer.score(_fused(_alert()))+ total = sum(f.weight for f in scored.confidence_rationale)+ assert total == pytest.approx(1.0, abs=1e-6)+++def test_score_is_deterministic(scorer: ConfidenceScorer) -> None:+ """Same input → identical score and rationale ordering. The rationale+ is reproducible audit evidence."""+ alert = _alert(severity=AlertSeverity.HIGH, techniques=["T1078"])+ a = scorer.score(_fused(alert, anomaly_score=0.7, priority_score=0.6))+ b = scorer.score(_fused(alert, anomaly_score=0.7, priority_score=0.6))+ assert a.confidence_score == b.confidence_score+ assert a.confidence_label == b.confidence_label+ assert [f.factor for f in a.confidence_rationale] == [+ f.factor for f in b.confidence_rationale+ ]+++# ─── Banding ─────────────────────────────────────────────────────────────────+++def test_high_confidence_requires_multiple_positive_signals(scorer: ConfidenceScorer) -> None:+ """Severity alone must NOT clear the HIGH threshold — the whole point+ of the explainability surface is that "critical" without supporting+ evidence is a noisy detection, not a confident one."""+ bare = _fused(_alert(severity=AlertSeverity.CRITICAL))+ scored = scorer.score(bare)+ assert scored.confidence_label != ConfidenceLabel.HIGH+++def test_high_confidence_with_strong_corroborating_signals(scorer: ConfidenceScorer) -> None:+ """Critical severity + strong ML scores + MITRE coverage + TI hit + IOCs+ must produce HIGH confidence. This is the "ship it" path."""+ fused = _fused(+ _alert(+ severity=AlertSeverity.CRITICAL,+ techniques=["T1078", "T1098", "T1556"],+ risk_score=0.9,+ src_ip="10.0.0.1",+ dst_ip="8.8.8.8",+ hostname="prod-1",+ username="alice",+ file_hash="abc123",+ ),+ anomaly_score=0.92,+ priority_score=0.95,+ enrichments={+ "misp": {"hit": True},+ "otx": {"hit": True},+ "kev": {"matches": ["CVE-2024-1234"]},+ },+ )+ scored = scorer.score(fused)+ assert scored.confidence_label == ConfidenceLabel.HIGH+ assert scored.confidence_score >= HIGH_THRESHOLD+++def test_low_confidence_for_info_severity_with_no_signals(scorer: ConfidenceScorer) -> None:+ """An info-severity alert with no MITRE coverage, no TI hit, no IOCs,+ and zero ML scores belongs in the low-confidence band — that's the+ "suppress or downgrade" lane."""+ fused = _fused(_alert(severity=AlertSeverity.INFO))+ scored = scorer.score(fused)+ assert scored.confidence_label == ConfidenceLabel.LOW+ assert scored.confidence_score < LOW_THRESHOLD+++def test_medium_confidence_for_balanced_signal(scorer: ConfidenceScorer) -> None:+ """High severity + two techniques + a couple IOCs + reasonable ML+ scores but **no TI hit** must land in MEDIUM. This is the most+ realistic real-world detection — looks suspicious but missing the+ last bit of corroborating evidence to auto-action."""+ fused = _fused(+ _alert(+ severity=AlertSeverity.HIGH,+ techniques=["T1078", "T1098"],+ src_ip="10.0.0.1",+ hostname="prod-1",+ ),+ anomaly_score=0.6,+ priority_score=0.55,+ )+ scored = scorer.score(fused)+ assert scored.confidence_label == ConfidenceLabel.MEDIUM+ assert LOW_THRESHOLD <= scored.confidence_score < HIGH_THRESHOLD+++# ─── Individual factors ──────────────────────────────────────────────────────+++def test_threat_intel_hit_increases_score(scorer: ConfidenceScorer) -> None:+ """A TI hit must monotonically increase confidence relative to the+ same alert without one — that's the whole point of enrichment."""+ base = _alert(severity=AlertSeverity.HIGH, techniques=["T1078"], src_ip="10.0.0.1")++ no_ti = scorer.score(_fused(base, anomaly_score=0.6, priority_score=0.6))+ with_ti = scorer.score(+ _fused(+ base,+ anomaly_score=0.6,+ priority_score=0.6,+ enrichments={"misp": {"hit": True}},+ )+ )+ assert with_ti.confidence_score > no_ti.confidence_score+++def test_mitre_coverage_increases_score(scorer: ConfidenceScorer) -> None:+ """More MITRE techniques → more confident detection. Three techniques+ must beat zero, all else equal."""+ sparse = _fused(+ _alert(severity=AlertSeverity.HIGH, src_ip="10.0.0.1"),+ anomaly_score=0.5,+ priority_score=0.5,+ )+ rich = _fused(+ _alert(+ severity=AlertSeverity.HIGH,+ techniques=["T1078", "T1098", "T1556"],+ src_ip="10.0.0.1",+ ),+ anomaly_score=0.5,+ priority_score=0.5,+ )+ assert scorer.score(rich).confidence_score > scorer.score(sparse).confidence_score+++def test_ioc_density_increases_score(scorer: ConfidenceScorer) -> None:+ """More populated IOC fields → more concrete signal → higher score.+ Five IOC fields must beat zero, all else equal."""+ sparse = _fused(_alert(severity=AlertSeverity.MEDIUM, techniques=["T1078"]))+ rich = _fused(+ _alert(+ severity=AlertSeverity.MEDIUM,+ techniques=["T1078"],+ src_ip="10.0.0.1",+ dst_ip="8.8.8.8",+ hostname="prod-1",+ username="alice",+ file_hash="abc123",+ )+ )+ assert scorer.score(rich).confidence_score > scorer.score(sparse).confidence_score+++# ─── Feature flag (break-glass) ──────────────────────────────────────────────+++def test_disabled_scorer_passes_alert_through_unchanged() -> None:+ """When ``AISOC_FEATURE_CONFIDENCE`` is off the scorer must be a no-op:+ the alert keeps the FusedAlert defaults (MEDIUM / 0.5 / []) so the+ frontend degrades gracefully and downstream consumers never see a+ half-populated rationale."""+ disabled = ConfidenceScorer(enabled=False)+ assert disabled.enabled is False++ fused = _fused(+ _alert(severity=AlertSeverity.CRITICAL, techniques=["T1078"]),+ anomaly_score=0.95,+ priority_score=0.95,+ enrichments={"misp": {"hit": True}},+ )+ scored = disabled.score(fused)++ # Same instance back; we explicitly do NOT compute a rationale when off.+ assert scored is fused+ assert scored.confidence_label == ConfidenceLabel.MEDIUM+ assert scored.confidence_score == 0.5+ assert scored.confidence_rationale == []+++def test_score_clamped_to_unit_interval(scorer: ConfidenceScorer) -> None:+ """Score must always live in [0, 1] no matter how many signals fire."""+ extreme = _fused(+ _alert(+ severity=AlertSeverity.CRITICAL,+ techniques=["T1078", "T1098", "T1556", "T1110", "T1003"],+ risk_score=1.0,+ src_ip="10.0.0.1",+ dst_ip="8.8.8.8",+ hostname="prod-1",+ username="alice",+ file_hash="abc123",+ domain="evil.example",+ url="https://evil.example/payload",+ ),+ anomaly_score=1.0,+ priority_score=1.0,+ enrichments={+ "misp": {"hit": True},+ "otx": {"hit": True},+ "kev": {"matches": ["CVE-2024-1234"]},+ "virustotal": {"hit": True},+ },+ )+ scored = scorer.score(extreme)+ assert 0.0 <= scored.confidence_score <= 1.0diff --git a/services/fusion/tests/test_entity_risk.py b/services/fusion/tests/test_entity_risk.pynew file mode 100644index 000000000..37e64fef7--- /dev/null+++ b/services/fusion/tests/test_entity_risk.py@@ -0,0 +1,361 @@+"""+Unit tests for the Risk-Based Alerting (RBA) entity-rollup engine.++These tests run without a real Redis: a tiny in-memory fake implements the+exact subset of redis.asyncio commands ``EntityRiskEngine`` calls. That keeps+the test fast and deterministic (no clock + no flakes from TTLs).++The tests gate three properties the 2026 KPI bar depends on:++1. Score accumulates additively across alerts and severities.+2. Time-decay halves the score after one half-life so stale signal drops out.+3. Threshold promotion happens exactly once and is visible on the queue.+"""++from __future__ import annotations++from datetime import datetime, timedelta+from typing import Any+from uuid import UUID, uuid4++import pytest+from app.models.alert import AlertSeverity, RawAlert+from app.services.entity_risk import EntityRiskEngine++# ---------------------------------------------------------------------------+# In-memory fake redis (only the commands the engine uses)+# ---------------------------------------------------------------------------+++class _FakeRedis:+ """Minimal async fake covering hset/hgetall/expire/zadd/zrevrange/zcard/zremrangebyrank."""++ def __init__(self) -> None:+ self.hashes: dict[str, dict[bytes, bytes]] = {}+ self.zsets: dict[str, dict[str, float]] = {}++ async def hset(self, key: str, mapping: dict[str, Any]) -> int:+ bucket = self.hashes.setdefault(key, {})+ for k, v in mapping.items():+ bucket[k.encode() if isinstance(k, str) else k] = (+ v.encode() if isinstance(v, str) else v+ )+ return len(mapping)++ async def hgetall(self, key: str) -> dict[bytes, bytes]:+ return dict(self.hashes.get(key, {}))++ async def expire(self, key: str, ttl: int) -> bool:+ return key in self.hashes or key in self.zsets++ async def zadd(self, key: str, mapping: dict[str, float]) -> int:+ bucket = self.zsets.setdefault(key, {})+ added = 0+ for member, score in mapping.items():+ if member not in bucket:+ added += 1+ bucket[member] = float(score)+ return added++ async def zrevrange(+ self, key: str, start: int, stop: int, withscores: bool = False+ ) -> list[Any]:+ bucket = self.zsets.get(key, {})+ sorted_pairs = sorted(bucket.items(), key=lambda kv: kv[1], reverse=True)+ # Redis ranges are inclusive on both ends.+ if stop == -1:+ sliced = sorted_pairs[start:]+ else:+ sliced = sorted_pairs[start : stop + 1]+ if withscores:+ return [(m.encode(), s) for m, s in sliced]+ return [m.encode() for m, _ in sliced]++ async def zcard(self, key: str) -> int:+ return len(self.zsets.get(key, {}))++ async def zremrangebyrank(self, key: str, start: int, stop: int) -> int:+ bucket = self.zsets.get(key)+ if not bucket:+ return 0+ sorted_pairs = sorted(bucket.items(), key=lambda kv: kv[1])+ n = len(sorted_pairs)+ # Redis allows negative indexes from the end.+ s = start if start >= 0 else max(0, n + start)+ e = stop if stop >= 0 else n + stop+ if e < s:+ return 0+ to_remove = sorted_pairs[s : e + 1]+ for member, _ in to_remove:+ bucket.pop(member, None)+ return len(to_remove)+++# ---------------------------------------------------------------------------+# Helpers+# ---------------------------------------------------------------------------+++_TENANT = UUID("11111111-1111-1111-1111-111111111111")+++def _alert(+ severity: AlertSeverity = AlertSeverity.MEDIUM,+ *,+ username: str | None = "alice",+ hostname: str | None = None,+ src_ip: str | None = None,+ risk_score: float = 0.0,+) -> RawAlert:+ return RawAlert(+ id=uuid4(),+ tenant_id=_TENANT,+ source="test",+ title="probe",+ severity=severity,+ username=username,+ hostname=hostname,+ src_ip=src_ip,+ risk_score=risk_score,+ )+++def fake_redis() -> _FakeRedis:+ return _FakeRedis()+++def engine(fake_redis: _FakeRedis) -> EntityRiskEngine:+ return EntityRiskEngine(fake_redis) # type: ignore[arg-type]+++# ---------------------------------------------------------------------------+# Score accumulation+# ---------------------------------------------------------------------------+++async def test_observe_creates_record_for_each_entity(engine: EntityRiskEngine) -> None:+ alert = _alert(username="alice", hostname="dc01", src_ip="10.0.0.1")+ await engine.observe(alert)+ assert (await engine.get(_TENANT, "user", "alice")) is not None+ assert (await engine.get(_TENANT, "host", "dc01")) is not None+ assert (await engine.get(_TENANT, "src_ip", "10.0.0.1")) is not None+++async def test_score_accumulates_additively(engine: EntityRiskEngine) -> None:+ """Two medium alerts on the same user must double-up the score."""+ await engine.observe(_alert(severity=AlertSeverity.MEDIUM))+ await engine.observe(_alert(severity=AlertSeverity.MEDIUM))+ rec = await engine.get(_TENANT, "user", "alice")+ assert rec is not None+ # Two medium alerts at base weight 8.0 (config default) ≈ 16.0 (within decay window).+ assert rec.score >= 15.0+ assert rec.alert_count == 2+++async def test_severity_weights_are_ordered(engine: EntityRiskEngine) -> None:+ a_crit = _alert(severity=AlertSeverity.CRITICAL, username="u-crit")+ a_high = _alert(severity=AlertSeverity.HIGH, username="u-high")+ a_med = _alert(severity=AlertSeverity.MEDIUM, username="u-med")+ a_low = _alert(severity=AlertSeverity.LOW, username="u-low")+ for a in (a_crit, a_high, a_med, a_low):+ await engine.observe(a)++ s_crit = (await engine.get(_TENANT, "user", "u-crit")).score # type: ignore[union-attr]+ s_high = (await engine.get(_TENANT, "user", "u-high")).score # type: ignore[union-attr]+ s_med = (await engine.get(_TENANT, "user", "u-med")).score # type: ignore[union-attr]+ s_low = (await engine.get(_TENANT, "user", "u-low")).score # type: ignore[union-attr]+ assert s_crit > s_high > s_med > s_low+++async def test_risk_score_amplifies_points(engine: EntityRiskEngine) -> None:+ """Upstream risk_score (detection confidence) boosts entity points."""+ base = _alert(severity=AlertSeverity.HIGH, risk_score=0.0, username="u-base")+ boosted = _alert(severity=AlertSeverity.HIGH, risk_score=1.0, username="u-boosted")+ await engine.observe(base)+ await engine.observe(boosted)++ s_base = (await engine.get(_TENANT, "user", "u-base")).score # type: ignore[union-attr]+ s_boosted = (await engine.get(_TENANT, "user", "u-boosted")).score # type: ignore[union-attr]+ # confidence_factor doubles points at risk_score=1.0+ assert s_boosted == pytest.approx(2.0 * s_base, rel=0.1)+++# ---------------------------------------------------------------------------+# Time decay+# ---------------------------------------------------------------------------+++def test_decay_halves_after_one_halflife(engine: EntityRiskEngine) -> None:+ now = datetime.utcnow()+ one_half_life_ago = now - timedelta(seconds=engine._half_life) # type: ignore[attr-defined]+ decayed = engine._decay(40.0, one_half_life_ago, now) # type: ignore[attr-defined]+ assert decayed == pytest.approx(20.0, rel=0.05)+++def test_decay_floor_zeros_dust(engine: EntityRiskEngine) -> None:+ now = datetime.utcnow()+ long_ago = now - timedelta(seconds=engine._half_life * 20) # type: ignore[attr-defined]+ assert engine._decay(40.0, long_ago, now) == 0.0 # type: ignore[attr-defined]+++def test_decay_no_negative_or_future_time(engine: EntityRiskEngine) -> None:+ now = datetime.utcnow()+ future = now + timedelta(seconds=120)+ # Future "prior_seen" must not amplify the score.+ assert engine._decay(40.0, future, now) <= 40.0 # type: ignore[attr-defined]+++# ---------------------------------------------------------------------------+# Promotion+# ---------------------------------------------------------------------------+++async def test_promotion_fires_when_threshold_crossed(engine: EntityRiskEngine) -> None:+ """Three CRITICAL alerts on one user (3 × 40 = 120) ≥ default threshold 80."""+ for _ in range(3):+ await engine.observe(_alert(severity=AlertSeverity.CRITICAL))+ rec = await engine.get(_TENANT, "user", "alice")+ assert rec is not None and rec.promoted_at is not None+++async def test_promotion_is_idempotent(engine: EntityRiskEngine) -> None:+ """Crossing the threshold a second time must not re-promote."""+ for _ in range(3):+ await engine.observe(_alert(severity=AlertSeverity.CRITICAL))+ rec_first = await engine.get(_TENANT, "user", "alice")+ promoted_at_first = rec_first.promoted_at # type: ignore[union-attr]++ # Add another contributing alert.+ await engine.observe(_alert(severity=AlertSeverity.CRITICAL))+ rec_second = await engine.get(_TENANT, "user", "alice")+ assert rec_second is not None+ assert rec_second.promoted_at == promoted_at_first+++async def test_no_promotion_below_threshold(engine: EntityRiskEngine) -> None:+ await engine.observe(_alert(severity=AlertSeverity.LOW))+ rec = await engine.get(_TENANT, "user", "alice")+ assert rec is not None and rec.promoted_at is None+++# ---------------------------------------------------------------------------+# Top-N queue + stats+# ---------------------------------------------------------------------------+++async def test_top_entities_orders_by_score(engine: EntityRiskEngine) -> None:+ await engine.observe(_alert(severity=AlertSeverity.LOW, username="quiet"))+ await engine.observe(_alert(severity=AlertSeverity.CRITICAL, username="loud"))+ await engine.observe(_alert(severity=AlertSeverity.MEDIUM, username="middle"))+ top = await engine.top_entities(_TENANT, limit=10)+ names = [r.entity_value for r in top if r.entity_type == "user"]+ assert names[0] == "loud"+ assert names[-1] == "quiet"+++async def test_promoted_only_filters_queue(engine: EntityRiskEngine) -> None:+ await engine.observe(_alert(severity=AlertSeverity.LOW, username="quiet"))+ for _ in range(3):+ await engine.observe(_alert(severity=AlertSeverity.CRITICAL, username="loud"))+ promoted = await engine.top_entities(_TENANT, limit=10, promoted_only=True)+ assert {r.entity_value for r in promoted} == {"loud"}+++async def test_stats_reports_bands(engine: EntityRiskEngine) -> None:+ await engine.observe(_alert(severity=AlertSeverity.LOW, username="low-1"))+ await engine.observe(_alert(severity=AlertSeverity.MEDIUM, username="med-1"))+ for _ in range(3):+ await engine.observe(_alert(severity=AlertSeverity.CRITICAL, username="crit-1"))+ stats = await engine.stats(_TENANT)+ assert stats["tracked_entities"] >= 3+ assert stats["promoted_entities"] >= 1+ assert stats["threshold"] == engine.threshold+ assert sum(stats["score_bands"].values()) == stats["tracked_entities"]+++# ---------------------------------------------------------------------------+# 2026 KPI bar — alert-to-incident ratio ≥ 50:1+#+# This is the headline number RBA exists to deliver. The scenario simulates a+# realistic noisy day: 200 alerts of mixed severity hitting a small set of+# entities (a campaign of related medium / high signal against ~5 users).+# RBA must collapse those 200 alerts into ≤ 4 entity-incidents — i.e. one+# promoted entity per cluster. If this regresses we want CI to fail.+# ---------------------------------------------------------------------------+++async def test_alert_to_incident_ratio_meets_2026_bar(engine: EntityRiskEngine) -> None:+ """500 alerts clustered on 4 entities → ≤ 10 entity-incidents (≥ 50:1).++ This is the headline number RBA exists to deliver — the published 2026+ KPI bar of ≥ 50 alerts per promoted entity-incident. The scenario models+ a real noisy day: a focused campaign of 500 mixed-severity alerts hitting+ a small pool of users. RBA must collapse those into ≤ 10 entity-incidents.+ """+ users = ["alice", "bob", "carol", "dave"]+ severities = [+ AlertSeverity.HIGH,+ AlertSeverity.MEDIUM,+ AlertSeverity.MEDIUM,+ AlertSeverity.LOW,+ AlertSeverity.LOW,+ ]+ total_alerts = 500+ for i in range(total_alerts):+ # Distribute alerts across the 5 users so every promoted entity is a+ # cluster of ~40 contributing alerts — what a real campaign looks like.+ await engine.observe(+ _alert(+ severity=severities[i % len(severities)],+ username=users[i % len(users)],+ )+ )++ promoted = await engine.top_entities(_TENANT, limit=50, promoted_only=True)+ promoted_count = len({(r.entity_type, r.entity_value) for r in promoted})++ # Hard floor: every promoted entity must be a real cluster, not a single+ # noisy alert. This is the "50:1" published bar — at minimum the ratio of+ # contributing alerts to entity-incidents must be ≥ 50.+ assert promoted_count > 0, "RBA must promote at least one entity-incident"+ ratio = total_alerts / promoted_count+ assert ratio >= 50.0, (+ f"alert-to-incident ratio {ratio:.1f}:1 fails the 2026 KPI bar of ≥ 50:1; "+ f"got {promoted_count} entity-incidents from {total_alerts} alerts"+ )+++# ---------------------------------------------------------------------------+# Tenant isolation+# ---------------------------------------------------------------------------+++async def test_tenants_are_isolated(engine: EntityRiskEngine) -> None:+ other_tenant = UUID("22222222-2222-2222-2222-222222222222")+ a = _alert(severity=AlertSeverity.HIGH, username="alice")+ a_other = RawAlert(**{**a.model_dump(), "tenant_id": other_tenant, "id": uuid4()})+ await engine.observe(a)+ await engine.observe(a_other)+ rec_a = await engine.get(_TENANT, "user", "alice")+ rec_b = await engine.get(other_tenant, "user", "alice")+ assert rec_a is not None and rec_b is not None+ assert rec_a.tenant_id != rec_b.tenant_id++ queue_a = await engine.top_entities(_TENANT)+ queue_b = await engine.top_entities(other_tenant)+ assert all(r.tenant_id == str(_TENANT) for r in queue_a)+ assert all(r.tenant_id == str(other_tenant) for r in queue_b)diff --git a/services/purple-team/alembic/versions/0002_detection_drift_snapshots.py b/services/purple-team/alembic/versions/0002_detection_drift_snapshots.pynew file mode 100644index 000000000..1bf596dce--- /dev/null+++ b/services/purple-team/alembic/versions/0002_detection_drift_snapshots.py@@ -0,0 +1,74 @@+"""Detection drift snapshots.++Revision ID: 0002+Revises: 0001+Create Date: 2026-05-05+"""++from __future__ import annotations++import sqlalchemy as sa+from sqlalchemy.dialects.postgresql import JSONB, UUID++from alembic import op++revision = "0002"+down_revision = "0001"+branch_labels = None+depends_on = None+++def upgrade() -> None:+ op.create_table(+ "purple_team_detection_drift_snapshots",+ sa.Column(+ "id",+ UUID(as_uuid=True),+ primary_key=True,+ server_default=sa.text("gen_random_uuid()"),+ ),+ sa.Column("tenant_id", UUID(as_uuid=True), nullable=False),+ sa.Column(+ "captured_at",+ sa.DateTime(timezone=True),+ server_default=sa.func.now(),+ nullable=False,+ ),+ sa.Column("trigger", sa.String(32), nullable=False, server_default="scheduled"),+ sa.Column("total_techniques", sa.Integer, nullable=False, server_default="0"),+ sa.Column("tested_techniques", sa.Integer, nullable=False, server_default="0"),+ sa.Column("detected_techniques", sa.Integer, nullable=False, server_default="0"),+ sa.Column("overall_coverage", sa.Float, nullable=False, server_default="0"),+ sa.Column("coverage", JSONB, nullable=False, server_default="{}"),+ )+ op.create_index(+ "ix_drift_snapshots_tenant_id",+ "purple_team_detection_drift_snapshots",+ ["tenant_id"],+ )+ op.create_index(+ "ix_drift_snapshots_captured_at",+ "purple_team_detection_drift_snapshots",+ ["captured_at"],+ )+ op.create_index(+ "ix_drift_snapshots_tenant_captured_at",+ "purple_team_detection_drift_snapshots",+ ["tenant_id", "captured_at"],+ )+++def downgrade() -> None:+ op.drop_index(+ "ix_drift_snapshots_tenant_captured_at",+ table_name="purple_team_detection_drift_snapshots",+ )+ op.drop_index(+ "ix_drift_snapshots_captured_at",+ table_name="purple_team_detection_drift_snapshots",+ )+ op.drop_index(+ "ix_drift_snapshots_tenant_id",+ table_name="purple_team_detection_drift_snapshots",+ )+ op.drop_table("purple_team_detection_drift_snapshots")diff --git a/services/purple-team/app/api/routes.py b/services/purple-team/app/api/routes.pyindex d426149d9..409b97180 100644--- a/services/purple-team/app/api/routes.py+++ b/services/purple-team/app/api/routes.py@@ -14,10 +14,21 @@ from sqlalchemy.ext.asyncio import AsyncSession, create_async_enginefrom sqlalchemy.orm import sessionmakerfrom app.core.config import settings-from app.models.purple_team import AtomicTest, TabletopSession, TestExecution+from app.models.purple_team import (+ AtomicTest,+ DetectionDriftSnapshot,+ TabletopSession,+ TestExecution,+)from app.services.atomic_loader import load_atomicsfrom app.services.caldera_client import CalderaClient-from app.services.coverage import build_coverage_matrix+from app.services.drift import (+ capture_snapshot,+ compute_coverage_for_tenant,+ compute_drift,+ latest_two_snapshots,+ list_snapshots,+)LOG = logging.getLogger(__name__)@@ -307,21 +318,98 @@ async def report_detection(execution_id: uuid.UUID, body: ReportDetectionRequest# ---------------------------------------------------------------------------@router.get("/api/v1/purple-team/coverage", tags=["Coverage"])async def get_coverage(tenant_id: uuid.UUID) -> dict:+ """Live coverage matrix computed from current execution history.++ Tactics are resolved by joining executions to the tenant's Atomic+ Red Team catalog (see ``compute_coverage_for_tenant``), so the+ heatmap is grouped by real ATT&CK tactics rather than the legacy+ placeholder.+ """+ async with _async_session() as session:+ return await compute_coverage_for_tenant(session, tenant_id)+++# ---------------------------------------------------------------------------+# Detection drift (w1-drift)+# ---------------------------------------------------------------------------+class DriftSnapshotOut(BaseModel):+ id: uuid.UUID+ captured_at: datetime+ trigger: str+ total_techniques: int+ tested_techniques: int+ detected_techniques: int+ overall_coverage: float++ model_config = {"from_attributes": True}+++class DriftSnapshotDetail(DriftSnapshotOut):+ coverage: dict[str, Any]+++ "/api/v1/purple-team/drift/snapshot",+ response_model=DriftSnapshotDetail,+ tags=["Drift"],+)+async def trigger_drift_snapshot(+ tenant_id: uuid.UUID,+ trigger: str = Query(+ "manual",+ description="Why this snapshot was captured (manual|scheduled|post-run)",+ ),+) -> DetectionDriftSnapshot:+ """Capture a coverage snapshot on demand (e.g. after a purple-team run)."""+ async with _async_session() as session:+ snap = await capture_snapshot(session, tenant_id, trigger=trigger)+ await session.commit()+ await session.refresh(snap)+ return snap+++ "/api/v1/purple-team/drift/snapshots",+ response_model=list[DriftSnapshotOut],+ tags=["Drift"],+)+async def list_drift_snapshots(+ tenant_id: uuid.UUID,+ limit: int = Query(50, le=200),+) -> list[DetectionDriftSnapshot]:+ async with _async_session() as session:+ return await list_snapshots(session, tenant_id, limit=limit)++[email protected]("/api/v1/purple-team/drift/latest", tags=["Drift"])+async def get_latest_drift(tenant_id: uuid.UUID) -> dict:+ """Return the most recent snapshot plus delta-vs-previous for the heatmap."""async with _async_session() as session:- result = await session.execute(select(TestExecution).where(TestExecution.tenant_id == tenant_id))- executions = result.scalars().all()-- rows = [- {- "technique_id": ex.technique_id,- "test_name": ex.test_name,- "tactic": "unknown",- "status": ex.status,- "detected": ex.detected,- }- for ex in executions- ]- return build_coverage_matrix(rows)+ current, previous = await latest_two_snapshots(session, tenant_id)++ return {+ "current": _serialize_snapshot(current),+ "previous": _serialize_snapshot(previous),+ "drift": compute_drift(+ current.coverage if current else None,+ previous.coverage if previous else None,+ ),+ }+++def _serialize_snapshot(snap: DetectionDriftSnapshot | None) -> dict | None:+ if snap is None:+ return None+ return {+ "id": str(snap.id),+ "captured_at": snap.captured_at.isoformat() if snap.captured_at else None,+ "trigger": snap.trigger,+ "total_techniques": snap.total_techniques,+ "tested_techniques": snap.tested_techniques,+ "detected_techniques": snap.detected_techniques,+ "overall_coverage": snap.overall_coverage,+ "coverage": snap.coverage,+ }# ---------------------------------------------------------------------------diff --git a/services/purple-team/app/core/config.py b/services/purple-team/app/core/config.pyindex 827cf6021..5cef99099 100644--- a/services/purple-team/app/core/config.py+++ b/services/purple-team/app/core/config.py@@ -30,5 +30,11 @@ class Settings(BaseSettings):host: str = "0.0.0.0"port: int = 8006+ # Drift snapshot scheduler+ # Default cadence: weekly (7 days) — matches the 2026 KPI bar's+ # "delta vs. last week" mandate. Set to 0 to disable.+ drift_snapshot_interval_seconds: int = 7 * 24 * 60 * 60+ drift_scheduler_enabled: bool = True+settings = Settings()diff --git a/services/purple-team/app/main.py b/services/purple-team/app/main.pyindex 757e2026f..2309d1d0d 100644--- a/services/purple-team/app/main.py+++ b/services/purple-team/app/main.py@@ -3,9 +3,11 @@from __future__ import annotationsimport logging+from contextlib import asynccontextmanagerfrom fastapi import FastAPIfrom fastapi.middleware.cors import CORSMiddleware+from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_enginefrom app.core.config import settings@@ -42,11 +44,41 @@ LOG = logging.getLogger(__name__)# Application# ---------------------------------------------------------------------------from app.api.routes import router # noqa: E402+from app.services.scheduler import DriftScheduler # noqa: E402++# Detection drift scheduler — owned by the FastAPI lifespan so it+# starts/stops cleanly with the service.+_drift_scheduler: DriftScheduler | None = None+++@asynccontextmanager+async def _lifespan(app: FastAPI):+ global _drift_scheduler+ LOG.info("Purple Team service started (OTel=%s)", _otel_enabled)++ if settings.drift_scheduler_enabled and settings.drift_snapshot_interval_seconds > 0:+ engine = create_async_engine(settings.database_url, pool_pre_ping=True)+ session_factory = async_sessionmaker(engine, expire_on_commit=False)+ _drift_scheduler = DriftScheduler(+ session_factory=session_factory,+ interval_seconds=settings.drift_snapshot_interval_seconds,+ )+ _drift_scheduler.start()+ else:+ LOG.info("Detection drift scheduler disabled by config")++ try:+ yield+ finally:+ if _drift_scheduler is not None:+ _drift_scheduler.stop()+app = FastAPI(title="AiSOC Purple Team Service",description=("Atomic Red Team execution, Caldera adversary emulation, ATT&CK coverage heatmap, and tabletop exercise simulator."),version="0.1.0",+ lifespan=_lifespan,)app.add_middleware(@@ -62,11 +94,6 @@ if _otel_enabled:FastAPIInstrumentor.instrument_app(app)[email protected]_event("startup")-async def _startup() -> None:- LOG.info("Purple Team service started (OTel=%s)", _otel_enabled)--@app.get("/health")async def health() -> dict:return {"status": "ok", "service": settings.service_name}diff --git a/services/purple-team/app/models/purple_team.py b/services/purple-team/app/models/purple_team.pyindex 9c971001b..34b2b8365 100644--- a/services/purple-team/app/models/purple_team.py+++ b/services/purple-team/app/models/purple_team.py@@ -107,3 +107,35 @@ class TabletopSession(Base):created_by: Mapped[str | None] = mapped_column(String(128), nullable=True)created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now(), nullable=False)updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False)+++class DetectionDriftSnapshot(Base):+ """Point-in-time snapshot of ATT&CK detection coverage for a tenant.++ Snapshots are produced by the weekly scheduler (or on-demand via API)+ and used to surface "delta vs. last week" on the MITRE heatmap. The+ full coverage matrix is stored in JSONB so the API can replay+ historical coverage without recomputing from raw executions, which+ can age out under retention policies.+ """++ __tablename__ = "purple_team_detection_drift_snapshots"++ id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True, server_default=func.gen_random_uuid())+ tenant_id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), nullable=False, index=True)++ captured_at: Mapped[datetime] = mapped_column(+ DateTime(timezone=True), server_default=func.now(), nullable=False, index=True+ )++ # "scheduled" | "manual" | "post-run"+ trigger: Mapped[str] = mapped_column(String(32), nullable=False, server_default="scheduled")++ # Aggregate counters lifted from coverage["summary"] for cheap historical queries.+ total_techniques: Mapped[int] = mapped_column(Integer, nullable=False, server_default="0")+ tested_techniques: Mapped[int] = mapped_column(Integer, nullable=False, server_default="0")+ detected_techniques: Mapped[int] = mapped_column(Integer, nullable=False, server_default="0")+ overall_coverage: Mapped[float] = mapped_column(Float, nullable=False, server_default="0")++ # Full ATT&CK coverage matrix (tactics + techniques + summary) at capture time.+ coverage: Mapped[dict] = mapped_column(JSONB, nullable=False, server_default="{}")diff --git a/services/purple-team/app/services/drift.py b/services/purple-team/app/services/drift.pynew file mode 100644index 000000000..dc840ac6e--- /dev/null+++ b/services/purple-team/app/services/drift.py@@ -0,0 +1,146 @@+"""Detection drift snapshotting + delta computation.++Wave 1 of the AiSOC v6 capability roadmap (`w1-drift`) — turns the existing+ATT&CK coverage heatmap from a point-in-time view into a tracked time series+so the console can surface "delta vs. last week" on the MITRE heatmap.++Design notes+------------+The roadmap calls this "scheduled Atomic Red Team + Caldera runs". In+practice we do *not* execute attacks on a schedule — actual atomic+execution is gated behind an explicit human/operator action because it+mutates production endpoints. Instead, the scheduler periodically+*recomputes coverage from the existing execution history* and writes a+snapshot row, plus exposes an on-demand snapshot endpoint so operators+can capture coverage immediately after an exercise.++This still meets the "automated, not point-in-time" mandate from the+2026 buyer-side rubric: drift is detected by diffing the JSONB coverage+matrices of consecutive snapshots, regardless of *when* the underlying+runs happened.+"""++from __future__ import annotations++import logging+import uuid+from datetime import UTC, datetime+from typing import Any++from sqlalchemy import select+from sqlalchemy.ext.asyncio import AsyncSession++from app.models.purple_team import AtomicTest, DetectionDriftSnapshot, TestExecution+from app.services.coverage import build_coverage_matrix++LOG = logging.getLogger(__name__)+++async def compute_coverage_for_tenant(+ session: AsyncSession,+ tenant_id: uuid.UUID,+) -> dict[str, Any]:+ """Build the ATT&CK coverage matrix for a tenant from current executions.++ Resolves the ``tactic`` field by joining executions to the tenant's+ Atomic Red Team catalog so the coverage matrix is grouped under real+ tactics rather than the placeholder "unknown" the legacy endpoint+ used.+ """++ exec_result = await session.execute(+ select(TestExecution).where(TestExecution.tenant_id == tenant_id)+ )+ executions = exec_result.scalars().all()++ atomic_result = await session.execute(+ select(AtomicTest.technique_id, AtomicTest.tactic).where(+ AtomicTest.tenant_id == tenant_id+ )+ )+ tactic_by_technique: dict[str, str] = {}+ for technique_id, tactic in atomic_result.all():+ # Atomic Red Team can list the same technique under multiple+ # tactics; first writer wins, which keeps the heatmap stable+ # across snapshots.+ tactic_by_technique.setdefault(technique_id, tactic)++ rows = [+ {+ "technique_id": ex.technique_id,+ "test_name": ex.test_name,+ "tactic": tactic_by_technique.get(ex.technique_id, "unknown"),+ "status": ex.status,+ "detected": ex.detected,+ }+ for ex in executions+ ]+ return build_coverage_matrix(rows)+++async def capture_snapshot(+ session: AsyncSession,+ tenant_id: uuid.UUID,+ *,+ trigger: str = "scheduled",+ coverage: dict[str, Any] | None = None,+) -> DetectionDriftSnapshot:+ """Persist a `DetectionDriftSnapshot` for a tenant and return it.++ If ``coverage`` is not supplied it is computed from the tenant's+ current execution history. Caller is responsible for committing the+ surrounding transaction.+ """++ if coverage is None:+ coverage = await compute_coverage_for_tenant(session, tenant_id)++ summary = coverage.get("summary", {})+ snapshot = DetectionDriftSnapshot(+ tenant_id=tenant_id,+ captured_at=datetime.now(UTC),+ trigger=trigger,+ total_techniques=int(summary.get("total_techniques", 0)),+ tested_techniques=int(summary.get("tested_techniques", 0)),+ detected_techniques=int(summary.get("detected_techniques", 0)),+ overall_coverage=float(summary.get("overall_coverage", 0.0)),+ coverage=coverage,+ )+ session.add(snapshot)+ await session.flush()+ return snapshot+++async def list_snapshots(+ session: AsyncSession,+ tenant_id: uuid.UUID,+ *,+ limit: int = 50,+) -> list[DetectionDriftSnapshot]:+ """Return the most recent snapshots for a tenant, newest first."""++ result = await session.execute(+ select(DetectionDriftSnapshot)+ .where(DetectionDriftSnapshot.tenant_id == tenant_id)+ .order_by(DetectionDriftSnapshot.captured_at.desc())+ .limit(limit)+ )+ return list(result.scalars().all())+++async def latest_two_snapshots(+ session: AsyncSession,+ tenant_id: uuid.UUID,+) -> tuple[DetectionDriftSnapshot | None, DetectionDriftSnapshot | None]:+ """Return ``(current, previous)`` snapshots for delta computation."""++ snaps = await list_snapshots(session, tenant_id, limit=2)+ current = snaps[0] if snaps else None+ previous = snaps[1] if len(snaps) > 1 else None+ return current, previous+++# NOTE: ``compute_drift`` (and its helper ``_index_techniques``) are+# imported from ``app.services.drift_diff`` so the pure-Python delta+# logic stays unit-testable without SQLAlchemy installed.+from app.services.drift_diff import compute_drift # noqa: E402,F401diff --git a/services/purple-team/app/services/drift_diff.py b/services/purple-team/app/services/drift_diff.pynew file mode 100644index 000000000..5ffc44314--- /dev/null+++ b/services/purple-team/app/services/drift_diff.py@@ -0,0 +1,108 @@+"""Pure-Python delta computation between two ATT&CK coverage matrices.++Split out from `app.services.drift` so the heatmap-friendly delta logic+stays importable without SQLAlchemy — the storage/scheduler concerns+live in `drift.py`, the math lives here so unit tests can run with only+the standard library.+"""++from __future__ import annotations++from typing import Any+++def _index_techniques(coverage: dict[str, Any]) -> dict[str, dict[str, Any]]:+ """Flatten a coverage matrix into ``{technique_id: technique_row}``."""++ out: dict[str, dict[str, Any]] = {}+ for techniques in (coverage.get("techniques") or {}).values():+ for tech in techniques:+ tid = tech.get("technique_id")+ if tid:+ out[tid] = tech+ return out+++def compute_drift(+ current: dict[str, Any] | None,+ previous: dict[str, Any] | None,+) -> dict[str, Any]:+ """Compute a per-technique delta between two coverage matrices.++ Output schema is intentionally heatmap-friendly: a flat list of+ technique rows annotated with ``delta_*`` and a ``status`` enum that+ the frontend overlays directly on the existing MITRE grid.+ """++ current = current or {"techniques": {}, "summary": {}}+ previous = previous or {"techniques": {}, "summary": {}}++ cur_idx = _index_techniques(current)+ prev_idx = _index_techniques(previous)++ techniques: list[dict[str, Any]] = []+ for tid in sorted(set(cur_idx) | set(prev_idx)):+ cur = cur_idx.get(tid)+ prev = prev_idx.get(tid)++ if cur and not prev:+ status = "new"+ elif prev and not cur:+ status = "removed"+ else:+ cur_cov = float(cur.get("coverage", 0.0)) if cur else 0.0+ prev_cov = float(prev.get("coverage", 0.0)) if prev else 0.0+ cur_det = int(cur.get("detected", 0)) if cur else 0+ prev_det = int(prev.get("detected", 0)) if prev else 0++ if cur_cov > prev_cov or cur_det > prev_det:+ status = "improved"+ elif cur_cov < prev_cov or cur_det < prev_det:+ status = "regressed"+ else:+ status = "unchanged"++ techniques.append(+ {+ "technique_id": tid,+ "current": cur,+ "previous": prev,+ "delta_coverage": round(+ float((cur or {}).get("coverage", 0.0))+ - float((prev or {}).get("coverage", 0.0)),+ 3,+ ),+ "delta_detected": int((cur or {}).get("detected", 0))+ - int((prev or {}).get("detected", 0)),+ "status": status,+ }+ )++ cur_sum = current.get("summary") or {}+ prev_sum = previous.get("summary") or {}+ summary_delta = {+ "delta_total": int(cur_sum.get("total_techniques", 0))+ - int(prev_sum.get("total_techniques", 0)),+ "delta_tested": int(cur_sum.get("tested_techniques", 0))+ - int(prev_sum.get("tested_techniques", 0)),+ "delta_detected": int(cur_sum.get("detected_techniques", 0))+ - int(prev_sum.get("detected_techniques", 0)),+ "delta_coverage": round(+ float(cur_sum.get("overall_coverage", 0.0))+ - float(prev_sum.get("overall_coverage", 0.0)),+ 3,+ ),+ }++ return {+ "techniques": techniques,+ "summary": {+ "current": cur_sum,+ "previous": prev_sum,+ "delta": summary_delta,+ "regressed": sum(1 for t in techniques if t["status"] == "regressed"),+ "improved": sum(1 for t in techniques if t["status"] == "improved"),+ "new": sum(1 for t in techniques if t["status"] == "new"),+ "removed": sum(1 for t in techniques if t["status"] == "removed"),+ },+ }diff --git a/services/purple-team/app/services/scheduler.py b/services/purple-team/app/services/scheduler.pynew file mode 100644index 000000000..e8e28e3be--- /dev/null+++ b/services/purple-team/app/services/scheduler.py@@ -0,0 +1,110 @@+"""APScheduler-based detection drift snapshot scheduler.++Recomputes ATT&CK coverage from each tenant's current execution history+on a fixed cadence (default: weekly) and persists a+``DetectionDriftSnapshot`` row per tenant. The MITRE heatmap UI then+diffs the two most recent snapshots to surface "delta vs. last week".++Mirrors the pattern in ``services/threatintel/app/feeds/scheduler.py``.+"""++from __future__ import annotations++import logging+import uuid++from apscheduler.schedulers.asyncio import AsyncIOScheduler+from apscheduler.triggers.interval import IntervalTrigger+from sqlalchemy import select+from sqlalchemy.ext.asyncio import async_sessionmaker++from app.models.purple_team import AtomicTest, TestExecution+from app.services.drift import capture_snapshot++LOG = logging.getLogger(__name__)+++class DriftScheduler:+ """Periodically captures coverage snapshots across all known tenants."""++ JOB_ID = "purple-team-drift-snapshot"++ def __init__(+ self,+ session_factory: async_sessionmaker,+ interval_seconds: int,+ ) -> None:+ self._session_factory = session_factory+ self._interval_seconds = interval_seconds+ self._scheduler = AsyncIOScheduler()++ async def _discover_tenants(self) -> list[uuid.UUID]:+ """Tenants with any purple-team data — atomic catalog or executions.++ We can't reach the central tenants table from here without+ crossing a service boundary, so we discover tenants from rows+ the service itself owns. A tenant with zero rows has nothing+ to snapshot.+ """++ async with self._session_factory() as session:+ tids: set[uuid.UUID] = set()+ for table in (TestExecution, AtomicTest):+ rows = await session.execute(select(table.tenant_id).distinct())+ tids.update(rows.scalars().all())+ return list(tids)++ async def _run_once(self) -> None:+ """Single scheduler tick — snapshot every active tenant."""++ tenants = await self._discover_tenants()+ if not tenants:+ LOG.info("Drift scheduler tick: no tenants with purple-team data")+ return++ async with self._session_factory() as session:+ for tenant_id in tenants:+ try:+ snap = await capture_snapshot(+ session, tenant_id, trigger="scheduled"+ )+ LOG.info(+ "Captured drift snapshot tenant=%s coverage=%.3f tested=%d",+ tenant_id,+ snap.overall_coverage,+ snap.tested_techniques,+ )+ except Exception:+ LOG.exception(+ "Drift snapshot failed for tenant=%s", tenant_id+ )+ await session.commit()++ def start(self) -> None:+ """Register the snapshot job and start the scheduler."""++ if self._interval_seconds <= 0:+ LOG.info("Drift scheduler disabled (interval<=0)")+ return++ self._scheduler.add_job(+ func=self._run_once,+ trigger=IntervalTrigger(seconds=self._interval_seconds),+ id=self.JOB_ID,+ name="Detection drift snapshot",+ replace_existing=True,+ max_instances=1,+ coalesce=True,+ )+ if not self._scheduler.running:+ self._scheduler.start()+ LOG.info(+ "Drift scheduler started (interval=%ss)", self._interval_seconds+ )++ def stop(self) -> None:+ """Gracefully stop the scheduler."""++ if self._scheduler.running:+ self._scheduler.shutdown(wait=False)+ LOG.info("Drift scheduler stopped")diff --git a/services/purple-team/pyproject.toml b/services/purple-team/pyproject.tomlindex 8322939a1..c8ea6fb37 100644--- a/services/purple-team/pyproject.toml+++ b/services/purple-team/pyproject.toml@@ -17,6 +17,7 @@ dependencies = ["pydantic-settings>=2.0.0","httpx>=0.27.0","pyyaml>=6.0.0",+ "apscheduler>=3.10.0","opentelemetry-sdk>=1.24.0","opentelemetry-exporter-otlp>=1.24.0","opentelemetry-instrumentation-fastapi>=0.45b0",diff --git a/services/purple-team/tests/test_drift.py b/services/purple-team/tests/test_drift.pynew file mode 100644index 000000000..0ed79ad5e--- /dev/null+++ b/services/purple-team/tests/test_drift.py@@ -0,0 +1,125 @@+"""Unit tests for compute_drift — pure stdlib, no DB required."""++from __future__ import annotations++from app.services.coverage import build_coverage_matrix+from app.services.drift_diff import compute_drift+++def _exec(+ technique_id: str,+ tactic: str,+ *,+ status: str = "success",+ detected: bool = False,+) -> dict:+ return {+ "technique_id": technique_id,+ "tactic": tactic,+ "status": status,+ "detected": detected,+ "test_name": f"test for {technique_id}",+ }+++class TestComputeDrift:+ def test_no_change_marks_all_unchanged(self) -> None:+ cov = build_coverage_matrix(+ [+ _exec("T1078", "initial-access", status="success", detected=True),+ _exec("T1059", "execution", status="success", detected=True),+ ]+ )+ drift = compute_drift(cov, cov)+ statuses = {t["status"] for t in drift["techniques"]}+ assert statuses == {"unchanged"}+ assert drift["summary"]["regressed"] == 0+ assert drift["summary"]["improved"] == 0++ def test_new_technique_marked_new(self) -> None:+ prev = build_coverage_matrix([_exec("T1078", "initial-access")])+ curr = build_coverage_matrix(+ [+ _exec("T1078", "initial-access"),+ _exec("T1059", "execution"),+ ]+ )+ drift = compute_drift(curr, prev)+ new_techs = [t for t in drift["techniques"] if t["status"] == "new"]+ assert len(new_techs) == 1+ assert new_techs[0]["technique_id"] == "T1059"+ assert drift["summary"]["new"] == 1++ def test_removed_technique_marked_removed(self) -> None:+ prev = build_coverage_matrix(+ [+ _exec("T1078", "initial-access"),+ _exec("T1059", "execution"),+ ]+ )+ curr = build_coverage_matrix([_exec("T1078", "initial-access")])+ drift = compute_drift(curr, prev)+ removed = [t for t in drift["techniques"] if t["status"] == "removed"]+ assert len(removed) == 1+ assert removed[0]["technique_id"] == "T1059"+ assert drift["summary"]["removed"] == 1++ def test_regression_lowers_detection_count(self) -> None:+ prev = build_coverage_matrix(+ [_exec("T1078", "initial-access", status="success", detected=True)]+ )+ curr = build_coverage_matrix(+ [_exec("T1078", "initial-access", status="success", detected=False)]+ )+ drift = compute_drift(curr, prev)+ regressed = [t for t in drift["techniques"] if t["status"] == "regressed"]+ assert len(regressed) == 1+ assert regressed[0]["delta_detected"] == -1+ assert drift["summary"]["regressed"] == 1++ def test_improvement_raises_detection_count(self) -> None:+ prev = build_coverage_matrix(+ [_exec("T1078", "initial-access", status="success", detected=False)]+ )+ curr = build_coverage_matrix(+ [_exec("T1078", "initial-access", status="success", detected=True)]+ )+ drift = compute_drift(curr, prev)+ improved = [t for t in drift["techniques"] if t["status"] == "improved"]+ assert len(improved) == 1+ assert improved[0]["delta_detected"] == 1+ assert drift["summary"]["improved"] == 1++ def test_summary_delta_reflects_aggregate_change(self) -> None:+ prev = build_coverage_matrix(+ [_exec("T1078", "initial-access", status="success", detected=False)]+ )+ curr = build_coverage_matrix(+ [+ _exec("T1078", "initial-access", status="success", detected=True),+ _exec("T1059", "execution", status="success", detected=True),+ ]+ )+ drift = compute_drift(curr, prev)+ delta = drift["summary"]["delta"]+ assert delta["delta_total"] == 1+ assert delta["delta_tested"] == 1+ assert delta["delta_detected"] == 2++ def test_none_inputs_produce_empty_drift(self) -> None:+ drift = compute_drift(None, None)+ assert drift["techniques"] == []+ assert drift["summary"]["new"] == 0+ assert drift["summary"]["removed"] == 0++ def test_first_snapshot_against_none_marks_all_new(self) -> None:+ curr = build_coverage_matrix(+ [+ _exec("T1078", "initial-access"),+ _exec("T1059", "execution"),+ ]+ )+ drift = compute_drift(curr, None)+ statuses = {t["status"] for t in drift["techniques"]}+ assert statuses == {"new"}+ assert drift["summary"]["new"] == 2