A hands-on, fully offline SQL injection training lab — dedicated exclusively to SQL injection, from first principles through real-world exploitation chains.
By difficulty: Beginner 10, Intermediate 13, Advanced 16, Expert 8, Pro 6 By category: Fundamentals 13, Authentication 6, UNION 7, Error-Based 2, Blind 7, Second-Order 4, Filter Bypass 5, HTTP/API 3, Real-World 3, Advanced 3
All labs are fully implemented and individually verified end-to-end by actually exploiting each one over HTTP against the running server. Recent passes added:
- Critical flag-security fix:
/interactnever returns the actual flag under any circumstances — only a booleanexploitedsignal. The flag is only obtainable viaGET /reveal-flag, gated on server-side confirmation. See "Flags" below. - 13 new labs filling real gaps: ORDER BY blind, LIMIT/OFFSET blind, dynamic column injection, reporting/aggregate SQLi, a nested-subquery "complex query" lab (comment bypass genuinely fails here — verified — requiring manual parenthesis-balancing instead), true character-by-character blind extraction, three more second-order scenarios, two more cookie/header labs using UNION extraction, a case-sensitivity filter bypass, a double-encoding bypass (two deliberate app-level decode passes), and a JSON-array API bulk-lookup.
- Automated regression suite (
npm test, 252 checks) — spawns the real server against a throwaway DB: a flag-leak sweep across every lab, plus real exploit payloads for a representative sample spanning every category/tier, each checked through the complete reveal → submit → complete → reset cycle. - Category-specialized UI: Authentication labs render as a real login card; HTTP/API labs render as a Postman-style request/response tester; Blind labs render a clean signal-only readout instead of raw JSON; Second-Order labs get a two-step wizard (numbered "store" and "trigger reuse" panels with a connecting arrow) instead of generic buttons. A "developer view" toggle still exposes the raw request/response everywhere. All other categories, and any lab that doesn't fit a specialized shell, keep the original generic layout.
- Schema migrations for existing installs — new columns added via
ALTER TABLEwith existing data preserved, verified against simulated pre-upgrade databases with real prior progress. - Broader "real application" UI coverage: beyond the 4 categories
already specialized (Auth, API, Blind, Second-Order), a
uiPersonamechanism now targets labs individually rather than by category — since categories like Fundamentals mix genuinely different contexts (a product search bar vs. a cookie-driven theme picker vs. an availability check) that shouldn't all look the same. Two new personas: a storefront shell (search bar + product grid, with an automatic "Security filter: BLOCKED" banner when a filter-bypass lab rejects a request) applied to ~21 product/search-flavored labs across Fundamentals, UNION, Error-Based, Blind, Filter Bypass, and Real-World; and a data console shell (internal admin-tool framing, results as a real table) applied to the schema-enumeration and reporting labs. The second-order wizard also now applies to any two-step lab regardless of category (previously Second-Order only — now coversP03too). - Documentation fixes: a couple of stale "40 labs" comments in
registry.ts/types.ts(left over from before the lab count grew) now correctly reflect the current count.
Real bugs caught during this work (not hypothetical — each one actually reproduced, then fixed and reverified):
B01/B06falsely triggeredexploitedon an empty search term, sinceLIKE '%%'trivially matches everything — no injection needed. Caught by the automated test suite on its first run.- The original double-encoding lab design relied on transport-level
auto-decode that a real browser's
URLSearchParamswould silently cancel out before the request even left the client — meaning it was solvable via curl but not through the app's own UI. Redesigned around two explicit, app-level decode passes instead. - A header-based lab originally used
User-Agent, which browsers'fetch()API forbids scripts from overriding — same class of bug, caught before shipping and renamed to a custom header. - The case-sensitivity bypass lab initially also blocked
--case-independently, which meant the trailing clause could never be neutralized regardless of the UNION-case trick — simplified the query so the lab tests one technique cleanly.
See sqli-lab-plan.md for the original master challenge matrix.
This pass didn't add or remove a single lab — it rebuilt how you reach
them. Previously every lab was tested by filling in a generic form that
POSTed to an internal /api/labs/:id/interact endpoint. That's still
there (see below), but it's no longer what you actually test against.
Every one of the 53 labs now has a real, believable HTTP route —
GET /products/search, POST /login, POST /api/v1/products/search,
and so on — serving genuine server-rendered HTML pages or JSON APIs,
with real cookies, real headers, real HTTP status codes (200/302/400/
401/403/404/500), and realistic response bodies. None of this depends on
frontend JavaScript: every route works identically whether you reach it
from a browser, curl, or Burp Suite (Proxy → Repeater → Intruder all
work unmodified). See server/target-app/routeMap.ts for the full
lab → route mapping.
- The lab engine and the target application are now separate layers.
server/target-app/*.tsholds 7 routers (storefront, auth, account, workflows, orders, reports, api) that call each lab's existing, unchangedhandle(req)— the actual vulnerable query logic isn't touched — but render a realistic response instead of a JSON debug envelope.server/routes/labs.ts(progress, hints, flags, reset) is unchanged and still backs the training UI. - Zero leakage by default. The target application's HTTP response
never includes the executed SQL query or an
exploitedflag —server/target-app/respond.tsstrips both before anything reaches the wire. Exploitation is detected and recorded server-side (recordExploitConfirmed) independently of what the client sees. - Developer / Lab Debug View — opt-in, separate endpoint.
GET /api/labs/:id/debugreturns the raw request, executed SQL, and response for your most recent hit on that lab's real route (server/target-app/debugStore.ts, in-memory, cleared on reset). Never fetched automatically — the frontend only calls it when you click "Reveal" in the Lab View. - Multi-step labs are genuine two-request workflows. Second-order
and chained labs (
A10,E03,SO01,SO02,P03) each expose a real "save" route and a real "trigger" route — e.g.POST /account/profilethenGET /admin/directory— so exploiting them means making two ordinary HTTP requests, not clicking a wizard's "next step" button. - Filter-bypass rejections read like application validation, not a
security product. Where a lab's filter blocks a payload, the target
app now returns a generic
400("We couldn't process that request...") instead of a"Security filter: BLOCKED"banner. The lab's own internal message is preserved verbatim in the opt-in Debug View for learners who want it. /api/labs/:id/interactstill exists, unchanged, and the original 647-check regression suite still passes against it unmodified — it's now explicitly the internal/legacy path, used by the in-page "Quick tester" (demoted, collapsed by default, clearly labeled) and bytests/regression.test.ts. It is no longer the primary workflow.- New 964-check regression suite (
tests/realistic-workflow.test.ts,npm run test:realistic) exercises all 53 labs through their real routes exclusively — normal request, exploit request, leak checks on both, server-sideexploitConfirmedverification, Developer/Debug View accuracy, and the full reveal → submit → complete → reset cycle — plus dedicated Burp-Repeater-style spot checks (capture a request, change one field, resend) across categories.npm testnow runs both suites; 1,611 checks total, 0 failures.
Real bugs this caught (each reproduced against the running server, then fixed and reverified — not hypothetical):
- Real HTML
<form method="POST">submissions were silently dropped: the server only hadexpress.json()registered, notexpress.urlencoded(), so every form-based lab's POST body arrived empty. Every login, checkout, and workflow-save route was affected until this was added. B08's new route used a display-friendly field name (category) that didn't match the lab handler's actual expected query key (cat) — the exploit payload was silently never reaching the vulnerable query. Caught immediately by the new suite'sexploitConfirmedcheck failing.SO02's second query interpolates the stored "preferred name" as a bare, unquoted SQL expression (not inside quotes, unlike the other second-order labs) — so genuinely ordinary free-text input breaks it with a real SQL error, independent of any injection attempt. This is an existing property of that lab's own vulnerable design (not introduced here); the test's benign baseline value was adjusted to a numeric string to avoid tripping over it while still exercising the lab as-authored.
Honest limitations of this pass:
- Titles and objectives were not rewritten for spoiler-reduction
(spec sections 18/20/21) — several still name the technique
(
"UNION Filter Bypass", etc.). The category label is still visible on the dashboard too. This is a deliberate scope cut to prioritize the architectural change (which is the harder, higher-value part) within this pass; it's a reasonable follow-up, not done here. - No actual browser/Playwright click-through was performed for this
pass either (same network restriction as the note below) — verification
here is via the automated suites plus manual
curlspot-checks shown in this file's history, not a rendered browser.
cd sql-injection-lab
npm install
npm run devOpen http://localhost:3000 — that's the training dashboard. Each lab's page now has an "Open target application ↗" button; that's the real app to actually test (browser, curl, or Burp all work). The in-page "Quick tester" and "Developer / Lab Debug View" are both optional and collapsed by default.
No Docker, no external database, no internet connection required after
npm install. The SQLite database is created and seeded automatically on
first run.
- Frontend: React + TypeScript + Vite + Tailwind, served by the same process as the API (single port, single command).
- Backend: Node.js + Express + TypeScript.
- Database: SQLite via
better-sqlite3, file atserver/db/lab.sqlite(gitignored, regenerated automatically). - Safe app state (progress, install salt) is managed through Drizzle ORM with fully parameterized queries.
- Vulnerable lab data (users, products, etc.) is queried with deliberate raw string concatenation inside each lab's handler only — that's the actual, exploitable vulnerability, not a simulation.
server/
db/ — schema, client, seed/auto-init
labs/ — one file per challenge; registry.ts is the master list
engine/ — flag validation, hints, progress, reset (shared logic)
routes/ — Express routers for the lab engine (progress/hints/flags)
target-app/ — the realistic target applications (see above): routeMap,
shared HTML layout, debug snapshot store, and one router
per app (storefront, auth, account, workflows, orders,
reports, api)
src/
pages/ — Dashboard, LabView
components/ — ChallengeCard, HintPanel, FlagSubmit, SolutionPanel, etc.
lib/api.ts — typed frontend API client
Each lab's flag is derived server-side via HMAC(install_salt, lab_id),
unique per installation. The flag is never included in any /interact
response, under any circumstances — exploitation only ever returns a
boolean exploited: true signal. The server independently persists that
confirmation (lab_progress.exploit_confirmed), and the flag is only
obtainable afterward via GET /api/labs/:id/reveal-flag, which checks
that server-side state and 403s otherwise. It is never present in any
frontend bundle, HTML, localStorage, or unauthenticated API response.
- Create
server/labs/<category>/<id>.tsimplementing theLabDefinitioninterface (server/labs/types.ts): objective, hints (3), solution,handle(req)(the real vulnerable query), andreset(). - Register it in
server/labs/registry.ts'simplementedLabsmap — itsstatuson the dashboard flips from "planned" to "available" automatically. - If its input context isn't a simple GET query param, add its param
mapping (or a small dedicated form) in
src/pages/LabView.tsx.
This pass focused entirely on verification and fixing what the previous passes' lighter checks had missed — no new labs were added.
- Automated suite expanded from a representative ~24-lab sample to all
53 labs (
npm test, 647 checks) — every lab now has a real, previously-verified exploit payload run through the complete reveal → submit → complete → reset cycle. A coverage-completeness meta-check fails loudly if a lab is ever added without a corresponding test, or if a test references a lab that no longer exists. - A duplicate test entry removed, and the catalog-count check
tightened from a loose
>= 40to an exact=== 53. - A real, previously-undetected bug found and fixed:
I07's "exploited" detection (rows.length > totalVisibleProducts()) could mathematically never fire when using the lab's own suggested payload (a neutralid=0base + one UNION-appended row will never exceed a 6-row baseline). This had been latent since early in the build — caught only once test coverage became exhaustive rather than representative. Fixed with a data-driven check (does the displayed value match a real product name) that's correct regardless of which base ID the payload uses. - Automated
uiPersonavalidation added — checks every persona value is recognized, isn't assigned alongside multi-step actions (where the wizard shell always wins, making it dead config), and thatstorefrontisn't assigned to a non-array result shape (which would render as a permanently empty grid). This caughtE02being taggeddataConsolewith a bare{found: bool}result — rather than just removing the mismatched tag,DataConsoleShellwas improved to render any object shape as a clean key:value readout, which is a genuine general improvement, not a workaround. - The 6 remaining labs on the plain generic layout now have a proper
shell too — three new personas: a preferences panel for
cookie-driven pickers (
B09,LG01), a header inspector (dev-tools-style, forI02/UA01), and a contact-form shell for multi-field POST forms (B04,P01). Every one of the 53 labs now has a themed interface — zero remain on the bare generic form. - Two more real bugs found via manual code-level review (see below)
and fixed:
AuthLoginShellalways showed "Access denied" forA02regardless of actual outcome, since that lab's response nests its error/success data ({error}/{loggedInAs, permissions}) rather than using the top-level shape the shell originally checked for. Separately,StorefrontShellonly ever displayed a title + one "price-like" field, silently hiding a lab's actual extracted data for any lab whose columns didn't match that naming pattern (P02'stracking_code, for instance) — now shows every column.
On manual browser verification — an honest limitation: I attempted
to install Playwright to actually render and click through every lab in
a real headless browser, which would have been the most rigorous
possible check. The npm package installs fine, but downloading the
actual browser binary is blocked by this environment's network egress
restrictions (cdn.playwright.dev isn't reachable here) — there's no
way for me to work around that. Rather than claim a browser check I
couldn't actually perform, I did the most rigorous alternative
available: a systematic line-by-line review of every lab's assigned
shell component against that lab's actual runtime result shape (not
the shape I assumed when I originally wrote each shell), which is what
surfaced the two bugs above. If you're able to click through the 53
labs yourself, that remains the one verification step this project
hasn't had.
npm testSpawns the real server against a throwaway database and runs the full regression suite: a flag-leak sweep across every lab, plus real exploit payloads for a representative sample across every category and difficulty tier, each verified through the complete reveal-flag → submit → complete → reset cycle. Exits non-zero on any failure (CI-friendly).
npm testRuns both regression suites back to back (npm run test:regression && npm run test:realistic), 1,611 checks total:
npm run test:regression(647 checks) — the original suite, driving every lab through the internal/api/labs/:id/interactlab-engine endpoint directly: a flag-leak sweep anduiPersonavalidation across every lab, plus a real exploit payload for every one of the 53 labs, each verified through the complete reveal-flag → submit → complete → reset cycle.npm run test:realistic(964 checks) — drives every lab through its real target-application route instead (ordinary GET/POST, form bodies, JSON bodies, cookies, headers — curl/Burp-style, no lab-engine shortcut): normal-request sanity, the exploit itself, leak checks on both, server-sideexploitConfirmedverification, Developer/Debug View accuracy, the full completion cycle, and dedicated Burp-Repeater-style spot checks.
Both spawn the real server against a throwaway database and exit non-zero on any failure (CI-friendly).
npm run db:resetDrops and recreates the vulnerable lab tables and reseeds starter data. Per-lab progress in the dashboard is independent of this and resets via each lab's own "Reset lab" button.
- Port 3000 already in use: stop whatever else is using it, or change
PORTinserver/index.tsandvite.config.ts. better-sqlite3fails to build on install: ensure you're on a supported Node.js LTS version; it ships prebuilt binaries for common platforms.