应该使用存储过程,sql命令参数对象,验证控件和MD5加密的多重防范

解决方案 »

  1.   

    用正则应该处理哪些?
    如何处理?Access数据库情形呢?
      

  2.   

    SQL:  在与SQL交互时使用这个函数先处理 replace(str,"'","''")
    Html:  在显示出来前先用这个函食处理 HttpUtility.HtmlEncode(to show str)
           或在web.config中加入<pages validateRequest="true">也行
      

  3.   


    在html方面是不是应该有些允许呢?.而只是防止一些恶意的代码应该是哪些呢
      

  4.   

    正则用来检测用户输入的有效性比如,输入的长度(汉字为2),指定字符范围的输入等等 。至于单引号 什么的,一般不屏蔽,在存储过程中,验证用户输入的时候,检测一下@@rowcount 是不是为1 。我一般都这么写,不知道还没有更好的方法~
      

  5.   

    注入攻击主要是防止用户输入恶意的Sql命令和输入Html代码时输入的恶意脚本。
    主要防范的就是恶意sql命令。
    1 如果后台数据库使用的是Sql Server这样的大型数据库,不要使用在代码中直接使用Sql命令字符串这样的方式操作数据库,应尽量使用存储过程执行。2 操作数据库输入等向数据库输入内容时,尽量使用OleDbParameter或SqlParameter这两个数据库参数对象,利用这个对象来向数据库传输内容。3 如果必须使用代码内硬编码用户输入 + Sql操作命令时,在用户输入的地方防止用户输入恶意代码,必须加上去除符号的验证控件。
    一般我使用RegularExpressionValidator控件控制用户输入,如防止aaa' or '1'='1这样的注入攻击,我设置它的ValidationExpression属性为“[A-Za-z0-9]*”(不包括引号),仅允许输入字母和数字,任何其他符号包括空格都不允许。
      

  6.   

    TomMax(笑望人生) 
    讲得很详细呀,
    学习
      

  7.   

    从asp.net寻的一些Web Security: Input Validation in ASP.NET Applications
    Posted: 01 Mar 2004 09:38 PM 
    Web applications constantly face serious attacks that result from inproper input validation. One popular attack is cross site scripting, which may allow an attacker to hijack another user's session or authentication state. Another is sql injection, which can lead to disclosure or tampering with your backend database. Of course, many others are possible in applications that perform tasks based on client input without proper validation. The series of guidelines below should help you determine an optimal strategy when securing your ASP.NET applications. While the exact validations details depend on what kind of input you expect, the overall guidelines are as follows: 1. Enable ValidateRequest (enabled by default in v1.1). This will detect most dangerous input that contains an XSS attack. 2. Do server validation. Client validation can be easily bypassed, in fact too easily to count on it. You can take advantage of our validator controls: http://www.dotnetjunkies.com/quickstart/aspplus/doc/webvalidation.aspx 3. Only accept legal input (using regular expressions), reject all else. Do no attempt to scan the input for invalid content. 4. If you cannot restrict legal input (such as you can social security numbers) and must accept more or less free form input (such as forums posts), sanitize it by removing dangerous characters/content you are aware of. Do not use this instead of 3 where possible. 5. If you must display input from the user, or data derived from it, HtmlEncode it. You can use HttpServerUtility.HtmlEncode(). 6. If you use the input to drive database queries, use stored procedures with db parameters, or sql queries with db parameters if you cant use stored procedures. Never build the sql query as a string. See ADO.NET documentation for more info on using parameters, for example: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtsksettinggettingdatacommandparameters.asp 
    Check out the security architecture guide for more information: http://msdn.microsoft.com/library/en-us/dnnetsec/html/THCMCh10.asp?frame=true#c10618429_006  
      

  8.   

    TomMax(笑望人生) :如果只允许字母和数字的话………………恐怕只能做用户名那吧?呵呵~~~别的地方这样的话,限制太大了,是不是?
      

  9.   

    to TomMax(笑望人生) :
      一般我使用RegularExpressionValidator控件控制用户输入,如防止aaa' or '1'='1这样的注入攻击,我设置它的ValidationExpression属性为“[A-Za-z0-9]*”(不包括引号),仅允许输入字母和数字,任何其他符号包括空格都不允许。
    --------------------------------------------------------------------------------- 
    我是这么想的,你可以判断 他的返回行数是不是=1,
      

  10.   

    必须要解码.编码?.将用户的输入进行转换(将>替换为&gt;)?请大家先确定这一条是不是一定要做?
    考虑上不能使用存储过程参数的Access情形
      

  11.   

    html是否过滤那看自己是否需要,主要是SQL危害字符吧?
      

  12.   

    to  xinshaw
    但是access情形呢
      

  13.   

    就直接这么说吧如果用户在前台一个aspx页面文本框(txtIntro)中输入了<marquee><font size=1>密'密'麻麻</font></marquee>在插入access数据库之前
    你会如何处理
      

  14.   

    Access里有视图,可以用它达到和存储过程一样的效果
      

  15.   

    public string CheckString(string v)
    {
    v = v.Replace("<", "&lt;");
    v = v.Replace(">", "&gt;");
    v = v.Replace("'", "''");
    v = v.Replace(" ", "&nbsp;");
    v = v.Replace("\n", "<br>");
    v = v.Replace("\r\n", "<br>");
    v = v.Trim();
    return v;
    }在textbox 中限制长度..这样一般的就可以了..
      

  16.   

    * SQL Injection FAQ (http://www.sqlsecurity.com/) * Advanced SQL Injection White Paper (http://www.nextgenss.com/research.html) * Preventing SQL Injection (http://www.owasp.org/asac/input_validation/sql.shtml)
      

  17.   

    html, 存的时候不过滤,输出的时候过滤
    sql,用参数,就不会有问题,否则用户告诉你我就要用这个名字或密码,你怎么办
      

  18.   

    推荐大家看一本书,ASP.NET安全性高级编程,清华大学出的,看完了,什么都明白了