牛腩新闻视频 09讲 Sql注入 cmd 的 Parameter.ADD 单个参数 和 Parameters.AddRange 多个参数

image

看看 增加后显示的文字

image

那么为什么会这样呢?我们把上面的文字 放到 sql里面去看看

image

实际上 替换掉的是  逗号之间的内容,替换后,原来的插入是一个语句,后面的删除又是另外一个语句,并且 -- 后面  被当做注释已经忽略了

举例两个比较经典的注入案例

1:管理员登陆    

select * from admin where username='admin' and [password]='admin'

假如在密码区  我输入   注入' or  '1' = '1      (前面有一个 '   后面的1  没有  '   就变成了如下)

select * from admin where username='admin' and [password]='注入' or '1'='1'

2:恶意删除

select * from category where name='中国新闻'
select * from category where name=''
--假如我要注入的是 asp';delete from category;--
select * from category where name='asp';delete from category;--'

如何避免 拼接字符串呢?我们使用 带参数的 SQL语句

当我们修改sql 2008数据库的表结构时  提示

image

image  image

回到刚才的   带参数的  sql 语句     SqlParameter

image

 
修改之后
image 

然后 回到 CategoryDAO 里面  需要使用  sqlparameter 需要引入  

using System.Data.SqlClient;
image 
原文地址:https://www.cnblogs.com/iceicebaby/p/2200177.html