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
- Use parameterised queries or prepared statements. This is the main fix: data is never treated as code.
- Use an ORM correctly and avoid building raw query strings
- Give the database account only the permissions the application needs
- Validate input as a second layer, not the only one
- Do not show raw database errors to users
- 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.
