CAPECattack pattern

CAPEC-66 SQL Injection

High Official page ↗
Abstraction
Standard
Status
Draft
Likelihood of attack
High
Typical severity
High
CAPEC version
3.9

Description

This attack exploits target software that constructs SQL statements based on user input. An attacker crafts input strings so that when the target software constructs SQL statements based on the input, the resulting SQL statement performs actions other than those the application intended. SQL Injection results from failure of the application to appropriately validate input.

Extended description

When specially crafted user-controlled input consisting of SQL syntax is used without proper validation as part of SQL queries, it is possible to glean information from the database in ways not envisaged during application design. Depending upon the database and the design of the application, it may also be possible to leverage injection to have the database execute system-related commands of the attackers' choice. SQL Injection enables an attacker to interact directly to the database, thus bypassing the application completely. Successful injection can cause information disclosure as well as ability to add or modify data in the database.

Execution flow

1. [Explore] [Survey application] The attacker first takes an inventory of the functionality exposed by the application. 2. [Experiment] [Determine user-controllable input susceptible to injection] Determine the user-controllable input susceptible to injection. For each user-controllable input that the attacker suspects is vulnerable to SQL injection, attempt to inject characters that have special meaning in SQL (such as a single quote character, a double quote character, two hyphens, a parenthesis, etc.). The goal is to create a SQL query with an invalid syntax. 3. [Experiment] [Experiment with SQL Injection vulnerabilities] After determining that a given input is vulnerable to SQL Injection, hypothesize what the underlying query looks like. Iteratively try to add logic to the query to extract information from the database, or to modify or delete information in the database. 4. [Exploit] [Exploit SQL Injection vulnerability] After refining and adding various logic to SQL queries, craft and execute the underlying SQL query that will be used to attack the target system. The goal is to reveal, modify, and/or delete database data, using the knowledge obtained in the previous step. This could entail crafting and executing multiple SQL queries if a denial of service attack is the intent.

Prerequisites

• SQL queries used by the application to store, retrieve or modify data. • User-controllable input that is not properly validated by the application as part of SQL queries.

Skills required

• [Low] It is fairly simple for someone with basic SQL knowledge to perform SQL injection, in general. In certain instances, however, specific knowledge of the database employed may be required.

Consequences

• Integrity: Modify Data • Confidentiality: Read Data • Confidentiality, Integrity, Availability: Execute Unauthorized Commands • Confidentiality, Access Control, Authorization: Gain Privileges

Mitigations

• Strong input validation - All user-controllable input must be validated and filtered for illegal characters as well as SQL content. Keywords such as UNION, SELECT or INSERT must be filtered in addition to characters such as a single-quote(') or SQL-comments (--) based on the context in which they appear. • Use of parameterized queries or stored procedures - Parameterization causes the input to be restricted to certain domains, such as strings or integers, and any input outside such domains is considered invalid and the query fails. Note that SQL Injection is possible even in the presence of stored procedures if the eventual query is constructed dynamically. • Use of custom error pages - Attackers can glean information about the nature of queries from descriptive error messages. Input validation must be coupled with customized error pages that inform about an error without disclosing information about the database or application.

Related

Child of · CAPEC (1)

Weakness · CWE (2)

  • CWE-1286 Improper Validation of Syntactic Correctness of Input weakness
  • CWE-89 Improper Neutralization of Special Elements used in an SQL Command weakness

Referenced by CAPEC · child of (5)

  • CAPEC-108 Command Line Execution through SQL Injection attack pattern
  • CAPEC-109 Object Relational Mapping Injection attack pattern
  • CAPEC-110 SQL Injection through SOAP Parameter Tampering attack pattern
  • CAPEC-470 Expanding Control over the Operating System from the Database attack pattern
  • CAPEC-7 Blind SQL Injection attack pattern

Referenced by CWE · attack pattern (2)

  • CWE-1286 Improper Validation of Syntactic Correctness of Input weakness
  • CWE-89 Improper Neutralization of Special Elements used in an SQL Command weakness