提问人:TheIronKnuckle 提问时间:10/10/2018 最后编辑:marc_sTheIronKnuckle 更新时间:10/10/2018 访问量:1113
防止通过存储过程的“quotename”进行 SQL 注入
Prevent SQL injection via "quotename" with stored procedure
问:
我正在尝试制作一些代码“sql-injection-proof”。有人建议我使用 .QUOTENAME
这工作原理:
select 'abc[]def'
它给出了与以下
select QUOTENAME('abc[]def')
但是,虽然以下工作有效:
exec sp_spaceused 'STMALOGqueue'
这不会:
exec sp_spaceused QUOTENAME('STMALOGqueue')
我收到一个烦人的错误:
Incorrect syntax near 'STMALOGqueue'
我试图通过注入证明的实际代码是在某些 C# 中硬编码的。供参考:
string sp_spaceused = @"
drop table if exists #temp
create table #temp(name nvarchar(100), rows int, reserved nvarchar(100), data nvarchar(100), index_size nvarchar(100), unused nvarchar(100))
insert into #temp
exec sp_spaceused QUOTENAME('{0}')";
我用来将相关的表名插入到这个字符串中,然后执行它。目前它不起作用String.format
答:
2赞
mohabbati
10/10/2018
#1
将结果存储到变量中,并将其用于存储过程参数:QUOTENAME('STMALOGqueue')
declare @test as varchar(100)
set @test = QUOTENAME('STMALOGqueue')
exec sp_spaceused @test
它有效。
评论