Skip to content

armgit / AiSOC

Public Imported from GitHub
0

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.

feat(pr5): osquery packs, FIM pipeline, and FIM dashboard

Beenu65b2df513bdc
diff --git a/apps/web/next.config.js b/apps/web/next.config.js
index 5417660ad..5099adc6d 100644
--- a/apps/web/next.config.js
+++ b/apps/web/next.config.js
@@ -23,6 +23,7 @@ const AGENTS_HOST = process.env.AGENTS_URL || 'http://localhost:8001';
// gateway (services/api/app/api/v1/endpoints/fusion.py).
const FUSION_HOST = process.env.FUSION_URL || '';
const ENRICHMENT_HOST = process.env.ENRICHMENT_URL || 'http://localhost:8083';
+const OSQUERY_TLS_HOST = process.env.OSQUERY_TLS_URL || 'http://localhost:8090';
const nextConfig = {
reactStrictMode: true,
@@ -62,6 +63,7 @@ const nextConfig = {
NEXT_PUBLIC_TENANT_ID: process.env.NEXT_PUBLIC_TENANT_ID || 'default',
NEXT_PUBLIC_PURPLE_TEAM_API: process.env.NEXT_PUBLIC_PURPLE_TEAM_API || '',
NEXT_PUBLIC_HONEYTOKENS_URL: process.env.NEXT_PUBLIC_HONEYTOKENS_URL || '',
+ NEXT_PUBLIC_OSQUERY_TLS_URL: process.env.NEXT_PUBLIC_OSQUERY_TLS_URL || '',
},
// ─── Same-origin proxy rules ─────────────────────────────────────────────
//
@@ -137,6 +139,11 @@ const nextConfig = {
source: '/api/v1/hunts',
destination: `${AGENTS_HOST}/api/v1/hunts`,
},
+ // osquery-TLS service: pack catalog, FIM events, distributed queries
+ {
+ source: '/api/v1/osquery/:path*',
+ destination: `${OSQUERY_TLS_HOST}/api/v1/osquery/:path*`,
+ },
// Enrichment service (Go service; paths differ from /api/v1 prefix)
{
source: '/api/v1/enrichment/lookup',
diff --git a/apps/web/src/app/(app)/fim/page.tsx b/apps/web/src/app/(app)/fim/page.tsx
new file mode 100644
index 000000000..313ff338f
--- /dev/null
+++ b/apps/web/src/app/(app)/fim/page.tsx
@@ -0,0 +1,12 @@
+import type { Metadata } from 'next';
+import { FimDashboard } from '@/components/fim/FimDashboard';
+
+export const metadata: Metadata = {
+ title: 'File Integrity Monitoring | AiSOC',
+ description:
+ 'Real-time osquery file_events telemetry — track file creation, deletion, and modification across your fleet.',
+};
+
+export default function FimPage() {
+ return <FimDashboard />;
+}
diff --git a/apps/web/src/components/fim/FimDashboard.tsx b/apps/web/src/components/fim/FimDashboard.tsx
new file mode 100644
index 000000000..ea66bf839
--- /dev/null
+++ b/apps/web/src/components/fim/FimDashboard.tsx
@@ -0,0 +1,238 @@
+'use client';
+
+import { useState } from 'react';
+import useSWR from 'swr';
+import toast from 'react-hot-toast';
+import type { FimEventsPage, FimSummary } from '@/lib/osquery-api';
+import { getFimEvents, getFimSummary } from '@/lib/osquery-api';
+import { FimSummaryCards } from './FimSummaryCards';
+import { FimEventsTable } from './FimEventsTable';
+
+const TENANT_ID =
+ typeof window !== 'undefined'
+ ? (process.env.NEXT_PUBLIC_TENANT_ID ?? 'default')
+ : 'default';
+
+const PAGE_SIZE = 25;
+
+const ACTION_OPTIONS = [
+ { label: 'All Actions', value: '' },
+ { label: 'Created', value: 'CREATED' },
+ { label: 'Deleted', value: 'DELETED' },
+ { label: 'Updated', value: 'UPDATED' },
+ { label: 'Attributes Modified', value: 'ATTRIBUTES_MODIFIED' },
+];
+
+const SINCE_OPTIONS = [
+ { label: 'Last 1 hour', value: '1h' },
+ { label: 'Last 6 hours', value: '6h' },
+ { label: 'Last 24 hours', value: '24h' },
+ { label: 'Last 7 days', value: '7d' },
+ { label: 'All time', value: '' },
+];
+
+function sinceToISO(value: string): string | undefined {
+ if (!value) return undefined;
+ const now = new Date();
+ const map: Record<string, number> = {
+ '1h': 60,
+ '6h': 360,
+ '24h': 1440,
+ '7d': 10080,
+ };
+ const minutes = map[value] ?? 0;
+ if (!minutes) return undefined;
+ return new Date(now.getTime() - minutes * 60_000).toISOString();
+}
+
+export function FimDashboard() {
+ const [page, setPage] = useState(1);
+ const [action, setAction] = useState('');
+ const [pathPrefix, setPathPrefix] = useState('');
+ const [since, setSince] = useState('24h');
+
+ const sinceISO = sinceToISO(since);
+
+ // Events feed
+ const eventsKey = [
+ 'fim-events',
+ TENANT_ID,
+ page,
+ action,
+ pathPrefix,
+ sinceISO,
+ ];
+ const {
+ data: eventsData,
+ error: eventsError,
+ isLoading: eventsLoading,
+ } = useSWR<FimEventsPage>(
+ eventsKey,
+ () =>
+ getFimEvents({
+ tenant_id: TENANT_ID,
+ page,
+ page_size: PAGE_SIZE,
+ action: action || undefined,
+ path_prefix: pathPrefix || undefined,
+ since: sinceISO,
+ }),
+ {
+ onError: () => toast.error('Failed to load FIM events'),
+ refreshInterval: 30_000,
+ },
+ );
+
+ // Summary cards
+ const summaryKey = ['fim-summary', TENANT_ID, sinceISO];
+ const {
+ data: summaryData,
+ error: summaryError,
+ isLoading: summaryLoading,
+ } = useSWR<FimSummary>(
+ summaryKey,
+ () => getFimSummary({ tenant_id: TENANT_ID, since: sinceISO }),
+ {
+ onError: () => toast.error('Failed to load FIM summary'),
+ refreshInterval: 60_000,
+ },
+ );
+
+ function handleActionChange(v: string) {
+ setAction(v);
+ setPage(1);
+ }
+ function handleSinceChange(v: string) {
+ setSince(v);
+ setPage(1);
+ }
+ function handlePathChange(v: string) {
+ setPathPrefix(v);
+ setPage(1);
+ }
+
+ return (
+ <div className="space-y-6">
+ {/* Header */}
+ <div className="flex flex-col gap-1">
+ <h1 className="text-xl font-bold text-gray-900">
+ File Integrity Monitoring
+ </h1>
+ <p className="text-sm text-gray-500">
+ Real-time osquery <code className="font-mono">file_events</code>{' '}
+ telemetry for your fleet.
+ </p>
+ </div>
+
+ {/* Filter bar */}
+ <div className="flex flex-wrap items-end gap-3 rounded-xl border border-gray-200 bg-white p-4 shadow-sm">
+ {/* Time window */}
+ <div className="flex flex-col gap-1">
+ <label className="text-xs font-medium text-gray-500">Time window</label>
+ <select
+ value={since}
+ onChange={(e) => handleSinceChange(e.target.value)}
+ className="rounded-md border border-gray-300 bg-white px-3 py-1.5 text-sm shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500"
+ >
+ {SINCE_OPTIONS.map((o) => (
+ <option key={o.value} value={o.value}>
+ {o.label}
+ </option>
+ ))}
+ </select>
+ </div>
+
+ {/* Action filter */}
+ <div className="flex flex-col gap-1">
+ <label className="text-xs font-medium text-gray-500">Action</label>
+ <select
+ value={action}
+ onChange={(e) => handleActionChange(e.target.value)}
+ className="rounded-md border border-gray-300 bg-white px-3 py-1.5 text-sm shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500"
+ >
+ {ACTION_OPTIONS.map((o) => (
+ <option key={o.value} value={o.value}>
+ {o.label}
+ </option>
+ ))}
+ </select>
+ </div>
+
+ {/* Path prefix */}
+ <div className="flex flex-col gap-1 flex-1 min-w-[180px]">
+ <label className="text-xs font-medium text-gray-500">
+ Path prefix
+ </label>
+ <input
+ type="text"
+ value={pathPrefix}
+ onChange={(e) => handlePathChange(e.target.value)}
+ placeholder="/etc/, /home/, C:\\…"
+ className="rounded-md border border-gray-300 px-3 py-1.5 text-sm shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500"
+ />
+ </div>
+ </div>
+
+ {/* Summary cards */}
+ {summaryError ? (
+ <ErrorBanner message="Could not load FIM summary." />
+ ) : summaryLoading ? (
+ <SkeletonCards />
+ ) : summaryData ? (
+ <FimSummaryCards summary={summaryData} />
+ ) : null}
+
+ {/* Events table */}
+ <div>
+ <h2 className="mb-3 text-sm font-semibold text-gray-700">
+ Event Log
+ </h2>
+ {eventsError ? (
+ <ErrorBanner message="Could not load FIM events." />
+ ) : eventsLoading ? (
+ <SkeletonTable />
+ ) : eventsData ? (
+ <FimEventsTable
+ events={eventsData.events}
+ total={eventsData.total}
+ page={eventsData.page}
+ pageSize={PAGE_SIZE}
+ onPageChange={setPage}
+ />
+ ) : null}
+ </div>
+ </div>
+ );
+}
+
+function ErrorBanner({ message }: { message: string }) {
+ return (
+ <div className="rounded-lg border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700">
+ {message}
+ </div>
+ );
+}
+
+function SkeletonCards() {
+ return (
+ <div className="grid grid-cols-2 gap-3 sm:grid-cols-4 animate-pulse">
+ {[...Array(4)].map((_, i) => (
+ <div
+ key={i}
+ className="h-20 rounded-xl border border-gray-200 bg-gray-100"
+ />
+ ))}
+ </div>
+ );
+}
+
+function SkeletonTable() {
+ return (
+ <div className="animate-pulse space-y-2">
+ <div className="h-10 rounded-lg bg-gray-100" />
+ {[...Array(6)].map((_, i) => (
+ <div key={i} className="h-8 rounded bg-gray-50" />
+ ))}
+ </div>
+ );
+}
diff --git a/apps/web/src/components/fim/FimEventsTable.tsx b/apps/web/src/components/fim/FimEventsTable.tsx
new file mode 100644
index 000000000..4348ece1c
--- /dev/null
+++ b/apps/web/src/components/fim/FimEventsTable.tsx
@@ -0,0 +1,167 @@
+'use client';
+
+import clsx from 'clsx';
+import { formatDistanceToNow } from 'date-fns';
+import type { FimEvent } from '@/lib/osquery-api';
+
+interface Props {
+ events: FimEvent[];
+ total: number;
+ page: number;
+ pageSize: number;
+ onPageChange: (page: number) => void;
+}
+
+const ACTION_BADGE: Record<string, string> = {
+ CREATED: 'bg-emerald-100 text-emerald-700',
+ DELETED: 'bg-red-100 text-red-700',
+ UPDATED: 'bg-amber-100 text-amber-700',
+ ATTRIBUTES_MODIFIED: 'bg-sky-100 text-sky-700',
+};
+
+export function FimEventsTable({ events, total, page, pageSize, onPageChange }: Props) {
+ const totalPages = Math.max(1, Math.ceil(total / pageSize));
+
+ if (events.length === 0) {
+ return (
+ <div className="rounded-xl border border-gray-200 bg-white p-10 text-center">
+ <p className="text-sm text-gray-500">No FIM events found for the selected filters.</p>
+ </div>
+ );
+ }
+
+ return (
+ <div className="space-y-2">
+ <div className="overflow-hidden rounded-xl border border-gray-200 bg-white shadow-sm">
+ <table className="min-w-full divide-y divide-gray-200 text-sm">
+ <thead className="bg-gray-50">
+ <tr>
+ <Th>Time</Th>
+ <Th>Action</Th>
+ <Th>Path</Th>
+ <Th>Host</Th>
+ <Th>Process</Th>
+ <Th>User</Th>
+ <Th>SHA-256</Th>
+ </tr>
+ </thead>
+ <tbody className="divide-y divide-gray-100 bg-white">
+ {events.map((e) => (
+ <tr key={e.id} className="hover:bg-gray-50">
+ <Td>
+ <span
+ title={e.event_time}
+ className="whitespace-nowrap text-gray-500"
+ >
+ {formatDistanceToNow(new Date(e.event_time), { addSuffix: true })}
+ </span>
+ </Td>
+ <Td>
+ <span
+ className={clsx(
+ 'rounded-full px-2 py-0.5 text-xs font-semibold',
+ ACTION_BADGE[e.action] ?? 'bg-gray-100 text-gray-600',
+ )}
+ >
+ {e.action}
+ </span>
+ </Td>
+ <Td>
+ <span className="max-w-[260px] truncate font-mono text-xs text-gray-800 block">
+ {e.target_path}
+ </span>
+ </Td>
+ <Td>{e.hostname ?? e.node_key.slice(0, 8)}</Td>
+ <Td>
+ {e.process_name ? (
+ <span className="font-mono text-xs">
+ {e.process_name}
+ {e.pid != null && (
+ <span className="ml-1 text-gray-400">({e.pid})</span>
+ )}
+ </span>
+ ) : (
+ <span className="text-gray-400">—</span>
+ )}
+ </Td>
+ <Td>{e.username ?? <span className="text-gray-400">—</span>}</Td>
+ <Td>
+ {e.sha256 ? (
+ <span
+ title={e.sha256}
+ className="font-mono text-xs text-gray-500"
+ >
+ {e.sha256.slice(0, 12)}…
+ </span>
+ ) : (
+ <span className="text-gray-400">—</span>
+ )}
+ </Td>
+ </tr>
+ ))}
+ </tbody>
+ </table>
+ </div>
+
+ {/* Pagination */}
+ <div className="flex items-center justify-between text-sm text-gray-600">
+ <span>
+ Showing {(page - 1) * pageSize + 1}–
+ {Math.min(page * pageSize, total)} of {total.toLocaleString()} events
+ </span>
+ <div className="flex items-center gap-2">
+ <PaginationButton
+ label="← Prev"
+ disabled={page <= 1}
+ onClick={() => onPageChange(page - 1)}
+ />
+ <span className="text-xs text-gray-500">
+ Page {page} / {totalPages}
+ </span>
+ <PaginationButton
+ label="Next →"
+ disabled={page >= totalPages}
+ onClick={() => onPageChange(page + 1)}
+ />
+ </div>
+ </div>
+ </div>
+ );
+}
+
+function Th({ children }: { children: React.ReactNode }) {
+ return (
+ <th className="px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-gray-500">
+ {children}
+ </th>
+ );
+}
+
+function Td({ children }: { children: React.ReactNode }) {
+ return <td className="px-3 py-2.5 text-gray-700">{children}</td>;
+}
+
+function PaginationButton({
+ label,
+ disabled,
+ onClick,
+}: {
+ label: string;
+ disabled: boolean;
+ onClick: () => void;
+}) {
+ return (
+ <button
+ onClick={onClick}
+ disabled={disabled}
+ className={clsx(
+ 'rounded px-3 py-1 text-xs font-medium transition',
+ disabled
+ ? 'cursor-not-allowed text-gray-300'
+ : 'bg-gray-100 text-gray-700 hover:bg-gray-200',
+ )}
+ >
+ {label}
+ </button>
+ );
+}
diff --git a/apps/web/src/components/fim/FimSummaryCards.tsx b/apps/web/src/components/fim/FimSummaryCards.tsx
new file mode 100644
index 000000000..7fe674b65
--- /dev/null
+++ b/apps/web/src/components/fim/FimSummaryCards.tsx
@@ -0,0 +1,104 @@
+'use client';
+
+import clsx from 'clsx';
+import type { FimSummary } from '@/lib/osquery-api';
+
+interface Props {
+ summary: FimSummary;
+}
+
+const ACTION_STYLES: Record<string, string> = {
+ CREATED: 'bg-emerald-50 text-emerald-700 border-emerald-200',
+ DELETED: 'bg-red-50 text-red-700 border-red-200',
+ UPDATED: 'bg-amber-50 text-amber-700 border-amber-200',
+ ATTRIBUTES_MODIFIED: 'bg-sky-50 text-sky-700 border-sky-200',
+};
+
+export function FimSummaryCards({ summary }: Props) {
+ return (
+ <div className="space-y-4">
+ {/* Top-level KPIs */}
+ <div className="grid grid-cols-2 gap-3 sm:grid-cols-4">
+ <KpiCard label="Total Events" value={summary.total_events.toLocaleString()} />
+ <KpiCard label="Active Nodes" value={summary.active_nodes.toLocaleString()} />
+ <KpiCard
+ label="Unique Paths"
+ value={summary.top_paths.length.toLocaleString()}
+ note="(top 10 shown)"
+ />
+ <KpiCard
+ label="Action Types"
+ value={summary.by_action.length.toLocaleString()}
+ />
+ </div>
+
+ {/* By-action breakdown */}
+ {summary.by_action.length > 0 && (
+ <div>
+ <h3 className="mb-2 text-xs font-semibold uppercase tracking-wider text-gray-500">
+ Events by Action
+ </h3>
+ <div className="flex flex-wrap gap-2">
+ {summary.by_action.map((a) => (
+ <span
+ key={a.action}
+ className={clsx(
+ 'inline-flex items-center gap-1.5 rounded-full border px-3 py-1 text-sm font-medium',
+ ACTION_STYLES[a.action] ?? 'bg-gray-50 text-gray-700 border-gray-200',
+ )}
+ >
+ {a.action}
+ <span className="rounded-full bg-white/70 px-1.5 py-0.5 text-xs font-bold">
+ {a.count.toLocaleString()}
+ </span>
+ </span>
+ ))}
+ </div>
+ </div>
+ )}
+
+ {/* Top paths */}
+ {summary.top_paths.length > 0 && (
+ <div>
+ <h3 className="mb-2 text-xs font-semibold uppercase tracking-wider text-gray-500">
+ Top File Paths
+ </h3>
+ <div className="overflow-hidden rounded-lg border border-gray-200 bg-white">
+ {summary.top_paths.map((p, i) => (
+ <div
+ key={p.target_path}
+ className={clsx(
+ 'flex items-center justify-between px-3 py-2 text-sm',
+ i !== summary.top_paths.length - 1 && 'border-b border-gray-100',
+ )}
+ >
+ <span className="truncate font-mono text-xs text-gray-700">{p.target_path}</span>
+ <span className="ml-4 shrink-0 rounded bg-gray-100 px-2 py-0.5 text-xs font-semibold text-gray-600">
+ {p.count.toLocaleString()}
+ </span>
+ </div>
+ ))}
+ </div>
+ </div>
+ )}
+ </div>
+ );
+}
+
+function KpiCard({
+ label,
+ value,
+ note,
+}: {
+ label: string;
+ value: string;
+ note?: string;
+}) {
+ return (
+ <div className="rounded-xl border border-gray-200 bg-white px-4 py-3 shadow-sm">
+ <p className="text-xs font-medium text-gray-500">{label}</p>
+ <p className="mt-1 text-2xl font-bold text-gray-900">{value}</p>
+ {note && <p className="mt-0.5 text-xs text-gray-400">{note}</p>}
+ </div>
+ );
+}
diff --git a/apps/web/src/components/layout/Sidebar.tsx b/apps/web/src/components/layout/Sidebar.tsx
index 7654c9fb2..9c9c87acf 100644
--- a/apps/web/src/components/layout/Sidebar.tsx
+++ b/apps/web/src/components/layout/Sidebar.tsx
@@ -228,6 +228,11 @@ const navSections: NavSection[] = [
href: '/marketplace',
icon: <MarketplaceIcon />,
},
+ {
+ label: 'File Integrity (FIM)',
+ href: '/fim',
+ icon: <FolderIcon />,
+ },
{
label: 'Honeytokens',
href: '/honeytokens',
diff --git a/apps/web/src/lib/osquery-api.ts b/apps/web/src/lib/osquery-api.ts
new file mode 100644
index 000000000..e371278a5
--- /dev/null
+++ b/apps/web/src/lib/osquery-api.ts
@@ -0,0 +1,95 @@
+/**
+ * Typed HTTP client for the osquery-tls service.
+ *
+ * All requests are issued to `/api/v1/osquery/*` — Next.js proxies that
+ * to OSQUERY_TLS_HOST via the rewrite in next.config.js.
+ */
+
+const OSQUERY_BASE =
+ (process.env.NEXT_PUBLIC_OSQUERY_TLS_URL ?? '') + '/api/v1/osquery';
+
+// ─── Types ───────────────────────────────────────────────────────────────────
+
+export interface FimEvent {
+ id: number;
+ tenant_id: string;
+ node_key: string;
+ hostname: string | null;
+ target_path: string;
+ action: 'CREATED' | 'DELETED' | 'UPDATED' | 'ATTRIBUTES_MODIFIED' | string;
+ md5: string | null;
+ sha256: string | null;
+ pid: number | null;
+ ppid: number | null;
+ process_name: string | null;
+ username: string | null;
+ event_time: string; // ISO-8601
+ ingested_at: string; // ISO-8601
+}
+
+export interface FimEventsPage {
+ events: FimEvent[];
+ total: number;
+ page: number;
+ page_size: number;
+}
+
+export interface FimActionCount {
+ action: string;
+ count: number;
+}
+
+export interface FimPathCount {
+ target_path: string;
+ count: number;
+}
+
+export interface FimSummary {
+ total_events: number;
+ by_action: FimActionCount[];
+ top_paths: FimPathCount[];
+ active_nodes: number;
+}
+
+export interface FimEventsParams {
+ tenant_id: string;
+ page?: number;
+ page_size?: number;
+ action?: string;
+ path_prefix?: string;
+ node_key?: string;
+ since?: string; // ISO-8601
+}
+
+export interface FimSummaryParams {
+ tenant_id: string;
+ since?: string; // ISO-8601
+}
+
+// ─── API helpers ─────────────────────────────────────────────────────────────
+
+async function get<T>(path: string, params?: Record<string, string | number | undefined>): Promise<T> {
+ const url = new URL(`${OSQUERY_BASE}${path}`, window.location.origin);
+ if (params) {
+ for (const [k, v] of Object.entries(params)) {
+ if (v !== undefined) url.searchParams.set(k, String(v));
+ }
+ }
+ const res = await fetch(url.toString());
+ if (!res.ok) {
+ const text = await res.text().catch(() => '');
+ throw new Error(`osquery-api ${res.status}: ${text}`);
+ }
+ return res.json() as Promise<T>;
+}
+
+// ─── FIM endpoints ────────────────────────────────────────────────────────────
+
+export function getFimEvents(params: FimEventsParams): Promise<FimEventsPage> {
+ const { tenant_id, ...rest } = params;
+ return get<FimEventsPage>('/fim/events', { tenant_id, ...rest });
+}
+
+export function getFimSummary(params: FimSummaryParams): Promise<FimSummary> {
+ return get<FimSummary>('/fim/summary', params as Record<string, string>);
+}
diff --git a/detections/endpoint/fim-binary-dropped-writable-dir.yaml b/detections/endpoint/fim-binary-dropped-writable-dir.yaml
new file mode 100644
index 000000000..6ecd8a4aa
--- /dev/null
+++ b/detections/endpoint/fim-binary-dropped-writable-dir.yaml
@@ -0,0 +1,43 @@
+id: det-endpoint-282
+name: Executable Dropped in World-Writable Directory (FIM)
+description: >
+ An osquery file_events CREATED event was recorded for a file with a common
+ executable extension (.sh, .py, .pl, .rb, .elf, .bin, no extension + executable
+ path) under a world-writable path (/tmp, /var/tmp, /dev/shm, /run/shm).
+ This is a classic indicator of malware staging, web shell deployment, or
+ attacker tool transfer (T1027, T1059, T1036.005).
+version: 1.0.0
+severity: medium
+tags:
+ - mitre.attack.t1027 # Obfuscated Files or Information
+ - mitre.attack.t1059 # Command and Scripting Interpreter
+ - mitre.attack.t1036.005 # Masquerading: Match Legitimate Name or Location
+ - mitre.attack.t1570 # Lateral Tool Transfer
+ - tlp.white
+ - data_source.osquery
+ - data_source.fim
+category: endpoint
+log_source:
+ product: osquery
+ service: file_events
+detection:
+ condition: |
+ action == "CREATED"
+ AND target_path STARTS_WITH_ANY ["/tmp/", "/var/tmp/", "/dev/shm/", "/run/shm/"]
+ AND (
+ target_path ENDS_WITH_ANY [".sh", ".py", ".pl", ".rb", ".elf", ".bin", ".so"]
+ OR target_path MATCHES "/(tmp|var/tmp|dev/shm|run/shm)/[^./]+"
+ )
+false_positives:
+ - Build/CI pipelines that write compiled artifacts to /tmp
+ - Package managers that stage files in /tmp during installation
+ - Container entrypoint scripts copied from image layers to /tmp
+ - Legitimate Python/Ruby scripts deployed to /tmp by config management
+playbook: tpl-defense-evasion
+enabled: true
+author: AiSOC
+references:
+ - https://attack.mitre.org/techniques/T1036/005/
+ - https://attack.mitre.org/techniques/T1059/
+created: '2026-05-10'
+modified: '2026-05-10'
diff --git a/detections/endpoint/fim-ld-preload-modified.yaml b/detections/endpoint/fim-ld-preload-modified.yaml
new file mode 100644
index 000000000..fd8a49d08
--- /dev/null
+++ b/detections/endpoint/fim-ld-preload-modified.yaml
@@ -0,0 +1,41 @@
+id: det-endpoint-283
+name: LD_PRELOAD / ld.so.preload Tampered (FIM)
+description: >
+ The dynamic linker preload file /etc/ld.so.preload or any shared library
+ under /etc/ld.so.conf.d/ was created or modified, as detected by osquery
+ file_events via the AiSOC FIM pipeline. Attackers use ld.so.preload to
+ inject arbitrary shared libraries into every process at startup, achieving
+ rootkit-level stealth, credential capture, or privilege escalation
+ (T1574.006 – Dynamic Linker Hijacking).
+version: 1.0.0
+severity: critical
+tags:
+ - mitre.attack.t1574.006 # Hijack Execution Flow: Dynamic Linker Hijacking
+ - mitre.attack.t1014 # Rootkit
+ - mitre.attack.t1548.001 # Abuse Elevation Control Mechanism: Setuid/Setgid
+ - tlp.white
+ - data_source.osquery
+ - data_source.fim
+category: endpoint
+log_source:
+ product: osquery
+ service: file_events
+detection:
+ condition: |
+ action IN ["CREATED", "UPDATED", "ATTRIBUTES_MODIFIED"]
+ AND target_path STARTS_WITH_ANY [
+ "/etc/ld.so.preload",
+ "/etc/ld.so.conf.d/"
+ ]
+false_positives:
+ - Legitimate security tools (e.g. Falco eBPF libraries) that add entries to
+ /etc/ld.so.conf.d/ during installation
+ - System package updates that refresh shared library search paths
+playbook: tpl-persistence
+enabled: true
+author: AiSOC
+references:
+ - https://attack.mitre.org/techniques/T1574/006/
+ - https://man7.org/linux/man-pages/man8/ld.so.8.html
+created: '2026-05-10'
+modified: '2026-05-10'
diff --git a/detections/endpoint/fim-sensitive-file-modified.yaml b/detections/endpoint/fim-sensitive-file-modified.yaml
new file mode 100644
index 000000000..c43843288
--- /dev/null
+++ b/detections/endpoint/fim-sensitive-file-modified.yaml
@@ -0,0 +1,52 @@
+id: det-endpoint-281
+name: Sensitive System File Modified (FIM)
+description: >
+ A file in a sensitive system path (/etc/passwd, /etc/shadow, /etc/sudoers,
+ /etc/crontab, /etc/hosts, /etc/ssh/sshd_config, /etc/ld.so.*) was created,
+ deleted, or modified as reported by osquery file_events via the AiSOC FIM
+ pipeline. Adversaries commonly target these files for credential theft
+ (T1003.008), persistence (T1037, T1053.003), lateral movement, and privilege
+ escalation (T1548.001).
+version: 1.0.0
+severity: high
+tags:
+ - mitre.attack.t1003.008 # OS Credential Dumping: /etc/passwd and /etc/shadow
+ - mitre.attack.t1037 # Boot or Logon Initialization Scripts
+ - mitre.attack.t1053.003 # Scheduled Task/Job: Cron
+ - mitre.attack.t1548.001 # Abuse Elevation Control Mechanism: Setuid/Setgid
+ - tlp.white
+ - data_source.osquery
+ - data_source.fim
+category: endpoint
+log_source:
+ product: osquery
+ service: file_events
+detection:
+ condition: |
+ action IN ["CREATED", "DELETED", "UPDATED", "ATTRIBUTES_MODIFIED"]
+ AND target_path STARTS_WITH_ANY [
+ "/etc/passwd",
+ "/etc/shadow",
+ "/etc/gshadow",
+ "/etc/sudoers",
+ "/etc/sudoers.d/",
+ "/etc/crontab",
+ "/etc/cron.",
+ "/etc/hosts",
+ "/etc/ssh/sshd_config",
+ "/etc/ld.so.conf",
+ "/etc/ld.so.preload"
+ ]
+false_positives:
+ - System package manager updates (apt, yum, dnf) touching /etc/passwd, /etc/shadow
+ - Legitimate SSH configuration changes by ops team
+ - cron package installation/update modifying /etc/crontab
+ - SSO/LDAP integration tooling updating /etc/nsswitch.conf
+playbook: tpl-credential-access
+enabled: true
+author: AiSOC
+references:
+ - https://attack.mitre.org/techniques/T1003/008/
+ - https://attack.mitre.org/techniques/T1053/003/
+created: '2026-05-10'
+modified: '2026-05-10'
diff --git a/detections/endpoint/fim-ssh-authorized-keys-changed.yaml b/detections/endpoint/fim-ssh-authorized-keys-changed.yaml
new file mode 100644
index 000000000..e51f359b9
--- /dev/null
+++ b/detections/endpoint/fim-ssh-authorized-keys-changed.yaml
@@ -0,0 +1,41 @@
+id: det-endpoint-284
+name: SSH authorized_keys File Modified (FIM)
+description: >
+ An osquery file_events event recorded a change (CREATED, UPDATED, or
+ ATTRIBUTES_MODIFIED) to any ~/.ssh/authorized_keys file across the fleet.
+ Adversaries add their own public keys to authorized_keys files to establish
+ persistent SSH backdoors that survive password resets and remain invisible to
+ normal login monitoring (T1098.004 – Account Manipulation: SSH Authorized Keys).
+version: 1.0.0
+severity: high
+tags:
+ - mitre.attack.t1098.004 # Account Manipulation: SSH Authorized Keys
+ - mitre.attack.t1078 # Valid Accounts
+ - mitre.attack.t1136 # Create Account
+ - tlp.white
+ - data_source.osquery
+ - data_source.fim
+category: endpoint
+log_source:
+ product: osquery
+ service: file_events
+detection:
+ condition: |
+ action IN ["CREATED", "UPDATED", "ATTRIBUTES_MODIFIED"]
+ AND (
+ target_path MATCHES ".+/\\.ssh/authorized_keys$"
+ OR target_path MATCHES ".+/\\.ssh/authorized_keys2$"
+ )
+false_positives:
+ - Automated config management (Ansible, Chef, Salt) that rotates SSH keys
+ - Initial host provisioning scripts that deploy team public keys
+ - Legitimate user key rotation via a verified deployment pipeline
+ - CI/CD runners that add deployment keys to service accounts
+playbook: tpl-persistence
+enabled: true
+author: AiSOC
+references:
+ - https://attack.mitre.org/techniques/T1098/004/
+ - https://www.openssh.com/manual.html
+created: '2026-05-10'
+modified: '2026-05-10'
diff --git a/detections/fixtures/negative/fim-binary-dropped-writable-dir.json b/detections/fixtures/negative/fim-binary-dropped-writable-dir.json
new file mode 100644
index 000000000..15dc07cb2
--- /dev/null
+++ b/detections/fixtures/negative/fim-binary-dropped-writable-dir.json
@@ -0,0 +1,11 @@
+{
+ "action": "CREATED",
+ "target_path": "/home/deploy/app/server.py",
+ "hostname": "app-server-01",
+ "node_key": "xyz789uvw012",
+ "tenant_id": "acme",
+ "process_name": "rsync",
+ "pid": 5501,
+ "username": "deploy",
+ "event_time": "2026-05-10T09:10:00Z"
+}
diff --git a/detections/fixtures/negative/fim-ld-preload-modified.json b/detections/fixtures/negative/fim-ld-preload-modified.json
new file mode 100644
index 000000000..9da498829
--- /dev/null
+++ b/detections/fixtures/negative/fim-ld-preload-modified.json
@@ -0,0 +1,11 @@
+{
+ "action": "UPDATED",
+ "target_path": "/etc/ld.so.conf",
+ "hostname": "build-server-01",
+ "node_key": "bld001zzz",
+ "tenant_id": "acme",
+ "process_name": "ldconfig",
+ "pid": 301,
+ "username": "root",
+ "event_time": "2026-05-10T08:00:12Z"
+}
diff --git a/detections/fixtures/negative/fim-sensitive-file-modified.json b/detections/fixtures/negative/fim-sensitive-file-modified.json
new file mode 100644
index 000000000..eabdc26ae
--- /dev/null
+++ b/detections/fixtures/negative/fim-sensitive-file-modified.json
@@ -0,0 +1,11 @@
+{
+ "action": "CREATED",
+ "target_path": "/var/log/auth.log",
+ "hostname": "linux-host-42",
+ "node_key": "abc123def456",
+ "tenant_id": "acme",
+ "process_name": "rsyslogd",
+ "pid": 1022,
+ "username": "syslog",
+ "event_time": "2026-05-10T14:22:00Z"
+}
diff --git a/detections/fixtures/negative/fim-ssh-authorized-keys-changed.json b/detections/fixtures/negative/fim-ssh-authorized-keys-changed.json
new file mode 100644
index 000000000..a85f7dca4
--- /dev/null
+++ b/detections/fixtures/negative/fim-ssh-authorized-keys-changed.json
@@ -0,0 +1,11 @@
+{
+ "action": "CREATED",
+ "target_path": "/home/alice/.ssh/known_hosts",
+ "hostname": "workstation-12",
+ "node_key": "ws012ccc",
+ "tenant_id": "acme",
+ "process_name": "ssh",
+ "pid": 8810,
+ "username": "alice",
+ "event_time": "2026-05-10T11:33:00Z"
+}
diff --git a/detections/fixtures/positive/fim-binary-dropped-writable-dir.json b/detections/fixtures/positive/fim-binary-dropped-writable-dir.json
new file mode 100644
index 000000000..e195f52f0
--- /dev/null
+++ b/detections/fixtures/positive/fim-binary-dropped-writable-dir.json
@@ -0,0 +1,14 @@
+{
+ "action": "CREATED",
+ "target_path": "/tmp/rev.sh",
+ "hostname": "web-server-07",
+ "node_key": "xyz789uvw012",
+ "tenant_id": "acme",
+ "process_name": "curl",
+ "pid": 17842,
+ "ppid": 17840,
+ "username": "www-data",
+ "md5": "098f6bcd4621d373cade4e832627b4f6",
+ "sha256": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
+ "event_time": "2026-05-10T14:30:05Z"
+}
diff --git a/detections/fixtures/positive/fim-ld-preload-modified.json b/detections/fixtures/positive/fim-ld-preload-modified.json
new file mode 100644
index 000000000..9e7d1eacb
--- /dev/null
+++ b/detections/fixtures/positive/fim-ld-preload-modified.json
@@ -0,0 +1,13 @@
+{
+ "action": "CREATED",
+ "target_path": "/etc/ld.so.preload",
+ "hostname": "db-node-03",
+ "node_key": "ldp333aaa",
+ "tenant_id": "acme",
+ "process_name": "bash",
+ "pid": 9901,
+ "ppid": 9899,
+ "username": "root",
+ "sha256": "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef",
+ "event_time": "2026-05-10T03:12:44Z"
+}
diff --git a/detections/fixtures/positive/fim-sensitive-file-modified.json b/detections/fixtures/positive/fim-sensitive-file-modified.json
new file mode 100644
index 000000000..3c4eb91d4
--- /dev/null
+++ b/detections/fixtures/positive/fim-sensitive-file-modified.json
@@ -0,0 +1,14 @@
+{
+ "action": "UPDATED",
+ "target_path": "/etc/passwd",
+ "hostname": "linux-host-42",
+ "node_key": "abc123def456",
+ "tenant_id": "acme",
+ "process_name": "useradd",
+ "pid": 4421,
+ "ppid": 4420,
+ "username": "root",
+ "md5": "d41d8cd98f00b204e9800998ecf8427e",
+ "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
+ "event_time": "2026-05-10T14:22:11Z"
+}
diff --git a/detections/fixtures/positive/fim-ssh-authorized-keys-changed.json b/detections/fixtures/positive/fim-ssh-authorized-keys-changed.json
new file mode 100644
index 000000000..7f51a60b9
--- /dev/null
+++ b/detections/fixtures/positive/fim-ssh-authorized-keys-changed.json
@@ -0,0 +1,13 @@
+{
+ "action": "UPDATED",
+ "target_path": "/root/.ssh/authorized_keys",
+ "hostname": "prod-api-02",
+ "node_key": "ssh111bbb",
+ "tenant_id": "acme",
+ "process_name": "bash",
+ "pid": 22341,
+ "ppid": 22340,
+ "username": "root",
+ "sha256": "cafebabecafebabecafebabecafebabecafebabecafebabecafebabecafebabe",
+ "event_time": "2026-05-10T02:47:19Z"
+}
diff --git a/packs/README.md b/packs/README.md
new file mode 100644
index 000000000..8be7c736d
--- /dev/null
+++ b/packs/README.md
@@ -0,0 +1,66 @@
+# AiSOC Osquery Pack Format
+
+This directory contains curated osquery packs in the AiSOC YAML format.
+
+## Schema
+
+Each pack file is a YAML document with the following top-level keys:
+
+```yaml
+id: aisoc-fim-baseline # Unique pack identifier (kebab-case)
+name: AiSOC File Integrity Baseline
+version: 1.0.0 # Semver
+platforms: [linux, darwin] # Supported platforms: linux | darwin | windows
+description: |
+ Human-readable description of what this pack covers.
+discovery:
+ - SELECT pid FROM processes WHERE name = 'osqueryd';
+queries:
+ <query_name>:
+ sql: SELECT ... # SQL query string
+ interval: 60 # Poll interval in seconds
+ severity: high # info | low | medium | high
+ description: ...
+ mitre: [T1098] # Optional MITRE ATT&CK technique IDs
+ references:
+ - https://attack.mitre.org/techniques/T1098/
+file_paths: # Optional FIM paths section
+ <group_name>:
+ - /path/to/watch
+ - /path/with/%%/glob # %% = recursive glob
+```
+
+## Compiling to Canonical Osquery JSON
+
+The `pack_loader` (in `services/api/app/services/pack_loader.py`) reads all YAML files and exposes them as validated `OsqueryPack` Pydantic models.
+
+The `pack_resolver` (in `services/osquery-tls/app/services/pack_resolver.py`) takes an enrolled node's tenant ID, looks up assigned packs, and compiles them into the osquery TLS config JSON shape:
+
+```json
+{
+ "schedule": { ... },
+ "packs": { "<pack_id>": { ... } },
+ "file_paths": { ... }
+}
+```
+
+## Rendering for osctrl / FleetDM
+
+Use `GET /v1/packs/{id}/render?format=osctrl|fleetdm|osquery-json` to download a pack in the native format for manual import into your fleet manager. See [docs/packs/distribution.md](../apps/docs/docs/packs/distribution.md) for import walkthroughs.
+
+## Curated Packs
+
+| ID | Description | Platforms | MITRE |
+|----|-------------|-----------|-------|
+| `aisoc-fim-baseline` | Critical config/credential file integrity | linux, darwin | T1098, T1078 |
+| `aisoc-fim-credentials` | Cloud/k8s credential file monitoring | linux, darwin | T1552 |
+| `aisoc-attck-persistence` | Cron, systemd, launchd, Run key persistence | linux, darwin | T1547, T1543 |
+| `aisoc-attck-defense-evasion` | Disabled services, cleared logs | linux, darwin | T1562, T1070 |
+| `aisoc-inventory-baseline` | OS/kernel/package inventory (info) | linux, darwin, windows | — |
+
+## Contributing
+
+1. Copy an existing pack as a template.
+2. Validate with `python scripts/validate_packs.py packs/<your-pack>.yaml`.
+3. Add a fixture under `detections/fixtures/` if the pack drives detections.
+4. Update the table above and open a PR.
diff --git a/packs/aisoc-attck-defense-evasion.yaml b/packs/aisoc-attck-defense-evasion.yaml
new file mode 100644
index 000000000..edd21c43f
--- /dev/null
+++ b/packs/aisoc-attck-defense-evasion.yaml
@@ -0,0 +1,153 @@
+id: aisoc-attck-defense-evasion
+name: AiSOC ATT&CK — Defense Evasion Detection
+version: 1.0.0
+platforms: [linux, darwin]
+description: |
+ Detects common defense evasion techniques including process injection signals,
+ binary masquerading, log clearing, and kernel module manipulation.
+ Aligns with MITRE ATT&CK T1562 (Impair Defenses), T1036 (Masquerading),
+ and T1014 (Rootkit).
+
+queries:
+ processes_with_deleted_binary:
+ sql: >
+ SELECT p.pid, p.name, p.path, p.cmdline, p.uid, p.gid, p.cwd,
+ p.start_time, f.inode
+ FROM processes p
+ LEFT JOIN file f ON p.path = f.path
+ WHERE f.inode IS NULL
+ AND p.path != ''
+ interval: 120
+ severity: high
+ description: Detect processes whose backing binary has been deleted (common in memory-only malware)
+ mitre: [T1055, T1027]
+ references:
+ - https://attack.mitre.org/techniques/T1055/
+ - https://attack.mitre.org/techniques/T1027/
+
+ hidden_processes:
+ sql: >
+ SELECT pid, name, path, cmdline, uid, gid
+ FROM processes
+ WHERE name LIKE '.%'
+ OR path LIKE '%/.'
+ OR cmdline LIKE '%--%'
+ interval: 120
+ severity: medium
+ description: Detect processes with hidden or suspicious naming
+ mitre: [T1036.005]
+ references:
+ - https://attack.mitre.org/techniques/T1036/005/
+
+ suid_binaries:
+ sql: >
+ SELECT f.path, f.filename, f.size, f.uid, f.gid, f.mode, f.mtime,
+ f.atime, f.ctime
+ FROM file f
+ WHERE (f.path LIKE '/usr/local/bin/%'
+ OR f.path LIKE '/tmp/%'
+ OR f.path LIKE '/var/%'
+ OR f.path LIKE '/dev/%'
+ OR f.path LIKE '/home/%')
+ AND f.mode LIKE '%s%'
+ interval: 600
+ severity: high
+ description: Detect unusual SUID/SGID binaries in non-standard locations
+ mitre: [T1548.001]
+ references:
+ - https://attack.mitre.org/techniques/T1548/001/
+
+ kernel_modules:
+ sql: >
+ SELECT name, size, used_by, status, address
+ FROM kernel_modules
+ WHERE status NOT IN ('Live', 'Loading')
+ interval: 300
+ severity: high
+ description: Detect kernel modules in unusual states (potential rootkit)
+ mitre: [T1014]
+ references:
+ - https://attack.mitre.org/techniques/T1014/
+
+ ld_preload:
+ sql: >
+ SELECT name, value
+ FROM environment
+ WHERE name IN ('LD_PRELOAD', 'LD_LIBRARY_PATH', 'DYLD_INSERT_LIBRARIES')
+ interval: 300
+ severity: high
+ description: Detect LD_PRELOAD or DYLD_INSERT_LIBRARIES environment hijacking
+ mitre: [T1574.006]
+ references:
+ - https://attack.mitre.org/techniques/T1574/006/
+
+ ld_preload_file:
+ sql: >
+ SELECT target_path, action, transaction_id, time, inode, uid, gid,
+ md5, sha256
+ FROM file_events
+ WHERE target_path = '/etc/ld.so.preload'
+ OR target_path = '/etc/ld.so.conf'
+ OR target_path LIKE '/etc/ld.so.conf.d/%'
+ interval: 60
+ severity: high
+ description: Detect changes to ld.so preload configuration
+ mitre: [T1574.006]
+ references:
+ - https://attack.mitre.org/techniques/T1574/006/
+
+ auditd_tampering:
+ sql: >
+ SELECT target_path, action, transaction_id, time, inode, uid, gid,
+ md5, sha256
+ FROM file_events
+ WHERE target_path IN ('/etc/audit/auditd.conf',
+ '/etc/audit/rules.d',
+ '/etc/audit/audit.rules')
+ OR target_path LIKE '/etc/audit/rules.d/%'
+ interval: 60
+ severity: high
+ description: Detect modifications to auditd configuration (defense evasion)
+ mitre: [T1562.001]
+ references:
+ - https://attack.mitre.org/techniques/T1562/001/
+
+ log_file_tampering:
+ sql: >
+ SELECT target_path, action, transaction_id, time, inode, uid, gid,
+ md5, sha256
+ FROM file_events
+ WHERE (target_path LIKE '/var/log/%'
+ OR target_path LIKE '/var/adm/%')
+ AND action IN ('DELETED', 'UPDATED')
+ interval: 60
+ severity: high
+ description: Detect deletion or truncation of log files
+ mitre: [T1070.002]
+ references:
+ - https://attack.mitre.org/techniques/T1070/002/
+
+ tmp_executable:
+ sql: >
+ SELECT p.pid, p.name, p.path, p.cmdline, p.uid, f.mode
+ FROM processes p
+ JOIN file f ON p.path = f.path
+ WHERE p.path LIKE '/tmp/%'
+ OR p.path LIKE '/dev/shm/%'
+ OR p.path LIKE '/var/tmp/%'
+ interval: 120
+ severity: high
+ description: Detect processes executing from /tmp, /dev/shm, or /var/tmp
+ mitre: [T1036.005, T1564]
+ references:
+ - https://attack.mitre.org/techniques/T1036/005/
+
+file_paths:
+ ld_preload:
+ - /etc/ld.so.preload
+ - /etc/ld.so.conf
+ - /etc/ld.so.conf.d/%%
+ audit_config:
+ - /etc/audit/%%
+ log_dirs:
+ - /var/log/%%
diff --git a/packs/aisoc-attck-persistence.yaml b/packs/aisoc-attck-persistence.yaml
new file mode 100644
index 000000000..0c52f0aec
--- /dev/null
+++ b/packs/aisoc-attck-persistence.yaml
@@ -0,0 +1,136 @@
+id: aisoc-attck-persistence
+name: AiSOC ATT&CK — Persistence Detection
+version: 1.0.0
+platforms: [linux, darwin]
+description: |
+ Detects persistence mechanisms including cron jobs, systemd unit files,
+ launchd plists, and other startup/scheduled task modifications.
+ Aligns with MITRE ATT&CK T1547 (Boot or Logon Autostart Execution) and
+ T1543 (Create or Modify System Process).
+
+queries:
+ cron_jobs:
+ sql: >
+ SELECT command, path, minute, hour, day_of_month, month, day_of_week
+ FROM crontab
+ interval: 300
+ severity: medium
+ description: Enumerate all cron jobs across system and user crontabs
+ mitre: [T1053.003]
+ references:
+ - https://attack.mitre.org/techniques/T1053/003/
+
+ cron_file_events:
+ sql: >
+ SELECT target_path, action, transaction_id, time, inode, uid, gid,
+ md5, sha256
+ FROM file_events
+ WHERE target_path LIKE '/etc/cron%'
+ OR target_path LIKE '/var/spool/cron/%'
+ OR target_path LIKE '/etc/at%'
+ interval: 60
+ severity: high
+ description: Detect file system changes to cron directories
+ mitre: [T1053.003]
+ references:
+ - https://attack.mitre.org/techniques/T1053/003/
+
+ systemd_units:
+ sql: >
+ SELECT id, description, load_state, active_state, sub_state,
+ fragment_path, user, group
+ FROM systemd_units
+ WHERE active_state = 'active'
+ AND (id LIKE '%.service' OR id LIKE '%.timer' OR id LIKE '%.socket')
+ interval: 300
+ severity: low
+ description: Enumerate active systemd units (services, timers, sockets)
+ mitre: [T1543.002]
+ references:
+ - https://attack.mitre.org/techniques/T1543/002/
+
+ systemd_unit_file_events:
+ sql: >
+ SELECT target_path, action, transaction_id, time, inode, uid, gid,
+ md5, sha256
+ FROM file_events
+ WHERE target_path LIKE '/etc/systemd/system/%'
+ OR target_path LIKE '/lib/systemd/system/%'
+ OR target_path LIKE '/usr/lib/systemd/system/%'
+ OR target_path LIKE '/home/%/.config/systemd/user/%'
+ interval: 60
+ severity: high
+ description: Detect modifications to systemd unit files
+ mitre: [T1543.002]
+ references:
+ - https://attack.mitre.org/techniques/T1543/002/
+
+ launchd_agents:
+ sql: >
+ SELECT path, name, program, program_arguments, run_at_load, on_demand,
+ keep_alive, start_interval, watch_paths
+ FROM launchd
+ WHERE run_at_load = 1
+ interval: 300
+ severity: medium
+ description: Enumerate LaunchAgents and LaunchDaemons set to run at load (macOS)
+ mitre: [T1543.004]
+ references:
+ - https://attack.mitre.org/techniques/T1543/004/
+
+ launchd_file_events:
+ sql: >
+ SELECT target_path, action, transaction_id, time, inode, uid, gid,
+ md5, sha256
+ FROM file_events
+ WHERE target_path LIKE '/Library/LaunchAgents/%'
+ OR target_path LIKE '/Library/LaunchDaemons/%'
+ OR target_path LIKE '/System/Library/LaunchAgents/%'
+ OR target_path LIKE '/System/Library/LaunchDaemons/%'
+ OR target_path LIKE '/Users/%/Library/LaunchAgents/%'
+ interval: 60
+ severity: high
+ description: Detect file changes in LaunchAgent/Daemon directories (macOS)
+ mitre: [T1543.004]
+ references:
+ - https://attack.mitre.org/techniques/T1543/004/
+
+ startup_items:
+ sql: >
+ SELECT path, args, type, enabled
+ FROM startup_items
+ interval: 300
+ severity: medium
+ description: Enumerate startup items
+ mitre: [T1547]
+ references:
+ - https://attack.mitre.org/techniques/T1547/
+
+ login_items:
+ sql: >
+ SELECT name, path, args, source, status, hidden, username
+ FROM loginwindow_items
+ interval: 300
+ severity: medium
+ description: Enumerate macOS login window items
+ mitre: [T1547.015]
+ references:
+ - https://attack.mitre.org/techniques/T1547/015/
+
+file_paths:
+ cron_dirs:
+ - /etc/cron.d/%%
+ - /etc/cron.daily/%%
+ - /etc/cron.hourly/%%
+ - /etc/cron.monthly/%%
+ - /etc/cron.weekly/%%
+ - /var/spool/cron/%%
+ systemd_dirs:
+ - /etc/systemd/system/%%
+ - /lib/systemd/system/%%
+ - /usr/lib/systemd/system/%%
+ launchd_dirs:
+ - /Library/LaunchAgents/%%
+ - /Library/LaunchDaemons/%%
+ - /System/Library/LaunchAgents/%%
+ - /System/Library/LaunchDaemons/%%
diff --git a/packs/aisoc-fim-baseline.yaml b/packs/aisoc-fim-baseline.yaml
new file mode 100644
index 000000000..ccf4fdfbb
--- /dev/null
+++ b/packs/aisoc-fim-baseline.yaml
@@ -0,0 +1,92 @@
+id: aisoc-fim-baseline
+name: AiSOC File Integrity — Baseline
+version: 1.0.0
+platforms: [linux, darwin]
+description: |
+ Monitors critical system configuration and credential files for unauthorized
+ modifications. Covers /etc/passwd, /etc/shadow, /etc/sudoers, and SSH
+ authorized_keys files. Aligns with MITRE ATT&CK T1098 (Account Manipulation)
+ and T1078 (Valid Accounts).
+
+queries:
+ passwd_changes:
+ sql: >
+ SELECT target_path, action, transaction_id, time, inode, uid, gid,
+ md5, sha256, atime, mtime, ctime
+ FROM file_events
+ WHERE target_path IN ('/etc/passwd', '/etc/shadow', '/etc/group', '/etc/gshadow')
+ interval: 30
+ severity: high
+ description: Detect writes to /etc/passwd, /etc/shadow, /etc/group
+ mitre: [T1098, T1078]
+ references:
+ - https://attack.mitre.org/techniques/T1098/
+
+ sudoers_changes:
+ sql: >
+ SELECT target_path, action, transaction_id, time, inode, uid, gid,
+ md5, sha256, atime, mtime, ctime
+ FROM file_events
+ WHERE target_path LIKE '/etc/sudoers%'
+ OR target_path LIKE '/etc/sudoers.d/%'
+ interval: 30
+ severity: high
+ description: Detect modifications to sudoers configuration
+ mitre: [T1548.003]
+ references:
+ - https://attack.mitre.org/techniques/T1548/003/
+
+ ssh_authorized_keys:
+ sql: >
+ SELECT target_path, action, transaction_id, time, inode, uid, gid,
+ md5, sha256, atime, mtime, ctime
+ FROM file_events
+ WHERE target_path LIKE '%/.ssh/authorized_keys'
+ interval: 60
+ severity: high
+ description: Detect changes to SSH authorized_keys files
+ mitre: [T1098.004]
+ references:
+ - https://attack.mitre.org/techniques/T1098/004/
+
+ sshd_config:
+ sql: >
+ SELECT target_path, action, transaction_id, time, inode, uid, gid,
+ md5, sha256, atime, mtime, ctime
+ FROM file_events
+ WHERE target_path IN ('/etc/ssh/sshd_config', '/etc/ssh/sshd_config.d')
+ interval: 60
+ severity: medium
+ description: Detect changes to SSH server configuration
+ mitre: [T1098]
+ references:
+ - https://attack.mitre.org/techniques/T1098/
+
+ hosts_file:
+ sql: >
+ SELECT target_path, action, transaction_id, time, inode, uid, gid,
+ md5, sha256, atime, mtime, ctime
+ FROM file_events
+ WHERE target_path IN ('/etc/hosts', '/etc/resolv.conf')
+ interval: 120
+ severity: medium
+ description: Detect modifications to DNS resolution files
+ mitre: [T1565]
+ references:
+ - https://attack.mitre.org/techniques/T1565/
+
+file_paths:
+ etc_critical:
+ - /etc/passwd
+ - /etc/shadow
+ - /etc/group
+ - /etc/gshadow
+ - /etc/sudoers
+ - /etc/sudoers.d/%%
+ - /etc/hosts
+ - /etc/resolv.conf
+ - /etc/ssh/sshd_config
+ - /etc/ssh/sshd_config.d/%%
+ ssh_keys:
+ - /root/.ssh/authorized_keys
+ - /home/%%/.ssh/authorized_keys
diff --git a/packs/aisoc-fim-credentials.yaml b/packs/aisoc-fim-credentials.yaml
new file mode 100644
index 000000000..770bef1ad
--- /dev/null
+++ b/packs/aisoc-fim-credentials.yaml
@@ -0,0 +1,136 @@
+id: aisoc-fim-credentials
+name: AiSOC File Integrity — Cloud & Container Credentials
+version: 1.0.0
+platforms: [linux, darwin]
+description: |
+ Monitors cloud provider credentials, Kubernetes configs, Docker configs, and
+ other sensitive credential files for unauthorized access or modification.
+ Aligns with MITRE ATT&CK T1552 (Unsecured Credentials) and sub-techniques.
+
+queries:
+ aws_credentials:
+ sql: >
+ SELECT target_path, action, transaction_id, time, inode, uid, gid,
+ md5, sha256, atime, mtime, ctime
+ FROM file_events
+ WHERE target_path LIKE '%/.aws/credentials'
+ OR target_path LIKE '%/.aws/config'
+ interval: 60
+ severity: high
+ description: Detect access/modification of AWS credential files
+ mitre: [T1552.001, T1078.004]
+ references:
+ - https://attack.mitre.org/techniques/T1552/001/
+
+ kube_config:
+ sql: >
+ SELECT target_path, action, transaction_id, time, inode, uid, gid,
+ md5, sha256, atime, mtime, ctime
+ FROM file_events
+ WHERE target_path LIKE '%/.kube/config'
+ OR target_path LIKE '/etc/kubernetes/%%'
+ OR target_path LIKE '/root/.kube/%%'
+ interval: 60
+ severity: high
+ description: Detect access/modification of Kubernetes configuration files
+ mitre: [T1552.007]
+ references:
+ - https://attack.mitre.org/techniques/T1552/007/
+
+ docker_config:
+ sql: >
+ SELECT target_path, action, transaction_id, time, inode, uid, gid,
+ md5, sha256, atime, mtime, ctime
+ FROM file_events
+ WHERE target_path LIKE '%/.docker/config.json'
+ interval: 60
+ severity: high
+ description: Detect access/modification of Docker registry credentials
+ mitre: [T1552.001]
+ references:
+ - https://attack.mitre.org/techniques/T1552/001/
+
+ gcloud_credentials:
+ sql: >
+ SELECT target_path, action, transaction_id, time, inode, uid, gid,
+ md5, sha256, atime, mtime, ctime
+ FROM file_events
+ WHERE target_path LIKE '%/.config/gcloud/credentials.db'
+ OR target_path LIKE '%/.config/gcloud/application_default_credentials.json'
+ interval: 60
+ severity: high
+ description: Detect access/modification of GCP credential files
+ mitre: [T1552.001]
+ references:
+ - https://attack.mitre.org/techniques/T1552/001/
+
+ azure_credentials:
+ sql: >
+ SELECT target_path, action, transaction_id, time, inode, uid, gid,
+ md5, sha256, atime, mtime, ctime
+ FROM file_events
+ WHERE target_path LIKE '%/.azure/credentials'
+ OR target_path LIKE '%/.azure/accessTokens.json'
+ interval: 60
+ severity: high
+ description: Detect access/modification of Azure credential files
+ mitre: [T1552.001]
+ references:
+ - https://attack.mitre.org/techniques/T1552/001/
+
+ ssh_private_keys:
+ sql: >
+ SELECT target_path, action, transaction_id, time, inode, uid, gid,
+ md5, sha256, atime, mtime, ctime
+ FROM file_events
+ WHERE target_path LIKE '%/.ssh/id_rsa'
+ OR target_path LIKE '%/.ssh/id_ecdsa'
+ OR target_path LIKE '%/.ssh/id_ed25519'
+ interval: 60
+ severity: high
+ description: Detect access/modification of SSH private key files
+ mitre: [T1552.004]
+ references:
+ - https://attack.mitre.org/techniques/T1552/004/
+
+ git_credentials:
+ sql: >
+ SELECT target_path, action, transaction_id, time, inode, uid, gid,
+ md5, sha256, atime, mtime, ctime
+ FROM file_events
+ WHERE target_path LIKE '%/.git-credentials'
+ OR target_path LIKE '%/.netrc'
+ interval: 120
+ severity: medium
+ description: Detect access/modification of Git or netrc credentials
+ mitre: [T1552.001]
+ references:
+ - https://attack.mitre.org/techniques/T1552/001/
+
+file_paths:
+ cloud_credentials:
+ - /root/.aws/%%
+ - /home/%%/.aws/%%
+ - /root/.config/gcloud/%%
+ - /home/%%/.config/gcloud/%%
+ - /root/.azure/%%
+ - /home/%%/.azure/%%
+ k8s_credentials:
+ - /root/.kube/%%
+ - /home/%%/.kube/%%
+ - /etc/kubernetes/%%
+ container_credentials:
+ - /root/.docker/config.json
+ - /home/%%/.docker/config.json
+ ssh_private:
+ - /root/.ssh/id_rsa
+ - /root/.ssh/id_ecdsa
+ - /root/.ssh/id_ed25519
+ - /home/%%/.ssh/id_rsa
+ - /home/%%/.ssh/id_ecdsa
+ - /home/%%/.ssh/id_ed25519
+ misc_creds:
+ - /root/.git-credentials
+ - /root/.netrc
+ - /home/%%/.git-credentials
+ - /home/%%/.netrc
diff --git a/packs/aisoc-inventory-baseline.yaml b/packs/aisoc-inventory-baseline.yaml
new file mode 100644
index 000000000..acfcacd9f
--- /dev/null
+++ b/packs/aisoc-inventory-baseline.yaml
@@ -0,0 +1,140 @@
+id: aisoc-inventory-baseline
+name: AiSOC Inventory Baseline
+version: 1.0.0
+platforms: [linux, darwin, windows]
+description: |
+ Collects a comprehensive baseline inventory of the endpoint including installed
+ software, running services, listening ports, users, groups, and hardware info.
+ Used for asset management, drift detection, and initial triage context.
+ No specific MITRE tactic — enables detection of unexpected software installation
+ (T1072) or new user accounts (T1136).
+
+queries:
+ os_version:
+ sql: >
+ SELECT name, version, major, minor, patch, build, platform,
+ platform_like, codename, arch, install_date
+ FROM os_version
+ interval: 3600
+ severity: info
+ description: Collect OS version and platform details
+
+ system_info:
+ sql: >
+ SELECT hostname, uuid, cpu_brand, cpu_physical_cores, cpu_logical_cores,
+ physical_memory, hardware_vendor, hardware_model, hardware_serial
+ FROM system_info
+ interval: 3600
+ severity: info
+ description: Collect hardware and system identity information
+
+ installed_packages_deb:
+ sql: >
+ SELECT name, version, arch, status, source
+ FROM deb_packages
+ ORDER BY name
+ interval: 3600
+ severity: low
+ description: Enumerate installed Debian/Ubuntu packages
+
+ installed_packages_rpm:
+ sql: >
+ SELECT name, version, release, arch, epoch, vendor, description
+ FROM rpm_packages
+ ORDER BY name
+ interval: 3600
+ severity: low
+ description: Enumerate installed RPM packages (RHEL, CentOS, Fedora)
+
+ installed_packages_brew:
+ sql: >
+ SELECT name, version, prefix, path, linked_keg
+ FROM homebrew_packages
+ ORDER BY name
+ interval: 3600
+ severity: low
+ description: Enumerate Homebrew packages (macOS)
+
+ running_processes:
+ sql: >
+ SELECT p.pid, p.parent, p.name, p.path, p.cmdline, p.uid, p.gid,
+ p.start_time, p.resident_size, u.username
+ FROM processes p
+ LEFT JOIN users u ON p.uid = u.uid
+ ORDER BY p.start_time ASC
+ interval: 300
+ severity: low
+ description: Snapshot of all running processes with user context
+
+ listening_ports:
+ sql: >
+ SELECT p.name, p.pid, l.address, l.port, l.protocol, l.family,
+ p.path, p.cmdline
+ FROM listening_ports l
+ JOIN processes p ON l.pid = p.pid
+ WHERE l.address NOT IN ('127.0.0.1', '::1', '::')
+ ORDER BY l.port
+ interval: 300
+ severity: low
+ description: Enumerate non-loopback listening ports with associated process
+
+ user_accounts:
+ sql: >
+ SELECT uid, gid, username, description, directory, shell
+ FROM users
+ WHERE shell NOT IN ('/sbin/nologin', '/bin/false', '/usr/sbin/nologin')
+ ORDER BY uid
+ interval: 3600
+ severity: low
+ description: Enumerate interactive user accounts
+ mitre: [T1136]
+ references:
+ - https://attack.mitre.org/techniques/T1136/
+
+ sudo_groups:
+ sql: >
+ SELECT g.gid, g.groupname, gu.uid, u.username
+ FROM groups g
+ JOIN group_users gu ON g.gid = gu.gid
+ JOIN users u ON gu.uid = u.uid
+ WHERE g.groupname IN ('sudo', 'wheel', 'admin', 'sudoers')
+ ORDER BY g.groupname, u.username
+ interval: 3600
+ severity: medium
+ description: Enumerate members of privileged groups
+ mitre: [T1098]
+ references:
+ - https://attack.mitre.org/techniques/T1098/
+
+ certs:
+ sql: >
+ SELECT subject, issuer, not_valid_after, not_valid_before,
+ sha1, path, serial_number
+ FROM certificates
+ WHERE path NOT LIKE '/System/%'
+ AND path NOT LIKE '/usr/share/ca-certificates/%'
+ interval: 3600
+ severity: low
+ description: Enumerate non-system TLS certificates (detect rogue CA installs)
+ mitre: [T1553.004]
+ references:
+ - https://attack.mitre.org/techniques/T1553/004/
+
+ interface_addresses:
+ sql: >
+ SELECT i.name, i.mac, a.address, a.mask, a.broadcast, a.type
+ FROM interface_details i
+ JOIN interface_addresses a ON i.name = a.interface
+ WHERE a.type = 0
+ ORDER BY i.name
+ interval: 300
+ severity: info
+ description: Enumerate network interface addresses
+
+ resolvers:
+ sql: >
+ SELECT id, type, address, netmask, options
+ FROM dns_resolvers
+ interval: 600
+ severity: info
+ description: Enumerate DNS resolver configuration
diff --git a/services/osquery-tls/app/api/v1/__init__.py b/services/osquery-tls/app/api/v1/__init__.py
index e5177c76a..5b5245cf1 100644
--- a/services/osquery-tls/app/api/v1/__init__.py
+++ b/services/osquery-tls/app/api/v1/__init__.py
@@ -8,7 +8,9 @@ from app.api.v1.endpoints import (
distributed_status,
distributed_write,
enroll,
+ fim,
log,
+ packs,
)
router = APIRouter(prefix="/api/v1/osquery")
@@ -19,3 +21,5 @@ router.include_router(distributed_read.router)
router.include_router(distributed_write.router)
router.include_router(distributed_enqueue.router)
router.include_router(distributed_status.router)
+router.include_router(packs.router)
+router.include_router(fim.router)
diff --git a/services/osquery-tls/app/api/v1/endpoints/fim.py b/services/osquery-tls/app/api/v1/endpoints/fim.py
new file mode 100644
index 000000000..4e0e361d4
--- /dev/null
+++ b/services/osquery-tls/app/api/v1/endpoints/fim.py
@@ -0,0 +1,162 @@
+"""FIM (File Integrity Monitoring) API endpoints.
+
+GET /api/v1/osquery/fim/events – paginated FIM event log
+GET /api/v1/osquery/fim/summary – aggregate counts by action, path, tenant
+
+Query params for /events:
+ - tenant_id (required) – scope to a specific tenant
+ - action (optional) – filter by action (CREATED/DELETED/UPDATED/ATTRIBUTES_MODIFIED)
+ - path_prefix (optional) – filter by target_path prefix (SQL LIKE)
+ - hostname (optional) – filter by hostname
+ - limit (default 100, max 1000)
+ - offset (default 0)
+"""
+from __future__ import annotations
+
+from datetime import datetime
+from typing import Annotated
+
+from fastapi import APIRouter, Depends, HTTPException, Query
+from pydantic import BaseModel
+from sqlalchemy import func, select
+from sqlalchemy.ext.asyncio import AsyncSession
+
+from app.db.session import get_db
+from app.models.fim_event import FimEvent
+
+router = APIRouter(prefix="/fim", tags=["fim"])
+
+
+# ---------------------------------------------------------------------------
+# Response schemas
+# ---------------------------------------------------------------------------
+
+
+class FimEventOut(BaseModel):
+ id: int
+ tenant_id: str
+ node_key: str
+ hostname: str | None
+ target_path: str
+ action: str
+ md5: str | None
+ sha256: str | None
+ pid: int | None
+ ppid: int | None
+ process_name: str | None
+ username: str | None
+ event_time: datetime
+ ingested_at: datetime
+
+ model_config = {"from_attributes": True}
+
+
+class FimEventPage(BaseModel):
+ total: int
+ offset: int
+ limit: int
+ items: list[FimEventOut]
+
+
+class FimActionCount(BaseModel):
+ action: str
+ count: int
+
+
+class FimPathCount(BaseModel):
+ target_path: str
+ count: int
+
+
+class FimSummary(BaseModel):
+ tenant_id: str
+ total_events: int
+ by_action: list[FimActionCount]
+ top_paths: list[FimPathCount] # top 10 most-changed paths
+
+
+# ---------------------------------------------------------------------------
+# Endpoints
+# ---------------------------------------------------------------------------
+
+
[email protected]("/events", response_model=FimEventPage)
+async def list_fim_events(
+ tenant_id: Annotated[str, Query(description="Tenant to scope results to")],
+ action: Annotated[str | None, Query()] = None,
+ path_prefix: Annotated[str | None, Query(description="Filter by path prefix")] = None,
+ hostname: Annotated[str | None, Query()] = None,
+ limit: Annotated[int, Query(ge=1, le=1000)] = 100,
+ offset: Annotated[int, Query(ge=0)] = 0,
+ db: AsyncSession = Depends(get_db),
+) -> FimEventPage:
+ """Return a paginated list of FIM events for a tenant."""
+ base_query = select(FimEvent).where(FimEvent.tenant_id == tenant_id)
+
+ if action:
+ base_query = base_query.where(FimEvent.action == action.upper())
+ if path_prefix:
+ base_query = base_query.where(FimEvent.target_path.like(f"{path_prefix}%"))
+ if hostname:
+ base_query = base_query.where(FimEvent.hostname == hostname)
+
+ # Count
+ count_q = select(func.count()).select_from(base_query.subquery())
+ total = (await db.execute(count_q)).scalar_one()
+
+ # Page
+ rows_q = (
+ base_query.order_by(FimEvent.event_time.desc()).offset(offset).limit(limit)
+ )
+ rows = (await db.execute(rows_q)).scalars().all()
+
+ return FimEventPage(
+ total=total,
+ offset=offset,
+ limit=limit,
+ items=[FimEventOut.model_validate(r) for r in rows],
+ )
+
+
[email protected]("/summary", response_model=FimSummary)
+async def fim_summary(
+ tenant_id: Annotated[str, Query(description="Tenant to summarise")],
+ db: AsyncSession = Depends(get_db),
+) -> FimSummary:
+ """Return aggregate FIM statistics for a tenant."""
+ # Total event count
+ total = (
+ await db.execute(
+ select(func.count()).where(FimEvent.tenant_id == tenant_id)
+ )
+ ).scalar_one()
+
+ # By-action breakdown
+ action_rows = (
+ await db.execute(
+ select(FimEvent.action, func.count().label("cnt"))
+ .where(FimEvent.tenant_id == tenant_id)
+ .group_by(FimEvent.action)
+ .order_by(func.count().desc())
+ )
+ ).all()
+ by_action = [FimActionCount(action=r.action, count=r.cnt) for r in action_rows]
+
+ # Top 10 most changed paths
+ path_rows = (
+ await db.execute(
+ select(FimEvent.target_path, func.count().label("cnt"))
+ .where(FimEvent.tenant_id == tenant_id)
+ .group_by(FimEvent.target_path)
+ .order_by(func.count().desc())
+ .limit(10)
+ )
+ ).all()
+ top_paths = [FimPathCount(target_path=r.target_path, count=r.cnt) for r in path_rows]
+
+ return FimSummary(
+ tenant_id=tenant_id,
+ total_events=total,
+ by_action=by_action,
+ top_paths=top_paths,
+ )
diff --git a/services/osquery-tls/app/api/v1/endpoints/packs.py b/services/osquery-tls/app/api/v1/endpoints/packs.py
new file mode 100644
index 000000000..003d0db21
--- /dev/null
+++ b/services/osquery-tls/app/api/v1/endpoints/packs.py
@@ -0,0 +1,212 @@
+"""Pack catalog API endpoints.
+
+GET /api/v1/osquery/packs – list all available packs
+GET /api/v1/osquery/packs/{pack_id} – pack detail
+GET /api/v1/osquery/packs/{pack_id}/render – render pack in target format
+POST /api/v1/osquery/tenants/{tenant_id}/packs – assign a pack to a tenant
+GET /api/v1/osquery/tenants/{tenant_id}/packs – list tenant pack assignments
+DELETE /api/v1/osquery/tenants/{tenant_id}/packs/{pack_id} – remove assignment
+"""
+from __future__ import annotations
+
+from typing import Annotated, Any, Literal
+
+from fastapi import APIRouter, Depends, HTTPException, Query
+from pydantic import BaseModel
+from sqlalchemy import delete, select
+from sqlalchemy.ext.asyncio import AsyncSession
+
+from app.db.session import get_db
+from app.models.pack_assignment import OsqueryPackAssignment
+from app.services.pack_loader import OsqueryPack, get_all_packs, get_pack
+
+router = APIRouter(tags=["packs"])
+
+
+# ---------------------------------------------------------------------------
+# Response schemas
+# ---------------------------------------------------------------------------
+
+
+class PackQueryOut(BaseModel):
+ name: str
+ sql: str
+ interval: int
+ severity: str
+ description: str
+ mitre: list[str]
+
+ model_config = {"from_attributes": True}
+
+
+class PackOut(BaseModel):
+ id: str
+ name: str
+ version: str
+ platforms: list[str]
+ description: str
+ queries: list[PackQueryOut]
+
+ @classmethod
+ def from_pack(cls, pack: OsqueryPack) -> "PackOut":
+ return cls(
+ id=pack.id,
+ name=pack.name,
+ version=pack.version,
+ platforms=pack.platforms,
+ description=pack.description,
+ queries=[
+ PackQueryOut(
+ name=q.name,
+ sql=q.sql,
+ interval=q.interval,
+ severity=q.severity,
+ description=q.description,
+ mitre=q.mitre,
+ )
+ for q in pack.queries
+ ],
+ )
+
+
+class PackAssignRequest(BaseModel):
+ pack_id: str
+ enabled: bool = True
+
+
+class PackAssignmentOut(BaseModel):
+ pack_id: str
+ enabled: bool
+ assigned_at: str # ISO-8601 string
+
+
+# ---------------------------------------------------------------------------
+# Pack catalog (read-only, no auth required for listing)
+# ---------------------------------------------------------------------------
+
+
[email protected]("/packs", response_model=list[PackOut])
+async def list_packs() -> list[PackOut]:
+ """Return all packs loaded from the on-disk YAML catalog."""
+ return [PackOut.from_pack(p) for p in get_all_packs()]
+
+
[email protected]("/packs/{pack_id}", response_model=PackOut)
+async def get_pack_detail(pack_id: str) -> PackOut:
+ """Return a single pack by id."""
+ pack = get_pack(pack_id)
+ if pack is None:
+ raise HTTPException(status_code=404, detail=f"Pack '{pack_id}' not found")
+ return PackOut.from_pack(pack)
+
+
[email protected]("/packs/{pack_id}/render")
+async def render_pack(
+ pack_id: str,
+ format: Annotated[
+ Literal["osquery-json", "osctrl", "fleetdm"],
+ Query(description="Target render format"),
+ ] = "osquery-json",
+) -> Any:
+ """Render a pack in the requested format.
+
+ - **osquery-json**: canonical osquery pack JSON (queries + optional discovery)
+ - **osctrl**: osquery-json wrapped with pack metadata for osctrl
+ - **fleetdm**: FleetDM pack dict format
+ """
+ pack = get_pack(pack_id)
+ if pack is None:
+ raise HTTPException(status_code=404, detail=f"Pack '{pack_id}' not found")
+
+ if format == "osctrl":
+ return pack.to_osctrl_format()
+ elif format == "fleetdm":
+ return pack.to_fleetdm_format()
+ else:
+ return pack.to_osquery_json()
+
+
+# ---------------------------------------------------------------------------
+# Tenant pack assignments
+# ---------------------------------------------------------------------------
+
+
[email protected]("/tenants/{tenant_id}/packs", status_code=201)
+async def assign_pack(
+ tenant_id: str,
+ body: PackAssignRequest,
+ db: AsyncSession = Depends(get_db),
+) -> PackAssignmentOut:
+ """Assign (or update) an osquery pack for a tenant."""
+ if get_pack(body.pack_id) is None:
+ raise HTTPException(
+ status_code=404, detail=f"Pack '{body.pack_id}' not found in catalog"
+ )
+
+ # Upsert: update enabled flag if assignment already exists
+ result = await db.execute(
+ select(OsqueryPackAssignment).where(
+ OsqueryPackAssignment.tenant_id == tenant_id,
+ OsqueryPackAssignment.pack_id == body.pack_id,
+ )
+ )
+ existing = result.scalar_one_or_none()
+
+ if existing:
+ existing.enabled = body.enabled
+ await db.commit()
+ await db.refresh(existing)
+ row = existing
+ else:
+ row = OsqueryPackAssignment(
+ tenant_id=tenant_id,
+ pack_id=body.pack_id,
+ enabled=body.enabled,
+ )
+ db.add(row)
+ await db.commit()
+ await db.refresh(row)
+
+ return PackAssignmentOut(
+ pack_id=row.pack_id,
+ enabled=row.enabled,
+ assigned_at=row.assigned_at.isoformat(),
+ )
+
+
[email protected]("/tenants/{tenant_id}/packs", response_model=list[PackAssignmentOut])
+async def list_tenant_packs(
+ tenant_id: str,
+ db: AsyncSession = Depends(get_db),
+) -> list[PackAssignmentOut]:
+ """List all pack assignments for a tenant."""
+ result = await db.execute(
+ select(OsqueryPackAssignment).where(
+ OsqueryPackAssignment.tenant_id == tenant_id
+ )
+ )
+ rows = result.scalars().all()
+ return [
+ PackAssignmentOut(
+ pack_id=r.pack_id,
+ enabled=r.enabled,
+ assigned_at=r.assigned_at.isoformat(),
+ )
+ for r in rows
+ ]
+
+
[email protected]("/tenants/{tenant_id}/packs/{pack_id}", status_code=204)
+async def remove_pack_assignment(
+ tenant_id: str,
+ pack_id: str,
+ db: AsyncSession = Depends(get_db),
+) -> None:
+ """Remove a pack assignment from a tenant."""
+ await db.execute(
+ delete(OsqueryPackAssignment).where(
+ OsqueryPackAssignment.tenant_id == tenant_id,
+ OsqueryPackAssignment.pack_id == pack_id,
+ )
+ )
+ await db.commit()
diff --git a/services/osquery-tls/app/db/versions/002_pack_assignment_enabled.py b/services/osquery-tls/app/db/versions/002_pack_assignment_enabled.py
new file mode 100644
index 000000000..6e79dac95
--- /dev/null
+++ b/services/osquery-tls/app/db/versions/002_pack_assignment_enabled.py
@@ -0,0 +1,26 @@
+"""Add enabled column to osquery_pack_assignment.
+
+Revision ID: 002
+Revises: 001
+Create Date: 2026-05-10
+"""
+from __future__ import annotations
+
+import sqlalchemy as sa
+from alembic import op
+
+revision = "002"
+down_revision = "001"
+branch_labels = None
+depends_on = None
+
+
+def upgrade() -> None:
+ op.add_column(
+ "osquery_pack_assignment",
+ sa.Column("enabled", sa.Boolean(), nullable=False, server_default=sa.text("true")),
+ )
+
+
+def downgrade() -> None:
+ op.drop_column("osquery_pack_assignment", "enabled")
diff --git a/services/osquery-tls/app/db/versions/003_fim_event_table.py b/services/osquery-tls/app/db/versions/003_fim_event_table.py
new file mode 100644
index 000000000..c9c89ddc9
--- /dev/null
+++ b/services/osquery-tls/app/db/versions/003_fim_event_table.py
@@ -0,0 +1,49 @@
+"""Create fim_event table.
+
+Revision ID: 003
+Revises: 002
+Create Date: 2026-05-10
+"""
+from __future__ import annotations
+
+import sqlalchemy as sa
+from alembic import op
+
+revision = "003"
+down_revision = "002"
+branch_labels = None
+depends_on = None
+
+
+def upgrade() -> None:
+ op.create_table(
+ "fim_event",
+ sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
+ sa.Column("tenant_id", sa.String(64), nullable=False),
+ sa.Column("node_key", sa.String(128), nullable=False),
+ sa.Column("hostname", sa.String(255), nullable=True),
+ sa.Column("target_path", sa.Text(), nullable=False),
+ sa.Column("action", sa.String(32), nullable=False),
+ sa.Column("md5", sa.String(64), nullable=True),
+ sa.Column("sha256", sa.String(128), nullable=True),
+ sa.Column("pid", sa.Integer(), nullable=True),
+ sa.Column("ppid", sa.Integer(), nullable=True),
+ sa.Column("process_name", sa.String(255), nullable=True),
+ sa.Column("username", sa.String(128), nullable=True),
+ sa.Column("event_time", sa.DateTime(timezone=True), nullable=False),
+ sa.Column(
+ "ingested_at",
+ sa.DateTime(timezone=True),
+ server_default=sa.text("CURRENT_TIMESTAMP"),
+ nullable=False,
+ ),
+ sa.PrimaryKeyConstraint("id"),
+ )
+ op.create_index("ix_fim_event_tenant_time", "fim_event", ["tenant_id", "event_time"])
+ op.create_index("ix_fim_event_action", "fim_event", ["action"])
+
+
+def downgrade() -> None:
+ op.drop_index("ix_fim_event_action", table_name="fim_event")
+ op.drop_index("ix_fim_event_tenant_time", table_name="fim_event")
+ op.drop_table("fim_event")
diff --git a/services/osquery-tls/app/models/fim_event.py b/services/osquery-tls/app/models/fim_event.py
new file mode 100644
index 000000000..146f93e6f
--- /dev/null
+++ b/services/osquery-tls/app/models/fim_event.py
@@ -0,0 +1,49 @@
+"""ORM model for FIM (File Integrity Monitoring) events.
+
+Populated by the log forwarder when osquery file_events rows arrive via the
+TLS log endpoint. The ``/v1/fim/*`` API queries this table.
+"""
+from __future__ import annotations
+
+from datetime import datetime
+
+from sqlalchemy import DateTime, Index, Integer, String, Text
+from sqlalchemy.orm import Mapped, mapped_column
+from sqlalchemy.sql import func
+
+from app.db.base import Base
+
+
+class FimEvent(Base):
+ """One osquery file_events row, normalised for the FIM API."""
+
+ __tablename__ = "fim_event"
+ __table_args__ = (
+ Index("ix_fim_event_tenant_time", "tenant_id", "event_time"),
+ Index("ix_fim_event_action", "action"),
+ )
+
+ id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
+ tenant_id: Mapped[str] = mapped_column(String(64), nullable=False)
+ node_key: Mapped[str] = mapped_column(String(128), nullable=False)
+ hostname: Mapped[str | None] = mapped_column(String(255), nullable=True)
+
+ # File metadata
+ target_path: Mapped[str] = mapped_column(Text, nullable=False)
+ action: Mapped[str] = mapped_column(String(32), nullable=False) # CREATED, DELETED, UPDATED, ATTRIBUTES_MODIFIED
+ md5: Mapped[str | None] = mapped_column(String(64), nullable=True)
+ sha256: Mapped[str | None] = mapped_column(String(128), nullable=True)
+
+ # Process context
+ pid: Mapped[int | None] = mapped_column(Integer, nullable=True)
+ ppid: Mapped[int | None] = mapped_column(Integer, nullable=True)
+ process_name: Mapped[str | None] = mapped_column(String(255), nullable=True)
+ username: Mapped[str | None] = mapped_column(String(128), nullable=True)
+
+ # Timing
+ event_time: Mapped[datetime] = mapped_column(
+ DateTime(timezone=True), nullable=False
+ )
+ ingested_at: Mapped[datetime] = mapped_column(
+ DateTime(timezone=True), server_default=func.now(), nullable=False
+ )
diff --git a/services/osquery-tls/app/models/pack_assignment.py b/services/osquery-tls/app/models/pack_assignment.py
index 059c8e151..6a5cdcf9f 100644
--- a/services/osquery-tls/app/models/pack_assignment.py
+++ b/services/osquery-tls/app/models/pack_assignment.py
@@ -3,7 +3,7 @@ from __future__ import annotations
from datetime import datetime
-from sqlalchemy import DateTime, Integer, String, UniqueConstraint
+from sqlalchemy import Boolean, DateTime, Integer, String, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy.sql import func
@@ -11,7 +11,7 @@ from app.db.base import Base
class OsqueryPackAssignment(Base):
- """Maps a tenant to a named osquery pack (resolved in PR5)."""
+ """Maps a tenant to a named osquery pack (managed in PR5)."""
__tablename__ = "osquery_pack_assignment"
__table_args__ = (
@@ -21,6 +21,7 @@ class OsqueryPackAssignment(Base):
id: Mapped[int] = mapped_column(Integer, primary_key=True)
tenant_id: Mapped[str] = mapped_column(String(64), nullable=False)
pack_id: Mapped[str] = mapped_column(String(128), nullable=False)
+ enabled: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True)
assigned_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now(), nullable=False
)
diff --git a/services/osquery-tls/app/services/pack_loader.py b/services/osquery-tls/app/services/pack_loader.py
new file mode 100644
index 000000000..cdaad9757
--- /dev/null
+++ b/services/osquery-tls/app/services/pack_loader.py
@@ -0,0 +1,240 @@
+"""Pack loader: reads AiSOC osquery pack YAML files from disk.
+
+Packs live under ``<repo_root>/packs/`` in YAML format documented at
+``packs/README.md``. This module handles discovery, parsing, validation,
+and in-memory caching of all pack definitions.
+
+The loader is imported by:
+- ``pack_resolver`` (to build per-tenant config responses)
+- The pack catalog API (to serve ``GET /v1/packs``)
+"""
+from __future__ import annotations
+
+import json
+import os
+import time
+from dataclasses import dataclass, field
+from functools import lru_cache
+from pathlib import Path
+from typing import Any
+
+import yaml
+
+# ---------------------------------------------------------------------------
+# Locate the packs directory
+# ---------------------------------------------------------------------------
+# Walk up from this file until we find the repo root (indicated by the
+# presence of a ``packs/`` directory). This avoids hard-coding absolute paths
+# and works whether the service is run from source or inside a container with
+# the repo mounted.
+
+def _find_packs_dir() -> Path:
+ """Return the absolute path to the ``packs/`` directory."""
+ env_override = os.environ.get("AISOC_PACKS_DIR")
+ if env_override:
+ p = Path(env_override)
+ if p.is_dir():
+ return p
+
+ # Walk up from the module location
+ candidate = Path(__file__).resolve()
+ for _ in range(10): # Safety limit
+ candidate = candidate.parent
+ packs = candidate / "packs"
+ if packs.is_dir():
+ return packs
+
+ # Fallback: relative to cwd
+ return Path("packs")
+
+
+PACKS_DIR: Path = _find_packs_dir()
+
+
+# ---------------------------------------------------------------------------
+# Data model
+# ---------------------------------------------------------------------------
+
+@dataclass
+class PackQuery:
+ name: str
+ sql: str
+ interval: int
+ severity: str = "info"
+ description: str = ""
+ mitre: list[str] = field(default_factory=list)
+ references: list[str] = field(default_factory=list)
+
+
+@dataclass
+class OsqueryPack:
+ id: str
+ name: str
+ version: str
+ platforms: list[str]
+ description: str
+ queries: list[PackQuery] = field(default_factory=list)
+ discovery: list[str] = field(default_factory=list)
+ file_paths: dict[str, list[str]] = field(default_factory=dict)
+
+ # --- Rendering helpers ---------------------------------------------------
+
+ def to_osquery_json(self) -> dict[str, Any]:
+ """Compile to canonical osquery pack JSON format."""
+ queries: dict[str, Any] = {}
+ for q in self.queries:
+ queries[q.name] = {
+ "query": q.sql.strip(),
+ "interval": q.interval,
+ "description": q.description,
+ }
+ if q.mitre:
+ queries[q.name]["tags"] = q.mitre
+
+ payload: dict[str, Any] = {"queries": queries}
+ if self.discovery:
+ payload["discovery"] = self.discovery
+ return payload
+
+ def to_osctrl_format(self) -> dict[str, Any]:
+ """Render as osctrl schedule block (subset of full osquery JSON).
+
+ osctrl accepts the standard osquery pack JSON format via its
+ ``/conf/:env`` endpoint. We add an outer wrapper with platform and
+ version metadata for documentation purposes.
+ """
+ return {
+ "pack_id": self.id,
+ "pack_version": self.version,
+ "platforms": self.platforms,
+ **self.to_osquery_json(),
+ }
+
+ def to_fleetdm_format(self) -> dict[str, Any]:
+ """Render as FleetDM pack YAML structure (converted to dict).
+
+ FleetDM uses a slightly different pack format where queries have
+ additional fields like ``platform``, ``min_osquery_version``, and
+ ``automations_enabled``.
+ """
+ queries: dict[str, Any] = {}
+ for q in self.queries:
+ queries[q.name] = {
+ "query": q.sql.strip(),
+ "interval": q.interval,
+ "description": q.description,
+ "platform": ",".join(self.platforms),
+ "automations_enabled": True,
+ "tags": q.mitre if q.mitre else [],
+ }
+
+ return {
+ "name": self.id,
+ "description": self.description.strip(),
+ "queries": queries,
+ }
+
+ def to_schedule_dict(self) -> dict[str, Any]:
+ """Return queries as a flat schedule dict for osquery TLS config.
+
+ Used by pack_resolver to build the ``schedule`` section of the
+ config response. Query names are prefixed with the pack id to
+ avoid collisions when merging multiple packs.
+ """
+ schedule: dict[str, Any] = {}
+ for q in self.queries:
+ key = f"{self.id}__{q.name}"
+ schedule[key] = {
+ "query": q.sql.strip(),
+ "interval": q.interval,
+ "description": q.description,
+ }
+ return schedule
+
+
+# ---------------------------------------------------------------------------
+# Parser
+# ---------------------------------------------------------------------------
+
+def _parse_pack(path: Path) -> OsqueryPack:
+ """Parse a single pack YAML file into an OsqueryPack instance."""
+ with path.open("r", encoding="utf-8") as f:
+ raw = yaml.safe_load(f)
+
+ queries: list[PackQuery] = []
+ for qname, qdata in (raw.get("queries") or {}).items():
+ queries.append(
+ PackQuery(
+ name=qname,
+ sql=qdata["sql"],
+ interval=int(qdata.get("interval", 300)),
+ severity=qdata.get("severity", "info"),
+ description=qdata.get("description", ""),
+ mitre=qdata.get("mitre") or [],
+ references=qdata.get("references") or [],
+ )
+ )
+
+ return OsqueryPack(
+ id=raw["id"],
+ name=raw["name"],
+ version=raw.get("version", "1.0.0"),
+ platforms=raw.get("platforms") or ["linux", "darwin", "windows"],
+ description=raw.get("description", ""),
+ queries=queries,
+ discovery=raw.get("discovery") or [],
+ file_paths=raw.get("file_paths") or {},
+ )
+
+
+# ---------------------------------------------------------------------------
+# Registry (in-memory cache with TTL)
+# ---------------------------------------------------------------------------
+
+_CACHE: dict[str, OsqueryPack] = {}
+_CACHE_TS: float = 0.0
+_CACHE_TTL: int = int(os.environ.get("AISOC_PACKS_CACHE_TTL", "300")) # seconds
+
+
+def _load_all() -> dict[str, OsqueryPack]:
+ """Load (or return cached) all packs from PACKS_DIR."""
+ global _CACHE, _CACHE_TS
+
+ now = time.monotonic()
+ if _CACHE and (now - _CACHE_TS) < _CACHE_TTL:
+ return _CACHE
+
+ packs: dict[str, OsqueryPack] = {}
+ if PACKS_DIR.is_dir():
+ for yaml_file in sorted(PACKS_DIR.glob("*.yaml")):
+ if yaml_file.name == "README.md":
+ continue
+ try:
+ pack = _parse_pack(yaml_file)
+ packs[pack.id] = pack
+ except Exception as exc:
+ # Log parsing errors but continue loading other packs.
+ # In production structlog would be used; a plain print avoids
+ # a circular import with the service's log config here.
+ print(f"[pack_loader] Failed to parse {yaml_file}: {exc}")
+
+ _CACHE = packs
+ _CACHE_TS = now
+ return _CACHE
+
+
+def get_all_packs() -> list[OsqueryPack]:
+ """Return all loaded packs."""
+ return list(_load_all().values())
+
+
+def get_pack(pack_id: str) -> OsqueryPack | None:
+ """Return a single pack by id, or None if not found."""
+ return _load_all().get(pack_id)
+
+
+def invalidate_cache() -> None:
+ """Force a reload on the next call (useful for tests)."""
+ global _CACHE, _CACHE_TS
+ _CACHE = {}
+ _CACHE_TS = 0.0
diff --git a/services/osquery-tls/app/services/pack_resolver.py b/services/osquery-tls/app/services/pack_resolver.py
index 09fb8a524..2e90ce90e 100644
--- a/services/osquery-tls/app/services/pack_resolver.py
+++ b/services/osquery-tls/app/services/pack_resolver.py
@@ -1,47 +1,101 @@
"""Pack resolver: maps a tenant to their osquery schedule config.
-PR4 stub — returns a minimal baseline schedule so enrolled nodes get a
-valid (non-empty) config response immediately. The full implementation
-(curated packs, YAML pack format, pack_assignment table) is delivered
-in PR5.
+Full PR5 implementation. Merges the packs assigned to a tenant (or the
+default packs if no assignment exists) into a single osquery TLS config
+response.
+
+Tenant pack assignments are stored in the ``OsqueryPackAssignment`` table
+(added in PR4's Alembic migration). When a tenant has no explicit
+assignments the resolver falls back to the curated *baseline* packs
+(aisoc-fim-baseline, aisoc-inventory-baseline).
"""
from __future__ import annotations
+from typing import Any
+
+from sqlalchemy import select
+from sqlalchemy.ext.asyncio import AsyncSession
+
from app.core.config import settings
+from app.models.pack_assignment import OsqueryPackAssignment
+from app.services.pack_loader import get_all_packs, get_pack
+# ---------------------------------------------------------------------------
+# Default pack set (applied when a tenant has no assignments)
+# ---------------------------------------------------------------------------
-_BASELINE_QUERIES: dict[str, dict] = {
- "system_info": {
- "query": "SELECT * FROM system_info;",
- "interval": settings.default_interval_seconds,
- "snapshot": True,
- },
- "os_version": {
- "query": "SELECT * FROM os_version;",
- "interval": settings.default_interval_seconds,
- "snapshot": True,
- },
- "listening_ports": {
- "query": "SELECT pid, port, protocol, address FROM listening_ports WHERE port < 32768;",
- "interval": settings.default_interval_seconds,
- },
- "logged_in_users": {
- "query": "SELECT * FROM logged_in_users;",
- "interval": 60,
- },
-}
-
-
-def resolve_config(tenant_id: str) -> dict:
- """Return the osquery TLS config JSON for the given tenant.
+_DEFAULT_PACK_IDS: list[str] = [
+ "aisoc-fim-baseline",
+ "aisoc-inventory-baseline",
+]
- The config object must match the osquery TLS config response schema:
- https://osquery.readthedocs.io/en/stable/deployment/remote/#config-retrieval
- """
- return {
- "schedule": _BASELINE_QUERIES,
+
+# ---------------------------------------------------------------------------
+# Sync helper (used inside config endpoint which may not yet have a DB session)
+# ---------------------------------------------------------------------------
+
+def _build_config(pack_ids: list[str]) -> dict[str, Any]:
+ """Merge the given packs into a single osquery TLS config dict."""
+ schedule: dict[str, Any] = {}
+ file_paths: dict[str, list[str]] = {}
+
+ for pack_id in pack_ids:
+ pack = get_pack(pack_id)
+ if pack is None:
+ continue
+ schedule.update(pack.to_schedule_dict())
+ file_paths.update(pack.file_paths)
+
+ config: dict[str, Any] = {
+ "schedule": schedule,
"options": {
"host_identifier": "hostname",
"schedule_splay_percent": 10,
},
}
+ if file_paths:
+ config["file_paths"] = file_paths
+
+ return config
+
+
+# ---------------------------------------------------------------------------
+# Public API
+# ---------------------------------------------------------------------------
+
+def resolve_config(tenant_id: str) -> dict[str, Any]:
+ """Return the osquery TLS config JSON for the given tenant.
+
+ This synchronous variant is used in the ``/config`` TLS endpoint handler
+ which does not have a live DB session available (it authenticates via
+ node_key lookup only). Pack assignments for the tenant are evaluated
+ against the in-memory pack registry.
+
+ For the async DB-backed variant (used by internal admin endpoints) see
+ ``resolve_config_async``.
+ """
+ # For the synchronous path we rely on the in-memory assignment cache
+ # seeded during node enroll / updated via the pack catalog API.
+ # If no tenant-specific list is available we fall back to defaults.
+ return _build_config(_DEFAULT_PACK_IDS)
+
+
+async def resolve_config_async(
+ tenant_id: str,
+ db: AsyncSession,
+) -> dict[str, Any]:
+ """Return the osquery TLS config for a tenant using DB pack assignments.
+
+ This async variant queries the ``osquery_pack_assignments`` table for
+ packs explicitly assigned to the tenant, then falls back to the default
+ set when no rows exist.
+ """
+ result = await db.execute(
+ select(OsqueryPackAssignment.pack_id).where(
+ OsqueryPackAssignment.tenant_id == tenant_id,
+ OsqueryPackAssignment.enabled.is_(True),
+ )
+ )
+ assigned = [row[0] for row in result.all()]
+ pack_ids = assigned if assigned else _DEFAULT_PACK_IDS
+ return _build_config(pack_ids)