首页 新闻 赞助 找找看

asp.net怎么调用C#代码防止Sql注入???

0
悬赏园豆:20 [已关闭问题] 关闭于 2010-06-05 14:42

asp.net怎么调用C#代码防止Sql注入???

淘宝名店街-.NET交流的主页 淘宝名店街-.NET交流 | 初学一级 | 园豆:90
提问于:2010-05-30 15:05
< >
分享
所有回答(3)
0
//public static void sqlJ()
   // {
   //     string flashack_In, flashack_db, flashack_dbstr, types;
   //     int flashack_Xh;
   //     string[] flashack_Inf;
   //     flashack_In = "'※;※and※exec※insert※select※delete※update※count※*※%※chr※mid※master※truncate※char※declare";
   //     flashack_Inf = flashack_In.Split('※');
   //     if (Request.Form != null)
   //     {
   //         foreach (string flashack_Post in Request.Form)
   //         {
   //             for (flashack_Xh = 0; flashack_Xh <= flashack_Inf.GetUpperBound(0); flashack_Xh++)
   //             {
   //                 if (Request.Form[flashack_Post].ToLower().Contains(flashack_Inf[flashack_Xh]))
   //                 {
   //                     Response.Write("<script language='javascript'>alert('系统提示你:请不要在参数中包含非法字符尝试注入');</script>");
   //                     Response.Write("<script language='javascript'>window.history.go(-1);</script>");
   //                     Response.End();
   //                 }
   //             }
   //         }
   //     }
   //     if (Request.QueryString != null)
   //     {
   //         foreach (string flashack_Get in Request.QueryString)
   //         {
   //             for (flashack_Xh = 0; flashack_Xh <= flashack_Inf.GetUpperBound(0); flashack_Xh++)
   //             {
   //                 if (Request.QueryString[flashack_Get].ToLower().Contains(flashack_Inf[flashack_Xh]))
   //                 {
   //                     Response.Write("<script language='javascript'>alert('系统提示你:请不要在参数中包含非法字符尝试注入');</script>");
   //                     Response.Write("<script language='javascript'>window.history.go(-1);</script>");
   //                     Response.End();
   //                 }
   //             }
   //         }
   //     }
   // }

//public static void sqlJ()   // {   //     string flashack_In, flashack_db, flashack_dbstr, types;   //     int flashack_Xh;   //     string[] flashack_Inf;   //     flashack_In = "'※;※and※exec※insert※select※delete※update※count※*※%※chr※mid※master※truncate※char※declare";   //     flashack_Inf = flashack_In.Split('※');   //     if (Request.Form != null)   //     {   //         foreach (string flashack_Post in Request.Form)   //         {   //             for (flashack_Xh = 0; flashack_Xh <= flashack_Inf.GetUpperBound(0); flashack_Xh++)   //             {   //                 if (Request.Form[flashack_Post].ToLower().Contains(flashack_Inf[flashack_Xh]))   //                 {   //                     Response.Write("<script language='javascript'>alert('系统提示你:请不要在参数中包含非法字符尝试注入');</script>");   //                     Response.Write("<script language='javascript'>window.history.go(-1);</script>");   //                     Response.End();   //                 }   //             }   //         }   //     }   //     if (Request.QueryString != null)   //     {   //         foreach (string flashack_Get in Request.QueryString)   //         {   //             for (flashack_Xh = 0; flashack_Xh <= flashack_Inf.GetUpperBound(0); flashack_Xh++)   //             {   //                 if (Request.QueryString[flashack_Get].ToLower().Contains(flashack_Inf[flashack_Xh]))   //                 {   //                     Response.Write("<script language='javascript'>alert('系统提示你:请不要在参数中包含非法字符尝试注入');</script>");   //                     Response.Write("<script language='javascript'>window.history.go(-1);</script>");   //                     Response.End();   //                 }   //             }   //         }   //     }   // }

林雨.... | 园豆:116 (初学一级) | 2010-05-30 15:09
0

一般来说老生常谈的问题就是使用存储过程或者参数化来解决sql语句的注入,不过如果说一定要从代码层次入手的话,个人觉得一般可以这样子来处理,方法一:当然是参数化和存储过程的使用了。

方法二:判断传入的参数,比如有login.aspx?user=dudu&password=dudu这样子的参数需要传入到服务器端进行使用,那么个人觉得你可以检查获取到的user和password这两个参数,看接收到的参数中是否含有特殊字符,比如你限定注册的用户名不可以有*&#@=等类似这样子的字符,那就可以检查输入的值是否有这些字符,如果有就不允许用户注册登录等...也就是在进行数据库操作前进行对参数处理..

就目前来说,个人觉得类似这样子的方式相对还算有效吧

西越泽 | 园豆:10775 (专家六级) | 2010-05-30 19:11
0

首先你要了解SQL注入的概念和使用,然后在WEB程序中做相应的防范,因为这些工作都是在程序制作中注意的,所以每个阶段的解决方法都不一样。最安全的还是使用“参数化”传递解决,再者就是过滤注入中的安全字符。

这篇文章很精典的:http://www.blueidea.com/tech/program/2004/1810.asp

如果程序已经开发完毕,可以使用MS提供的IIS插件:http://news.cnblogs.com/n/37005/

Astar | 园豆:40805 (高人七级) | 2010-05-30 19:39
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册