防止注入-转义原始SQL

时间:2019-02-28 10:47:37

标签: sql-server sql-injection

我有一个应用程序(Crystal Reports),可以将用户参数直接插入正在运行的查询中。

我需要运行的查询的性质意味着我无法更改此行为。

我发现这允许用户通过报告运行他们喜欢的任何SQL命令。

例如,我的SQL查询类似于:

declare @text varchar(100)
set @text = '{users parameter}'

select *
from blah
where blah.field = @text
-- rest of query

因此,如果用户将参数设置为'; select * from blah; --,它将运行此查询。

我已经通过一个非常有限的用户运行该命令,但仍然希望尝试阻止注入。

是否有任何方法可以防止或至少通过我正在运行的查询减轻它们?

类似的东西:

declare @text varchar(100)
set @text = NeverEscape('{users parameter}')

select *
from blah
where blah.field = @text
-- rest of query

修改

为阐明漏洞的存在,应用程序将单个文本查询传递给服务器,在我给出的示例中,以下查询将传递给服务器:

declare @text varchar(100)
set @text = ''; select * from blah; --'

select *
from blah
where blah.field = @text
-- rest of query

0 个答案:

没有答案
相关问题