CTF7
PricingFree tierFAQ Sign in

What is SQL injection in a CTF?

Input that becomes part of a database query. How it works and how it is fixed.

SQL injection (SQLi) is a web vulnerability where attacker-controlled input is interpreted as part of a database query, allowing data to be read, changed or bypassed. It happens when an application builds SQL by joining strings instead of using parameters.

Example

A login handler builds this query:

SELECT * FROM users WHERE name = '$name' AND pass = '$pass'

Entering admin' -- as the name comments out the password check, so the query returns the admin row. In a CTF the flag is then shown on the admin page, or you extract it with a UNION SELECT from another table.

How it is fixed

  • Use parameterized queries or an ORM that does.
  • Give the database account only the rights it needs.
  • Treat error messages as a leak and do not show them.

Practice only on targets you have permission to test, such as a challenge instance or a local intentionally vulnerable app.

On CTF7

Web challenges with a database run as isolated lab instances per team. Organizers can add hints that unlock for a cost, and Raw Ops events score real-style reports using CVSS 4.0. Try the CVSS calculator to see how an injection bug scores.

Learn more

Read the web exploitation guide for worked examples and tools, or browse all CTF guides.

Browse the full CTF and cybersecurity glossary for more terms.

Plan your next event with us

A free jeopardy event for up to 50 players goes live when you publish it. For flagship events, our team can build the challenges and run the managed formats: attack-defense, King of the Hill and SOC simulations.

CTF7 mascot holding a CTF7 flag