我通过程序插入数据,但仍有一些身体做SQL注入,为什么会发生? [英] I am inserting data via procedure but Still Some Body Do SQL Injection,Why it is happening?

查看:97
本文介绍了我通过程序插入数据,但仍有一些身体做SQL注入,为什么会发生?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的ms Sql server 2008中的程序

创建程序spp_add_student



@Id nvarchar(50),
@Name nvarchar(100),

@Roll nvarchar(500)



as

开始

插入tbl_add_student(Id,Name,Roll)值(@ Id,@ Name,@ Roll)

结束

和我通过c#中的dataaccess层发送参数值,

我读了很多论坛但这个参数化过程是标准的方式然后他们如何在我的应用程序中进行sql注入,

请帮助我

解决方案

但是,存储过程本身并不一定能防止SQL注入。存储过程作为保护措施的用处与存储过程的编写方式有关。



由您完成,

  insert   into  tbl_add_student(Id,Name,Roll) @ Id  @ Name  @ Roll 



如果有人指定值

引用:
100);删除TABLE tbl_add_student;



然后它将被执行为

  insert   into  tbl_add_student(Id,Name,Roll) values  @Id  @ Name  100 ); 
Drop TABLE tbl_add_student;





导致Add_Student表的删除。



您可以进一步查看这两个链接...



(I)存储过程是否可以防止SQL注入? - Brian Swan - 网站首页 - MSDN博客 [ ^ ]

(II)如何防止存储过程中的SQL注入 [ ^ ]


1 。你确定他们在做SQL注入吗?你怎么知道的?首先验证。

2.使用cmd.Parameters.AddWithValue(@ parm1,parm1Value);在C#中添加参数时。这可以保护大多数sql注入问题。


Here is my procedure in ms Sql server 2008
create procedure spp_add_student
(
@Id nvarchar(50),
@Name nvarchar(100),
@Roll nvarchar(500)
)
as
begin
insert into tbl_add_student(Id,Name,Roll) values(@Id,@Name,@Roll)
end
and i am sending the parameters value via dataaccess layer in c#,
I read many forums but This parameterized process is the standard way then how they are doing sql injection in my application,
Please Help Me

解决方案

But, stored procedures do not, by themselves, necessarily protect against SQL injection. The usefulness of a stored procedure as a protective measure has everything to do with how the stored procedure is written.

As done by you,

insert into tbl_add_student(Id,Name,Roll) values(@Id,@Name,@Roll)


If someone assign value

Quote:

100); Drop TABLE tbl_add_student;


then it will be executed as

insert into tbl_add_student(Id,Name,Roll) values(@Id,@Name,100);
Drop TABLE tbl_add_student;



Resulting in dropping of Add_Student table.

You can check out these two links further...

(I)Do Stored Procedures Protect Against SQL Injection? - Brian Swan - Site Home - MSDN Blogs[^]
(II)How to prevent SQL Injection in Stored Procedures[^]


1. Are you sure they are doing SQL injection? How do you know? Verify that first.
2. Use cmd.Parameters.AddWithValue("@parm1", parm1Value); when adding your parameters in C#. That protects most of sql injection issues.


这篇关于我通过程序插入数据,但仍有一些身体做SQL注入,为什么会发生?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆