repositories

daemon-sec-lotl

DÆMONBins: GTFOBins × LOLBAS × WADComs × LOOBins in one filterable catalog

clonegit clone https://git.daemon-sec.xyz/daemon-sec-lotl.git
technique-schema.mjsJavaScript85 lines3.5 KiBraw download
/**
 * The unified Technique vocabulary + Zod schema — the single source of truth
 * shared by the dataset builder (build-dataset.mjs), the standalone validator
 * (validate-data.mjs, run in CI over the committed JSON) and the one-shot
 * migrations. Keep it dependency-free beyond zod so it loads anywhere.
 *
 * Mirrors src/lib/taxonomy.ts; the TS side is the UI vocabulary, this is the
 * data contract. They must agree — validate-data.mjs cross-checks them.
 */
import { z } from 'zod';

export const PLATFORMS = ['Linux', 'Windows', 'macOS', 'ActiveDirectory'];
export const SOURCES = ['GTFOBins', 'LOLBAS', 'WADComs', 'LOOBins', 'DAEMON'];
export const CAPABILITIES = [
  'Execution', 'Reverse/Bind Shell',
  'File Download', 'File Upload', 'File Read', 'File Write', 'File Copy',
  'Library Load', 'Compile',
  'Privilege Escalation', 'UAC Bypass', 'AWL / Policy Bypass',
  'Defense Evasion', 'Credential Access',
  'Discovery', 'Enumeration', 'Persistence', 'Lateral Movement', 'Collection',
];

// Only absolute http(s) URLs may become <a href> — a stray `javascript:` or
// relative reference from an upstream merge must fail validation, not render.
const HTTP_URL = /^https?:\/\/\S+$/;
export const HttpUrl = z.string().regex(HTTP_URL, 'must be an absolute http(s) URL');

export const TechniqueSchema = z.object({
  id: z.string().min(1),
  toolId: z.string().min(1),
  toolName: z.string().min(1),
  name: z.string().optional(),
  source: z.enum(SOURCES),
  platform: z.array(z.enum(PLATFORMS)).min(1),
  capability: z.array(z.enum(CAPABILITIES)),
  nativeCategory: z.array(z.string()),
  command: z.string().min(1),
  description: z.string().optional(),
  usecase: z.string().optional(),
  mitre: z.array(z.string().regex(/^T\d{4}(\.\d{3})?$/, 'must be a MITRE ATT&CK technique id')),
  privilege: z.string().optional(),
  context: z.string().optional(),
  requires: z.array(z.string()).optional(),
  services: z.array(z.string()).optional(),
  fullPath: z.array(z.string()).optional(),
  toolType: z.string().optional(),
  detection: z.array(z.object({ type: z.string(), value: z.string() })).optional(),
  references: z.array(HttpUrl),
  added: z.boolean().optional(),
  verifyNote: z.string().optional(),
  environment: z.array(z.string()).optional(),
  aliases: z.array(z.string()).optional(),
  availability: z.string().optional(),
  verification: z.enum(['Upstream reference', 'Documentation checked', 'Lab tested']).optional(),
  reviewedAt: z.string().optional(),
  compatibility: z.string().optional(),
  expected: z.string().optional(),
  troubleshooting: z.string().optional(),
  sideEffects: z.string().optional(),
  restore: z.string().optional(),
  template: z.object({
    command: z.string(), shell: z.enum(['posix', 'powershell']),
    variables: z.array(z.object({ key: z.string().regex(/^[a-z][a-z0-9_]*$/), label: z.string(), default: z.string() })),
  }).optional(),
});

/**
 * Validate a whole Technique[]: schema per record + unique ids. Returns a list
 * of human-readable problems (empty = valid). Pure; callers decide how to fail.
 */
export function validateTechniques(techniques) {
  const problems = [];
  const ids = new Set();
  for (const t of techniques) {
    const r = TechniqueSchema.safeParse(t);
    if (!r.success) {
      const why = r.error.issues.map((i) => `${i.path.join('.')} ${i.message}`).join('; ');
      problems.push(`invalid ${t && t.id ? t.id : '<no id>'}: ${why}`);
      continue;
    }
    if (ids.has(t.id)) problems.push(`duplicate id ${t.id}`);
    ids.add(t.id);
  }
  return problems;
}