sqli-playground

SQLi Playground

Local, offline SQL Injection CTF lab — 60 progressive levels on MariaDB / MySQL.

Real vulnerable queries. Isolated databases per level. Random flags per install. Sequential unlock.

Educational use only. Run on your own machine. Do not expose this lab to the internet.

Live Demo Version License


Static UI preview (no database): Live Demo
Level 01 is interactive in the browser; the full lab needs a local install.

Share cards

After clearing a level you can export a difficulty-colored share card (six layouts). Examples by tier:

Easy Medium Hard
Easy share card Medium share card Hard share card
Expert Insane
Expert share card Insane share card

Features


Requirements

Stack Version
Python 3.10+
MariaDB 10.5+ or MySQL 8+
Docker optional (Compose v2)

Quick start (local)

1. Clone

git clone https://github.com/you-in-you/sqli-playground.git
cd sqli-playground

2. Python environment

python3 -m venv .venv
source .venv/bin/activate          # Windows: .venv\Scripts\activate
pip install -r requirements.txt

3. Database user

On many Linux distros, root uses socket auth. Create a dedicated user:

sudo mariadb -u root
CREATE USER IF NOT EXISTS 'ctf'@'localhost' IDENTIFIED BY 'ctfpass';
GRANT ALL PRIVILEGES ON *.* TO 'ctf'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;

4. Configure

Edit config.json if needed:

{
  "DB_HOST": "127.0.0.1",
  "DB_PORT": 3306,
  "DB_USER": "ctf",
  "DB_PASS": "ctfpass",
  "SECRET_KEY": "change-this-to-a-long-random-string",
  "HOST": "127.0.0.1",
  "PORT": 7080
}

Bind HOST to 127.0.0.1 for local-only access.

5. Run

chmod +x run.sh
./run.sh

This ensures databases (non-destructive), then starts Flask. Open the URL printed in the terminal (default http://127.0.0.1:7080).


Docker

Docker runs MariaDB + the web app together. No local MariaDB install required.

Start / stop (via ./run.sh)

git clone https://github.com/you-in-you/sqli-playground.git
cd sqli-playground

./run.sh docker up          # build + start (detached)
# Lab → http://127.0.0.1:5000

./run.sh docker logs        # follow web logs
./run.sh docker down        # stop
./run.sh docker down -v     # stop and delete DB volume (full wipe)

Equivalent Compose commands still work:

docker compose up --build -d
docker compose logs -f web
docker compose down

Lab maintenance inside Docker

Same verbs as local, prefixed with docker:

Goal Command
Status ./run.sh docker status
Ensure DBs ./run.sh docker ensure
Full rebuild ./run.sh docker -y install
Uninstall lab data ./run.sh docker -y uninstall
Shell in web ./run.sh docker shell

These run scripts/setup_db.py inside the web container (docker compose exec or a one-off run if the service is down).

Notes


CLI (./run.sh)

Local

Command What it does
./run.sh / ./run.sh start Ensure DBs, then start the lab server
./run.sh ensure Create missing DBs/tables; keep flags & progress
./run.sh install Drop lab DBs + flags, full rebuild
./run.sh reinstall Same as install
./run.sh uninstall Drop lab DBs + flags only (no rebuild)
./run.sh status Version, databases, progress
./run.sh -y install Skip confirmation prompts
./run.sh help Show help

Docker

Command What it does
./run.sh docker up Build images and start db + web
./run.sh docker down Stop containers
./run.sh docker down -v Stop and remove the DB volume
./run.sh docker logs Tail web logs
./run.sh docker ps Show compose services
./run.sh docker shell Shell inside the web container
./run.sh docker status setup_db status in the container
./run.sh docker ensure setup_db ensure in the container
./run.sh docker install setup_db install in the container
./run.sh docker -y install Same, non-interactive
./run.sh docker uninstall setup_db uninstall in the container

Examples:

./run.sh status
./run.sh install
./run.sh -y reinstall

./run.sh docker up
./run.sh docker status
./run.sh docker -y install
./run.sh docker logs
./run.sh docker down

Environment overrides:

Variable Effect
SQLI_CTF_FORCE_RESET=1 Auto-confirm destructive ops / migrations
SQLI_CTF_SKIP_RESET=1 Skip migrations
SQLI_CTF_SKIP_UPDATE=1 Skip remote version check in CLI status
SQLI_CTF_VERSION_URL=… Override version.json URL
SQLI_CTF_CONFIG=path Alternate config file
APP_VERSION Override local app version string
VERSION_CHECK_TIMEOUT HTTP timeout for version check (seconds)

How progress works


Project layout

.
├── app/
│   ├── main.py           # Flask routes & API (incl. /api/version)
│   ├── config.py         # Loads config.json / env
│   ├── db.py             # Progress, history, flag check
│   ├── levels/
│   │   ├── handlers.py   # Intentionally vulnerable level handlers
│   │   └── __init__.py   # Level metadata & registry
│   ├── static/           # CSS / JS (update modal)
│   └── templates/        # Dashboard UI
├── scripts/
│   └── setup_db.py       # DB toolkit (ensure / install / uninstall / …)
├── demo/                 # Static GitHub Pages preview
├── version/
│   └── version.json      # Published version + changelog (GitHub)
├── pictures/             # README screenshots & share-card samples
├── config.json           # Local settings
├── docker-compose.yml
├── Dockerfile
├── run.sh                # Local + Docker entrypoint
├── requirements.txt
└── README.md

Reset & maintenance

Progress only (SQL):

UPDATE sqli_ctf_meta.progress SET current_level = 1, solved = '';
TRUNCATE TABLE sqli_ctf_meta.attack_history;

New flags + clean progress:

./run.sh install
# Docker:
./run.sh docker -y install

Remove lab data from MySQL (keep source tree):

./run.sh uninstall
# Docker:
./run.sh docker -y uninstall

Common issues

Problem Fix
Access denied for user 'root'@'localhost' Use the ctf / ctfpass user, or enable password auth for root
Can't connect to MySQL server Start MariaDB: sudo systemctl start mariadb
ModuleNotFoundError: flask Activate venv and pip install -r requirements.txt
Port already in use Change PORT in config.json
Docker DB not ready Wait for healthcheck; ./run.sh docker logs or docker compose logs db
Permission denied on bind mounts (Fedora) Compose already uses :Z; ensure SELinux is not blocking Docker
Update modal never appears Normal if you are on the latest version, offline, or dismissed it this session

Security notes


Updates

Version checks do not block startup.

  1. Web UI — After the dashboard loads, the client calls /api/version/check. The server fetches:

    https://raw.githubusercontent.com/you-in-you/sqli-playground/main/version/version.json

    with a short timeout. If a newer version exists, a dismissible modal shows the changelog and a link to the repository. Closing it remembers the remote version for the browser session.

  2. CLI — ./run.sh status (or ./run.sh docker status) may still print a remote version summary. ensure / install no longer wait on the network for this check.

To publish a release: bump APP_VERSION in code/config, update version/version.json (version + changes), and push to main.


License

Educational use. Use responsibly.


AI Generation & Bug Reports

This project was built with the help of AI for educational purposes. Due to the nature of AI-generated code, you might encounter bugs, unexpected behavior, or logic flaws in some levels.

If you spot any issues or have suggestions for improvement, please Open an Issue or submit a Pull Request. Your feedback is much appreciated!

Author

you-in-you · Repository