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
SourcesFlow.astroAstro279 lines10.8 KiBraw download
---
import facets from '../data/facets.json';
import { SOURCES, SOURCE_META } from '../lib/taxonomy';

/**
 * How the catalog is assembled, as a diagram that moves: every source
 * flows into the one index, and the index carries ATT&CK mapping and
 * detection guidance out the other side.
 *
 * Drawn from the site's own data rather than typed in. The boxes on the
 * left are `SOURCES`, in order, each in its own accent with the number of
 * techniques it contributes (`facets.json`), so adding a collection adds
 * a box and a path and nothing here needs editing. The geometry is worked
 * out below at build time; the page ships a finished SVG.
 *
 * The moving dots are the only script. They show direction, not volume:
 * three per path whatever the count, and the note under the diagram says
 * so. They stop when the diagram is off screen, when the tab is hidden,
 * and under reduced motion (the OS setting or `<html data-motion="reduce">`),
 * where they rest part-way along each path so the direction still reads.
 */
const c = facets.counts;
const bySource = c.bySource as Record<string, number>;

const NUMBER = ['No', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight'];
const title = `${NUMBER[SOURCES.length] ?? SOURCES.length} sources, one index`;

/* ---- geometry: a 960-wide drawing, as tall as the sources need ---- */
const W = 960;
const TOP = 48;
const BOX_H = 56;
const GAP = 24;
const SRC_X = 40;
const SRC_W = 220;
const IDX_X = 400;
const IDX_W = 200;
const OUT_X = 740;
const OUT_W = 200;

const n = SOURCES.length;
const stackH = n * BOX_H + (n - 1) * GAP;
const H = TOP + stackH + 32;
const midY = TOP + stackH / 2;

const IDX_H = Math.min(stackH, Math.max(112, n * 34));
const idxTop = midY - IDX_H / 2;

const sources = SOURCES.map((id, i) => {
  const meta = SOURCE_META[id];
  const y = TOP + i * (BOX_H + GAP);
  const cy = y + BOX_H / 2;
  // Where this source's path meets the index: spread down its left edge.
  const entry = idxTop + ((i + 1) * IDX_H) / (n + 1);
  const x0 = SRC_X + SRC_W;
  const bend = (x0 + IDX_X) / 2;
  return {
    id,
    label: meta.label,
    accent: meta.accent,
    count: bySource[id] ?? 0,
    y,
    d: `M${x0} ${cy} C ${bend} ${cy}, ${bend} ${entry}, ${IDX_X} ${entry}`,
  };
});

const OUTPUTS = [
  { label: 'ATT&CK mapping', accent: 'pine' },
  { label: 'Detection guidance', accent: 'gold' },
];
const outs = OUTPUTS.map((o, i) => {
  const y = midY + (i === 0 ? -(BOX_H + GAP) : GAP);
  const cy = y + BOX_H / 2;
  const exit = idxTop + ((i + 1) * IDX_H) / (OUTPUTS.length + 1);
  const x0 = IDX_X + IDX_W;
  const bend = (x0 + OUT_X) / 2;
  return { ...o, y, d: `M${x0} ${exit} C ${bend} ${exit}, ${bend} ${cy}, ${OUT_X} ${cy}` };
});

const aria =
  `${sources.map((s) => s.label).join(', ')} feed DÆMONBins, ` +
  `which carries ${OUTPUTS.map((o) => o.label).join(' and ')} with each entry`;
---
<div class="sflow" data-sflow>
  <p class="sflow__title">{title}</p>
  <p class="sflow__intro">
    How the catalog is assembled. Each collection is ingested from its own repository at a pinned
    commit, every entry is expanded into individual techniques, and all of them land in one index
    that carries ATT&amp;CK mapping and detection guidance with each entry.
  </p>

  <div class="sflow__wrap">
    <svg class="sflow__svg" viewBox={`0 0 ${W} ${H}`} role="img" aria-label={aria}>
      <text class="sflow__cap" x={SRC_X} y="24">SOURCES</text>
      <text class="sflow__cap" x={IDX_X} y="24">INDEX</text>
      <text class="sflow__cap" x={OUT_X} y="24">CARRIED WITH EACH ENTRY</text>

      {sources.map((s) => <path class="sflow__path" data-sflow-path data-acc={s.accent} d={s.d} />)}
      {outs.map((o) => <path class="sflow__path" data-sflow-path data-acc={o.accent} data-fast d={o.d} />)}

      {sources.map((s) => (
        <g>
          <rect class="sflow__box" x={SRC_X} y={s.y} width={SRC_W} height={BOX_H} style={`--acc: var(--${s.accent});`} />
          <text class="sflow__name" x={SRC_X + 20} y={s.y + 34}>{s.label}</text>
          <text class="sflow__n" x={SRC_X + SRC_W - 16} y={s.y + 34} text-anchor="end">{s.count.toLocaleString('en-GB')}</text>
        </g>
      ))}

      <rect class="sflow__core" x={IDX_X} y={idxTop} width={IDX_W} height={IDX_H} />
      <text class="sflow__coretxt" x={IDX_X + 20} y={midY - 4}>DÆMONBins</text>
      <text class="sflow__coresub" x={IDX_X + 20} y={midY + 20}>{c.techniques.toLocaleString('en-GB')} techniques</text>

      {outs.map((o) => (
        <g>
          <rect class="sflow__box" x={OUT_X} y={o.y} width={OUT_W} height={BOX_H} style={`--acc: var(--${o.accent});`} />
          <text class="sflow__name sflow__name--out" x={OUT_X + 20} y={o.y + 34}>{o.label}</text>
        </g>
      ))}

      <g data-sflow-dots></g>
    </svg>
  </div>

  <div class="sflow__foot">
    <button class="sflow__btn" type="button" data-sflow-pause aria-pressed="false">Pause the flow</button>
    <span class="sflow__note">The dots show direction only; they are not a count of entries.</span>
  </div>
</div>

<style>
  .sflow { margin-top: 1rem; }
  .sflow__title {
    margin: 0;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: var(--step-3);
    line-height: 1.02;
    letter-spacing: -0.03em;
    text-transform: uppercase;
    color: var(--text);
  }
  .sflow__intro { max-width: 62ch; margin: 0.9rem 0 0; color: var(--subtle); font-size: var(--step-0); line-height: 1.6; }

  /* The drawing is 960 units wide and does not reflow; under that it
     scrolls sideways inside its own frame instead of shrinking the type
     past reading size. */
  .sflow__wrap { margin-top: 1.6rem; overflow-x: auto; border-top: 1px solid var(--text); border-bottom: 1px solid var(--text); padding-block: 20px; }
  .sflow__svg { display: block; width: 100%; min-width: 760px; height: auto; }
  .sflow__svg text { font-family: var(--font-plex); fill: var(--text); }
  .sflow__svg .sflow__cap { font-size: 11px; letter-spacing: 0.14em; fill: var(--muted); }
  .sflow__box { fill: var(--surface); stroke: var(--text); stroke-width: 1; }
  .sflow__name { font-size: 16px; }
  .sflow__name--out { font-size: 15px; }
  .sflow__svg .sflow__n { font-size: 12px; fill: var(--muted); font-variant-numeric: tabular-nums; }
  /* The index is the one inverse block: ink where the page is paper, and
     the other way round at night, from the same two tokens. */
  .sflow__core { fill: var(--text); stroke: var(--text); }
  .sflow__svg .sflow__coretxt { font-size: 20px; font-weight: 500; fill: var(--base); }
  .sflow__svg .sflow__coresub { font-size: 12px; fill: var(--base); opacity: 0.78; }
  .sflow__path { fill: none; stroke: color-mix(in srgb, var(--text) 34%, transparent); stroke-width: 1.2; }

  .sflow__foot { margin-top: 1.1rem; display: flex; flex-wrap: wrap; align-items: center; gap: 0.7rem 1rem; }
  .sflow__btn {
    display: inline-flex; align-items: center; min-height: 44px; padding: 0 18px;
    border: 1px solid var(--text); background: transparent; color: var(--text);
    font-family: var(--font-plex); font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; cursor: pointer;
  }
  .sflow__btn:hover { background: var(--text); color: var(--base); }
  .sflow__btn:focus-visible { outline: 2px solid var(--iris); outline-offset: 2px; }
  .sflow__note { font-family: var(--font-plex); font-size: 13px; color: var(--muted); }
</style>

<style is:global>
  /* The dots are created by the script, so the scoped rules above cannot
     reach them. One rule per accent the taxonomy uses. */
  .sflow__dot[data-acc='love'] { fill: var(--love); }
  .sflow__dot[data-acc='iris'] { fill: var(--iris); }
  .sflow__dot[data-acc='pine'] { fill: var(--pine); }
  .sflow__dot[data-acc='foam'] { fill: var(--foam); }
  .sflow__dot[data-acc='gold'] { fill: var(--gold); }
  .sflow__dot[data-acc='rose'] { fill: var(--rose); }
</style>

<script>
  /* Three dots per path, walked along it by length. Bound on every
     `astro:page-load` and let go on `astro:before-swap`: the router swaps
     the document, and a frame loop holding nodes from the last page would
     keep running against nothing. */
  const NS = 'http://www.w3.org/2000/svg';
  let stop: (() => void) | null = null;

  const still = () =>
    matchMedia('(prefers-reduced-motion: reduce)').matches ||
    document.documentElement.dataset.motion === 'reduce';

  function start(): void {
    stop?.();
    stop = null;
    const host = document.querySelector<HTMLElement>('[data-sflow]');
    const layer = host?.querySelector<SVGGElement>('[data-sflow-dots]');
    const btn = host?.querySelector<HTMLButtonElement>('[data-sflow-pause]');
    if (!host || !layer || !btn) return;

    layer.textContent = '';
    const paths = Array.from(host.querySelectorAll<SVGPathElement>('[data-sflow-path]')).map((p, i) => {
      const dots = [0, 1, 2].map((k) => {
        const dot = document.createElementNS(NS, 'circle');
        dot.setAttribute('r', '4.5');
        dot.setAttribute('class', 'sflow__dot');
        dot.dataset.acc = p.dataset.acc ?? 'iris';
        layer.appendChild(dot);
        return { dot, off: k / 3 + i * 0.11 };
      });
      return { p, len: p.getTotalLength(), dots, speed: 'fast' in p.dataset ? 0.0003 : 0.00022 };
    });

    let paused = false;
    let visible = true;
    let raf = 0;
    let clock = 0;
    let last = 0;
    let alive = true;

    const place = () => {
      for (const path of paths) {
        for (const d of path.dots) {
          const at = path.p.getPointAtLength(((clock * path.speed + d.off) % 1) * path.len);
          d.dot.setAttribute('cx', at.x.toFixed(1));
          d.dot.setAttribute('cy', at.y.toFixed(1));
        }
      }
    };
    const loop = (now: number) => {
      raf = 0;
      if (!alive) return;
      if (paused || !visible || document.hidden || still()) {
        last = 0;
        return;
      }
      if (last) clock += Math.min(64, now - last);
      last = now;
      place();
      raf = requestAnimationFrame(loop);
    };
    const kick = () => {
      if (!raf && alive) raf = requestAnimationFrame(loop);
    };

    const onPause = () => {
      paused = !paused;
      btn.setAttribute('aria-pressed', String(paused));
      btn.textContent = paused ? 'Resume the flow' : 'Pause the flow';
      kick();
    };
    btn.addEventListener('click', onPause);
    document.addEventListener('visibilitychange', kick);
    const seen = new IntersectionObserver((entries) => {
      visible = entries[entries.length - 1].isIntersecting;
      kick();
    });
    seen.observe(host);

    place();
    kick();

    stop = () => {
      alive = false;
      if (raf) cancelAnimationFrame(raf);
      seen.disconnect();
      btn.removeEventListener('click', onPause);
      document.removeEventListener('visibilitychange', kick);
    };
  }

  document.addEventListener('astro:page-load', start);
  document.addEventListener('astro:before-swap', () => {
    stop?.();
    stop = null;
  });
</script>