labs / sqli

SQL Injection Lab

Exploit a vulnerable search query and exfiltrate the admin's password.

Injection Beginner Server lab
leaderboard →
    Objective Make the user-search return the admin account's password, then submit it as the flag.

    This staff tool looks up a user by exact username. It builds its query like … WHERE username = '<your input>' — by gluing strings together. Try a normal name first (alice), then think about what an apostrophe could do.

    How the fix works

    The bug is that input changes the structure of the query. The fix is a parameterized query: WHERE username = ? with the value bound separately, so input is always treated as data, never as SQL. Every row you just leaked would be impossible against that.

    $ patch ./sqli

    You broke it — now fix it. Which change actually stops the SQL injection?

    const sql = "SELECT id, username FROM users WHERE username = '" + input + "'";
    db.query(sql);