Skip to content
uencoder

SQL Injection

SQL injection is attackers splicing malicious SQL fragments into a query string so the database executes unintended commands.

Purpose

To keep attackers from manipulating SQL queries through input, stealing or tampering with the database.

Mechanism

When user input is concatenated directly into the SQL string (e.g., "SELECT * WHERE name='"+input+"'"), entering ' OR 1=1 -- can bypass the condition. Defenses: parameterized queries (prepared statements), ORMs, input validation, least-privilege accounts.

Use cases

  • Login bypass (' OR 1=1)
  • Data leakage (UNION SELECT)
  • Data tampering (UPDATE/DELETE)
  • Command execution (xp_cmdshell)

Examples

  • Input
    admin' --
    Output
    Bypasses password verification

    Comments out the password condition

Common errors

Building SQL with string concatenation
Always use parameterized queries

Related terms

Related tools

References