SQL injection is an attack in which malicious code is inserted into strings that are later passed to an instance of SQL Server for parsing and execution. Any procedure that constructs SQL statements should be reviewed for injection vulnerabilities because SQL Server will execute all syntactically valid queries that it receives. Even parameterized data can be manipulated by a skilled and determined attacker.
The primary form of SQL injection consists of direct insertion of code into user-input variables that are concatenated with SQL commands and executed. A less direct attack injects malicious code into strings that are destined for storage in a table or as metadata. When the stored strings are subsequently concatenated into a dynamic SQL command, the malicious code is executed.
Example
UserID = Request.form ("userid");
var sql = "select * from UserTable where ID= '" + UserID + "'";
Input character | Meaning in Transact-SQL |
---|---|
; | Query delimiter. |
' | Character data string delimiter. |
-- | Comment delimiter. |
/* ... */ | Comment delimiters. Text between /* and */ is not evaluated by the server. |
xp_ | Used at the start of the name of catalog-extended stored procedures, such as xp_cmdshell. |