今晚看了msdn关于SQL注入的介绍,其中有一段不明白麻烦大家帮忙看下:
由数据截断启用的注入
如果分配给变量的任何动态 Transact-SQL 比为该变量分配的缓冲区大,那么它将被截断。如果攻击者能够通过将意外长度的字符串传递给存储过程来强制执行语句截断,则该攻击者可以操作该结果。例如,以下脚本创建的存储过程容易受到由截断启用的注入攻击。
- SQL code
CREATE PROCEDURE sp_MySetPassword @loginname sysname, @old sysname, @new sysname AS -- Declare variable. -- Note that the buffer here is only 200 characters long. DECLARE @command varchar(200) -- Construct the dynamic Transact-SQL. -- In the following statement, we need a total of 154 characters -- to set the password of 'sa'. -- 26 for UPDATE statement, 16 for WHERE clause, 4 for 'sa', and 2 for -- quotation marks surrounded by QUOTENAME(@loginname): -- 200 – 26 – 16 – 4 – 2 = 154. -- But because @new is declared as a sysname, this variable can only hold -- 128 characters. -- We can overcome this by passing some single quotation marks in @new. SET @command= 'update Users set password=' + QUOTENAME(@new, '''') + ' where username=' + QUOTENAME(@loginname, '''') + ' AND password = ' + QUOTENAME(@old, '''') -- Execute the command. EXEC (@command) GO
通过向 128 个字符的缓冲区传递 154 个字符,攻击者便可以在不知道旧密码的情况下为 sa 设置新密码。
EXEC sp_MySetPassword 'sa', 'dummy', '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012'''''''''''''''''''''''''''''''''''''''''''''''''''
因此,应对命令变量使用较大的缓冲区,或直接在 EXECUTE 语句内执行动态 Transact-SQL。
=========================================================================================
输入那么多字符后,会截断,这个大概明白,但是为什么截断了之后就可以设置sa的密码
“直接在 EXECUTE 语句内执行动态 Transact-SQL。”这一句又是什么意思,到底截断之后会发生什么事
------解决方案--------------------
看看这个,可能对你有帮助
http://wenku.baidu.com/view/0b676bd6c1c708a1284a4407.html
=========================================================================================
欢迎访问我的博客