SQL注入攻击及解决方案

更新时间:2023-07-01 23:16:30 阅读: 评论:0

SQL注⼊攻击及解决⽅案
日本研究生⼀, 定义:所谓SQL注⼊攻击是应⽤程序开发⼈员未预期地把SQL代码传⼊到应⽤程序的过程,只有那些直接使⽤⽤户提供的值构造SQL语句的应⽤程序才会受影响.
例如原SQL代码为:
lect Orders.CustomerID,Orders.OrderID,Count(UnitPrice) as Items,SUM(UnitPrice*Quantity) as Total from Orders INNER JOIN [Order Details]on Orders.OrderID=[Order Details].OrderID
where Orders.CustomerID='"+txtId.Text+"' GROUP BY Orders.OrderID,Orders.CustomerID
解决⽅案:采⽤参数化命令:
菜饽饽的做法  如使⽤参数化命令重写前⾯的代码为:
protected void btnQuery_Click(object nder, EventArgs e)
石榴石图片{
string conStr = WebConfigurationManager.ConnectionStrings["Northwind"].ConnectionString;
SqlConnection con = new SqlConnection(conStr);
con.Open();
string strSql = "lect Orders.CustomerID,Orders.OrderID,Count(UnitPrice) as Items,SUM(UnitPrice*Quantity) as Total from Orders INNER JOIN [Order Details]on Orders.OrderID=[Order Details].OrderID where Orders.CustomerID=@Cus            SqlCommand cmd = new SqlCommand(strSql, con);
cmd.Parameters.AddWithValue("@CustomerID", txtId.Text.Trim().ToString());
SqlDataReader reader = cmd.ExecuteReader();
GridView1.DataSource = reader;防控风险
小米路由器管理密码
GridView1.DataBind();
刘亦菲演的电影reader.Clo();
con.Clo();
最恐怖的鬼故事
}
什么大同成语
这样就可以避免SQL注⼊攻击.

本文发布于:2023-07-01 23:16:30,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1063742.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:程序   研究生   攻击   代码   构造   重写   语句
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图