Stored Procedure Injection

Source: Internet
Author: User

From:

Http://www.siteweavercms.cn/Item/113.aspx

Because the stored procedure has a + number connection SQL statement for string connection, this causes the possibility of SQL injection.
The following is an example:

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

It can be seen that the user name is directly put into the query without filtering.

Call place:

 Public  bool    movebyusername   ( string  username,  int  groupid) { parameters   parmsforusers  = new  parameters  (); parmsforusers.  addinparameter  ("@ usertype",  dbtype .  int32 , 2); parmsforusers.  addinparameter  ("@ username",  dbtype .  string , username); parmsforusers.  addinparameter  ("@ groupid",  dbtype .  int32 , groupid); Return  dbhelper .  executeproc  ("pr_usermanage_users_batchmove", parmsforusers);} exploitation process: 
 User Management, batch movement 
 specify the user name and add SQL Injection statements here 
"/"Application Server Error in  Program .

            the quotation marks after the string 'jax ') are incomplete. 
There Is A syntax error near 'jax.
Note: An error occurred while executing the current Web request. Check the stack trace information for details about the error and the source of the error in Code .
exception details: the quotation marks after system. Data. sqlclient. sqlexception: String 'jax ')' are incomplete.
'jannock') 'is near a syntax error.

solution:

because you do not pay attention to the call, this may cause danger. Therefore, stored procedures similar to this type should be written outside the program, it is easy to filter and discover, and should not be written in the stored procedure.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.