// Metabase Exploit Tooling with Bun · Part 5

Packaging the Scanner

Turn the script into a proper CLI — argument flags, an opt-in confirmation check, enterprise version handling, and clean exit codes for scripting.

TypeScriptBunCLITooling
4 min read

Four parts in, recon.ts fingerprints a target, enumerates what it leaks, and can confirm the CVE-2023-38646 injection on request. This part turns that script into a small CLI anyone — including a future you — can run without reading the source first.

Every code block below replaces the straight-line tail of the script — the bare const props = await fetchProperties(BASE) and everything after it that Parts 1 through 4 added at the bottom of the file. The fetchProperties, enumerate, confirmInjection, parseTag, and isBefore functions, and the SessionProperties and Findings interfaces, all stay exactly as they are — only the bottom of the file, where the script actually runs, changes. BASE goes away too: the target now comes from a command-line argument instead of an environment variable.

Reading flags

Bun doesn’t ship an argument parser, but util.parseArgs from Node’s standard library works fine under Bun and needs no dependency:

import { parseArgs } from "node:util";

const { values, positionals } = parseArgs({
  args: Bun.argv.slice(2),
  options: {
    confirm: { type: "boolean", default: false },
    json: { type: "boolean", default: false },
    help: { type: "boolean", default: false },
  },
  allowPositionals: true,
});

if (values.help || positionals.length === 0) {
  console.log("Usage: bun run recon.ts [--confirm] [--json] <target-url>");
  process.exit(values.help ? 0 : 1);
}

const target = positionals[0]!;

--confirm makes the injection check in Part 4 opt-in rather than automatic — a scanner that silently probes for RCE on every run is a worse default than one that reports the version and token exposure, and only goes further when asked.

Normalizing enterprise versions

Part 1’s version check assumed an open-source 0.x.y tag. Enterprise builds use a parallel 1.x.y line with its own patch schedule, so comparing them on the same number line is wrong. Detect which line we’re on and compare against the matching patched release:

const PATCHED_OSS = [0, 46, 6, 1];
const PATCHED_EE = [1, 46, 6, 1];

function isVulnerable(tag: string): boolean {
  const parts = parseTag(tag);
  const patched = (parts[0] ?? 0) >= 1 ? PATCHED_EE : PATCHED_OSS;
  return isBefore(parts, patched);
}

(parseTag and isBefore are unchanged from Part 1.)

Structured output

Pretty-printed by default; --json switches to a single compact line, so the tool composes with jq or a scanning pipeline instead of only being read by a human:

function report(found: Findings, confirmed: boolean | null): void {
  if (values.json) {
    console.log(JSON.stringify({ target, ...found, confirmed }));
    return;
  }
  console.log(`Target:      ${target}`);
  console.log(`Version:     ${found.version}`);
  console.log(`Vulnerable:  ${isVulnerable(found.version) ? "yes" : "no"}`);
  console.log(`Setup-token: ${found.setupToken ?? "(not exposed)"}`);
  if (confirmed !== null) console.log(`Confirmed:   ${confirmed ? "yes" : "no"}`);
}

Exit codes

A scanner that always exits 0 is useless in a pipeline — nothing downstream can tell success from failure without parsing output. Use the exit code to carry the one-bit answer a script actually needs:

const props = await fetchProperties(target);
const found = enumerate(props);
let confirmed: boolean | null = null;
if (values.confirm && found.setupToken) {
  confirmed = await confirmInjection(target, found.setupToken);
}
report(found, confirmed);
process.exit(isVulnerable(found.version) ? 1 : 0);

0 means “not vulnerable, by version”; 1 means “it’s in range.” Keep the version check as the exit-code signal rather than confirmed, since --confirm is opt-in — the tool should still give a useful exit code when it wasn’t asked to probe.

Running the finished tool

$ bun run recon.ts --confirm http://localhost:3000
Target:      http://localhost:3000
Version:     v0.46.6
Vulnerable:  yes
Setup-token: SETUP-TOKEN-PLACEHOLDER
Confirmed:   yes
$ echo $?
1
$ bun run recon.ts --json http://localhost:3000
{"target":"http://localhost:3000","version":"v0.46.6","setupToken":"SETUP-TOKEN-PLACEHOLDER","siteName":null,"authProviders":[],"confirmed":null}

Where we end up

Five parts, one file: a fingerprinter, an enumerator, an injection confirmer, and a CLI wrapper around all three — a couple hundred lines of TypeScript, no dependencies beyond Bun’s own standard library, that turns one CVE advisory into something you can actually point at a target and run. That’s the shape worth taking into the next CVE: read the advisory, find the unauthenticated primitive, write the smallest tool that proves it, stop before you have to ask whether you should.

← All parts