儲存過程的注入及解決

2021-12-29 20:21:46 字數 1591 閱讀 4868

由於儲存過程中存在用於字串連線的 + 號連線sql語句,這就造成sql注入的可能性.

下面乙個例子:

pr_usermanage_users_batchmove

create procedure [dbo].[pr_usermanage_users_batchmove]

( @usertype int = 1,

@groupid nvarchar(500) =」,

@userid nvarchar(4000) = 」,

@username nvarchar(255) = 」,

@startuserid int = 0,

@enduserid int = 0,

@batchusergroupid nvarchar(500) =」

) as

begin

set nocount off

if (@usertype = 1)

begin

exec(』update pe_users set groupid= 『 + @groupid +』 where userid in (』 + @userid + 『)』)

end

else if(@usertype = 2)

begin

exec(』update pe_users set groupid= 『 + @groupid +』 where username in (」』 + @username + 」』))

end

else if(@usertype = 3)

begin

exec(』update pe_users set groupid= 『 + @groupid +』 where userid between 『 + @startuserid + 『 and 『 + @enduserid)

end

else if(@usertype = 4)

begin

exec(』update pe_users set groupid= 『 + @groupid +』 where groupid in (』 + @batchusergroupid + 『)』)

end

end 

可以看出,在使用者名稱的地方,沒有過濾直接放入查詢.

呼叫地方:

public bool movebyusername(string username, int groupid)

利用過程: 

使用者管理,批量移動

指定使用者名稱 這裡加入sql注入語句

「/」應用程式中的伺服器錯誤。

字串 jax) 後的引號不完整。

jax) 附近有語法錯誤。

說明: 執行當前 web 請求期間,出現未處理的異常。請檢查堆疊跟蹤資訊,以了解有關該錯誤以及**中導致錯誤的出處的詳細資訊。

異常詳細資訊: system.data.sqlclient.sqlexception: 字串 jax) 後的引號不完整。

jannock) 附近有語法錯誤。

解決方案:

由於呼叫時不注意,可能造成危險,所以類似於這類的儲存過程,應寫在程式外面,便於過濾和發現,不要寫在儲存過程中。

儲存過程分頁的注入問題以及解決

最近發現,很久以前的乙個 專案中的查詢竟然會注入sql,原來是使用的通用的儲存過程分頁,裡面有個引數是 wherestr,這個引數是在拼接sql,所以會造成注入,這個真是蛋疼的問題。很多人沒發現這個問題,所以在這裡說一說,也希望找到完美的解決方法,首先過濾是不行的,過濾說白了是在改變使用者的意志。所...

儲存過程與注入

動態構建sql,不可sql注入 create procedure dbo membertestselect2 username nvarchar 50 password nvarchar 50 as begin set nocount on declare err int declare sqlst...

防止sql注入的儲存過程

function fn escapecmdshellstring description returns an escaped version of a given string with carets added in front of all the special mand shell sym...