SQL Injection Explained: Types, Examples and Prevention

What SQL injection is, how in-band, blind and out-of-band attacks work, a simple example and the defences that stop it, including parameterised queries.

Last updated 26 October 2026. Written by Zeeshan Aamiri, Security Architect and Director.

SQL injection is a vulnerability where an attacker's input changes the meaning of a database query. It has been understood for decades and is still found in real applications, which is why it has its own module in the CEH v13 syllabus.

How It Happens

If an application builds a query by gluing user input into a string, the input can contain SQL syntax. Imagine a login that builds a query from the username and password boxes. An attacker who types a quote followed by a condition that is always true can make the query succeed without a valid password.

Main Types

  • In-band (error-based and union-based): the results or errors come back on the same page
  • Blind (boolean-based and time-based): the page shows nothing useful, so the attacker asks yes or no questions and watches behaviour or timing
  • Out-of-band: data is sent to a server the attacker controls through a different channel

What an Attacker Can Do

  • Read data they should not see, such as users and orders
  • Bypass authentication
  • Change or delete data
  • In some setups, run commands on the database server

How to Prevent It

  1. Use parameterised queries or prepared statements. This is the main fix: data is never treated as code.
  2. Use an ORM correctly and avoid building raw query strings
  3. Give the database account only the permissions the application needs
  4. Validate input as a second layer, not the only one
  5. Do not show raw database errors to users
  6. Use a web application firewall as an extra layer, not a replacement for fixing the code

Practise Legally

Learn on intentionally vulnerable applications in a lab, never on real systems without permission. Our CEH v13 course and Lab include SQL injection exercises where you exploit a flaw by hand and then fix it with parameterised queries.

Ready to Start?

Tell us what you want to learn or secure. We reply within one business day.

Send an Enquiry

Leave your details and we will reply within one business day.

Prefer chat? Message us on WhatsApp or call +91 91647 52266.