Course contentsShow
← Computer Science
Lesson 2474 of 2,87255. Web SecurityFree lesson

What is SQL Injection?

Understanding how attackers inject malicious SQL code through application inputs to manipulate database queries.

What is SQL Injection?

You'll learn: How attackers exploit poorly secured application inputs to inject malicious SQL code that manipulates database queries.

The Core Vulnerability

SQL Injection (SQLi) occurs when an application builds database queries by directly concatenating user input into SQL strings without proper validation or sanitization. Think of it like a malicious customer at a restaurant who, instead of simply ordering from the menu, manages to whisper instructions directly to the chef that change what everyone else receives.

When your web application accepts user input—through login forms, search boxes, URL parameters, or any other input field—and embeds that input directly into a SQL query, an attacker can craft special input that breaks out of the intended query structure and injects their own SQL commands.

Why It's Dangerous

Attackers can use SQL injection to:

  • Bypass authentication (logging in without valid credentials)
  • Read sensitive data from the database
  • Modify or delete database records
  • Execute administrative operations on the database
  • In some cases, execute commands on the underlying operating system

The vulnerability stems from the application treating untrusted user data as trusted SQL code. Instead of the input being data for the query, it becomes part of the query's logic itself.

The Attack Pattern

The attacker exploits the difference between what developers intend the query to do and what it actually does when malicious input is inserted. By injecting SQL metacharacters (like quotes, semicolons, or comment markers), attackers can terminate the intended query early and append their own malicious SQL statements.

Key Takeaway: SQL Injection is a code injection attack where malicious SQL statements are inserted into application inputs, exploiting the lack of separation between code and data to manipulate database queries and potentially compromise the entire database.