除了调用存储过程,还有什么方法可以防止sql注入呢?程序里面如果有一两个地方没有用到存储过程,而是一直在类里面写sql语句,这样对程序的影响是不是很大呢?
各位大侠们,可以系统一点的说明吗?
各位大侠们,可以系统一点的说明吗?
解决方案 »
- JS页面刷新问题,谢谢关注
- this.GridView1.EditIndex = e.NewEditIndex;出来的结果是空白,
- SqlDbType.Decimal 问题
- DetailsView插入状态下两个DropdownList联动的问题.
- 如何实现net网络爬虫 或者网络抓取呢
- 求 .NET 2.0中TreeView 与数据库中数据绑定显示的例子
- 超难问题,高手请进!在线等待
- 数据实体层、数据访问层、业务逻辑层、业务实现层和web表现层?
- 如何让DataList显示在一个固定大小的窗口中?
- 各位,为什么Container的属性DataItem我点不出来啊?附上代码!
- OpenFlashChart2如何保存图片啊
- VS 2008 水晶报表打印慢的问题
public static bool AddNewProductImage(string sProductID, ArrayList alImages)
{
Util.DynamicQueryBuilder q = new Util.DynamicQueryBuilder();
q.AddQueryLine("INSERT INTO productimage (productid, imagefile, whratio) SELECT ");
bool fClause = false;
for (int i = 0; i < alImages.Count; i++)
{
Class.ProductImage image = (Class.ProductImage)alImages[i];
if (fClause)
{
q.AddQueryLine(" UNION ALL SELECT ");
}
Util.BuildInsertParameters(q, sProductID, false, false);
Util.BuildInsertParameters(q, image.sImageFile, true, true);
Util.BuildInsertParameters(q, image.sWhratio, false, true); fClause = true;
} DataConnection conn = new DataConnection();
return conn.ExecuteNonQuery(q.GetQueryText, q.GetParameters);
}
如果这样做的话,会有什么后果呢?可以防止sql注入吗?
好像.net运行时会自动把单引号替换掉
一般都考虑用这个,
虽然不能100%,但是效果还不错.
1、判断属性,如果是从?a=xxx直接进来,就判断xxx是不是整数,或者判断xxx的字符长度,超过就截取Left2、过滤非法字符(% 括弧等)Replace3、再严格点,就是过滤(drop, delete, select, exec等保留字节)
存储过程并不一定能防止SQL注入,有些存储过程中用exec(SQL语句)这类写法,就没办法防止啦,
主要一点是把数据参数化。,没办法参数化的用过滤,
public static bool AddNewUser(Model.Admin ad)
{
SqlParameter[] parm = new SqlParameter[]
{
new SqlParameter(PARM_SUSERNAME,SqlDbType.VarChar,20),
new SqlParameter(PARM_SPASSWORD,SqlDbType.VarChar,20),
new SqlParameter(PARM_SREGDATE,SqlDbType.DateTime)
}; parm[0].Value = ad.Username;
parm[1].Value = ad.Password;
parm[2].Value = ad.Regdate;
Object i = SqlHelper.ExecuteScalar(SqlHelper.ConnectionStringLocalTransaction,
CommandType.StoredProcedure, PROC_ADDNEWUSER, parm);
if (i != null)
{
return true;
}
else
{
return false;
}
}
如果是使用这种数据参数化,那么可以防止sql注入了吗?
或者滤掉 <> '' 等敏感字符
但是还是被注入了 js注入
真不知道要怎么解决了? 各位大侠,谁能够提供一下 这到底要怎么解决呀?