/** * DÆMONBins dataset builder. * * Reads the three vendored upstreams under vendor/ plus the daemon-sec WADComs * additions (and, if present, the DÆMON modernization backlog), normalizes * every source to one filterable atom — a Technique — and emits: * * src/data/techniques.json full canonical array (committed; Astro imports it) * src/data/tools.json per-tool metadata (aliases, Full_Path, contributors) * src/data/facets.json derived facet indexes + counts * public/data/techniques.json copy served statically for the catalog island fetch * * Run locally with `npm run data`. CI never runs this — it builds Astro + * Pagefind over the committed JSON. Deterministic: IDs derive from * source + tool + index, no wall-clock. * * All three upstreams are GPL-3.0, so the merged dataset is GPL-3.0. */ import { readFileSync, writeFileSync, readdirSync, existsSync, mkdirSync, statSync } from 'node:fs'; import { fileURLToPath } from 'node:url'; import { dirname, join, resolve } from 'node:path'; import yaml from 'js-yaml'; import { enrich, stableId } from './enrich-data.mjs'; import { impacketScript, canonicalizeFamilyCase } from './wadcoms-normalize.mjs'; import { PLATFORMS, SOURCES, CAPABILITIES, validateTechniques } from './technique-schema.mjs'; const __dirname = dirname(fileURLToPath(import.meta.url)); const ROOT = resolve(__dirname, '..'); const VENDOR = join(ROOT, 'vendor'); const OUT_SRC = join(ROOT, 'src', 'data'); const OUT_PUB = join(ROOT, 'public', 'data'); // Source of truth for the 134 daemon-authored WADComs additions. const WADCOMS_JSON = join(OUT_SRC, 'sources', 'wadcoms-additions.json'); // Optional: the §7 modernization backlog, emitted by the daemonbins-backlog workflow. const BACKLOG_JSON = join(OUT_SRC, 'daemon-backlog.json'); // --------------------------------------------------------------------------- // Unified vocabulary // --------------------------------------------------------------------------- // PLATFORMS / SOURCES / CAPABILITIES + TechniqueSchema live in technique-schema.mjs // (shared with validate-data.mjs and the one-shot migrations). // GTFOBins function → capability (BUILD-PROMPT §5) const GTFO_FN_CAP = { shell: ['Execution'], command: ['Execution'], 'reverse-shell': ['Reverse/Bind Shell'], 'bind-shell': ['Reverse/Bind Shell'], 'file-write': ['File Write'], 'file-read': ['File Read'], upload: ['File Upload'], download: ['File Download'], 'library-load': ['Library Load'], 'privilege-escalation': ['Privilege Escalation'], }; // GTFOBins function → MITRE fallback (from _data/functions.yml) const GTFO_FN_MITRE = { shell: ['T1059'], command: ['T1059'], 'reverse-shell': ['T1059', 'T1071'], 'bind-shell': ['T1059', 'T1071'], 'file-write': ['T1565'], 'file-read': ['T1005'], upload: ['T1041'], download: ['T1105'], 'library-load': ['T1574'], 'privilege-escalation': ['T1548'], }; // LOLBAS Category → capability (BUILD-PROMPT §5) const LOLBAS_CAT_CAP = { Execute: ['Execution'], 'AWL Bypass': ['AWL / Policy Bypass'], Download: ['File Download'], Upload: ['File Upload'], Copy: ['File Copy'], Encode: ['Defense Evasion'], Decode: ['Defense Evasion'], ADS: ['Defense Evasion', 'File Write'], Conceal: ['Defense Evasion'], Tamper: ['Defense Evasion'], Compile: ['Compile'], Credentials: ['Credential Access'], Dump: ['Credential Access'], Reconnaissance: ['Discovery'], 'UAC Bypass': ['UAC Bypass', 'Privilege Escalation'], }; // WADComs attack_type → capability (BUILD-PROMPT §5). Kept forgiving: unknown // values simply don't add a capability, but are always kept in nativeCategory. const WAD_ATTACK_CAP = { Enumeration: ['Enumeration'], Discovery: ['Discovery'], Exploitation: ['Execution'], PrivEsc: ['Privilege Escalation'], 'Privilege Escalation': ['Privilege Escalation'], Persistence: ['Persistence'], 'Credential Access': ['Credential Access'], 'Lateral Movement': ['Lateral Movement'], 'Defense Evasion': ['Defense Evasion'], Collection: ['Collection'], }; // Services / items that flag Active Directory scope (BUILD-PROMPT §5). const AD_SERVICES = new Set(['SMB', 'LDAP', 'Kerberos', 'RPC', 'WMI', 'DCOM', 'NTLM', 'DNS', 'WinRM', 'MSSQL', 'ADCS']); const AD_ITEMS = new Set(['TGS', 'TGT', 'PFX', 'AES_Key']); // GTFOBins binaries that are also standard on macOS (the classic POSIX/BSD // userland). Tagged Linux+macOS; everything else stays Linux-only rather than // risk a false macOS claim. const GTFO_MACOS = new Set([ 'awk', 'base64', 'basename', 'bash', 'bridge', 'busybox', 'cat', 'chmod', 'chown', 'cp', 'csh', 'cut', 'date', 'dd', 'df', 'diff', 'dig', 'dmesg', 'du', 'ed', 'env', 'expand', 'expect', 'file', 'find', 'flock', 'fmt', 'fold', 'ftp', 'gawk', 'gcc', 'gdb', 'gem', 'genie', 'git', 'grep', 'gzip', 'head', 'hexdump', 'iconv', 'irb', 'jjs', 'join', 'jq', 'ksh', 'ld.so', 'less', 'ln', 'logsave', 'look', 'lua', 'mail', 'make', 'man', 'more', 'mv', 'nano', 'nawk', 'nc', 'nice', 'nl', 'nmap', 'node', 'nohup', 'od', 'openssl', 'perl', 'pexec', 'php', 'pico', 'pip', 'python', 'python2', 'python3', 'rake', 'readelf', 'ruby', 'run-parts', 'rvim', 'scp', 'screen', 'script', 'sed', 'setarch', 'sftp', 'sh', 'smbclient', 'socat', 'sort', 'sqlite3', 'ss', 'ssh', 'stdbuf', 'strace', 'systemctl', 'tac', 'tail', 'tar', 'taskset', 'tbl', 'tclsh', 'tcpdump', 'tee', 'telnet', 'tftp', 'time', 'timeout', 'tmux', 'top', 'ul', 'unexpand', 'uniq', 'unshare', 'unzip', 'vi', 'vim', 'watch', 'wc', 'wget', 'xargs', 'xxd', 'zip', 'zsh', 'zypper', ]); // --------------------------------------------------------------------------- // Helpers // --------------------------------------------------------------------------- const uniq = (a) => [...new Set(a.filter((x) => x != null && x !== ''))]; const asArray = (x) => (Array.isArray(x) ? x : x == null ? [] : [x]); function listFiles(dir) { if (!existsSync(dir)) return []; return readdirSync(dir).filter((f) => { try { return statSync(join(dir, f)).isFile(); } catch { return false; } }); } function parseGtfoFile(content) { // Whole-file Jekyll front matter: strip leading `---` and trailing `...`. const body = content.replace(/^---\r?\n/, '').replace(/\r?\n?\.\.\.\s*$/, ''); return yaml.load(body) || {}; } function parseFrontMatter(content) { // Tolerate a leading BOM / blank lines before the `---` (some upstream // WADComs files, e.g. Rubeus-s4u.md, open with a blank line). const s = content.replace(/^/, '').replace(/^\s+/, ''); const m = /^---\r?\n([\s\S]*?)\r?\n---/.exec(s); if (!m) return {}; return yaml.load(m[1]) || {}; } function parseMitreFromRefs(refs) { const out = []; for (const r of asArray(refs)) { const re = /attack\.mitre\.org\/techniques\/(T\d{4})(?:\/(\d{3}))?/gi; let m; while ((m = re.exec(String(r))) !== null) out.push(m[2] ? `${m[1]}.${m[2]}` : m[1]); } return uniq(out); } function normPrivilege(raw) { const s = String(raw || '').toLowerCase(); if (!s) return undefined; if (/(system|nt authority|trustedinstaller)/.test(s)) return 'system'; if (/(admin|elevated|high integrity|local administrator)/.test(s)) return 'admin'; return 'user'; } const lolbasUrlType = { OSBinaries: 'Binaries', OSLibraries: 'Libraries', OSScripts: 'Scripts', OtherMSBinaries: 'OtherMSBinaries' }; const lolbasType = { OSBinaries: 'Binary', OSLibraries: 'Library', OSScripts: 'Script', OtherMSBinaries: 'OtherMSBinary' }; // --------------------------------------------------------------------------- // GTFOBins // --------------------------------------------------------------------------- function ingestGtfobins() { const dir = join(VENDOR, 'gtfobins', '_gtfobins'); const files = listFiles(dir); const techniques = []; const tools = new Map(); const aliasEdges = []; // {from: aliasFile, to: canonical} // Pass 1 — parse every file into a map. const parsed = new Map(); for (const bin of files) { const data = parseGtfoFile(readFileSync(join(dir, bin), 'utf8')); parsed.set(bin, data); } // Resolve the function set a binary exposes (for inherit capability union). const funcsOf = (bin, seen = new Set()) => { if (seen.has(bin)) return []; seen.add(bin); const d = parsed.get(bin); if (!d) return []; if (d.alias) return funcsOf(String(d.alias), seen); return Object.keys(d.functions || {}).filter((f) => f !== 'inherit'); }; for (const bin of files) { const data = parsed.get(bin); if (data.alias) { aliasEdges.push({ from: bin, to: String(data.alias) }); continue; } const fns = data.functions || {}; const toolId = `gtfo:${bin}`; const pageUrl = `https://gtfobins.github.io/gtfobins/${bin}/`; const platform = GTFO_MACOS.has(bin) ? ['Linux', 'macOS'] : ['Linux']; if (!tools.has(toolId)) { tools.set(toolId, { id: toolId, name: bin, source: 'GTFOBins', platform, aliases: [], references: [pageUrl], count: 0 }); } for (const [fn, examples] of Object.entries(fns)) { asArray(examples).forEach((ex, i) => { const contexts = ex.contexts && Object.keys(ex.contexts).length ? Object.keys(ex.contexts) : ['unprivileged']; contexts.forEach((ctx) => { const ctxObj = ex.contexts?.[ctx] || null; const command = (ctxObj && ctxObj.code) || ex.code; if (!command || !String(command).trim()) return; let capability, nativeCategory, mitre, name; if (fn === 'inherit') { const from = String(ex.from || ''); const inheritedFns = funcsOf(from); const caps = uniq(inheritedFns.flatMap((f) => GTFO_FN_CAP[f] || [])); capability = caps.length ? caps : ['Execution']; const mit = uniq(inheritedFns.flatMap((f) => GTFO_FN_MITRE[f] || [])); mitre = uniq([...(ex.mitre || []), ...(mit.length ? mit : ['T1059'])]); nativeCategory = uniq(['inherit', ...inheritedFns.map((f) => `from:${from}`)]); name = `inherit ← ${from}`; } else { capability = [...(GTFO_FN_CAP[fn] || ['Execution'])]; nativeCategory = [fn]; mitre = uniq([...(ex.mitre || []), ...(GTFO_FN_MITRE[fn] || [])]); name = fn; } // sudo/suid/capabilities contexts also grant Privilege Escalation. if ((ctx === 'sudo' || ctx === 'suid' || ctx === 'capabilities') && !capability.includes('Privilege Escalation')) { capability = [...capability, 'Privilege Escalation']; } techniques.push({ id: `gtfo:${bin}:${fn}:${i}:${ctx}`, toolId, toolName: bin, name, source: 'GTFOBins', platform, capability, nativeCategory, command: String(command), description: (ctxObj && ctxObj.comment) || ex.comment || undefined, mitre, privilege: ctx, context: ctx, references: [pageUrl], }); tools.get(toolId).count++; }); }); } } // Attach aliases to their canonical tool. for (const { from, to } of aliasEdges) { const t = tools.get(`gtfo:${to}`); if (t) t.aliases.push(from); } return { techniques, tools: [...tools.values()], aliasCount: aliasEdges.length }; } // --------------------------------------------------------------------------- // LOLBAS // --------------------------------------------------------------------------- function ingestLolbas() { const base = join(VENDOR, 'lolbas', 'yml'); const dirs = ['OSBinaries', 'OSLibraries', 'OSScripts', 'OtherMSBinaries']; // HonorableMentions skipped const techniques = []; const tools = []; for (const d of dirs) { const dir = join(base, d); for (const f of listFiles(dir).filter((x) => x.endsWith('.yml'))) { const data = yaml.load(readFileSync(join(dir, f), 'utf8')) || {}; const name = data.Name || f.replace(/\.yml$/, ''); const stem = name.replace(/\.(exe|dll|ps1|com|scr|bat|cmd|vbs|js|msc|cpl|inf)$/i, ''); // Slug the FULL name (extension included) so exe/vbs twins such as // SyncAppvPublishingServer.{exe,vbs} stay distinct tools/ids. const nameSlug = name.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, ''); const toolId = `lolbas:${nameSlug}`; const pageUrl = `https://lolbas-project.github.io/lolbas/${lolbasUrlType[d]}/${stem}/`; const fullPath = asArray(data.Full_Path).map((p) => p.Path).filter(Boolean); const aliases = asArray(data.Aliases).map((a) => a.Alias).filter(Boolean); const contributors = asArray(data.Acknowledgement) .map((a) => [a.Person, a.Handle].filter(Boolean).join(' ')) .filter((s) => s && s.toLowerCase() !== 'unknown'); tools.push({ id: toolId, name, source: 'LOLBAS', platform: ['Windows'], toolType: lolbasType[d], aliases, fullPath, author: data.Author || undefined, created: data.Created || undefined, contributors, references: [pageUrl], count: 0, }); const tool = tools[tools.length - 1]; asArray(data.Commands).forEach((c, i) => { const cat = c.Category; const capability = LOLBAS_CAT_CAP[cat] ? [...LOLBAS_CAT_CAP[cat]] : ['Execution']; const detection = asArray(data.Detection).map((det) => { const key = ['IOC', 'Sigma', 'Analysis', 'Elastic', 'Splunk', 'BlockRule'].find((k) => det[k]); return key ? { type: key, value: String(det[key]) } : null; }).filter(Boolean); const references = uniq([...asArray(data.Resources).map((r) => r.Link), pageUrl]); techniques.push({ id: `${toolId}:${i}`, toolId, toolName: name, name: cat, source: 'LOLBAS', platform: ['Windows'], capability, nativeCategory: [cat], command: String(c.Command || '').trim(), description: c.Description || undefined, usecase: c.Usecase || undefined, mitre: c.MitreID ? [String(c.MitreID)] : [], privilege: normPrivilege(c.Privileges), fullPath, toolType: lolbasType[d], detection: detection.length ? detection : undefined, references, }); tool.count++; }); } } return { techniques, tools }; } // --------------------------------------------------------------------------- // WADComs — shared normalizer for upstream (.md) and daemon-authored (TS/JSON). // --------------------------------------------------------------------------- function wadPlatform(os, services, items) { const plats = new Set(); for (const o of asArray(os)) { const s = String(o).toLowerCase(); if (s.includes('windows')) plats.add('Windows'); else if (s.includes('linux') || s.includes('unix')) plats.add('Linux'); else if (s.includes('mac') || s.includes('osx') || s.includes('darwin')) plats.add('macOS'); } const isAD = asArray(services).some((s) => AD_SERVICES.has(s)) || asArray(items).some((i) => AD_ITEMS.has(i)); if (isAD) { plats.add('ActiveDirectory'); plats.add('Windows'); } if (plats.size === 0) plats.add('Windows'); return [...plats]; } function wadTechnique(entry, source) { const attackTypes = asArray(entry.attackTypes ?? entry.attack_types); const os = asArray(entry.os ?? entry.OS); const services = asArray(entry.services); const items = asArray(entry.items); const references = asArray(entry.references); const capability = uniq(attackTypes.flatMap((a) => WAD_ATTACK_CAP[a] || [])); const slug = entry.slug; const family = String(slug).split('-')[0] || slug; // Impacket is a *suite* of independent example scripts, not one tool — file // each technique under its own `examples/