请详细讲解一下怎样的情况下会产生这种漏洞和具体的解决方案

解决方案 »

  1.   

    用用户输入的文本拼Sql文
    具体的解决方案:不要用用户输入的文本拼Sql文
      

  2.   

    比如在用户名或密码的输入框中输入
    d' or '1'='1
    构造where语句是:condition = "where col='"+txtControl.Text+"'";
    查询时就变成 where col ='d' or '1'='1
    这样查询结果就永远为TRUE了.
    解决办法是用查询数据库时使用参数传递值,或将用户输入的值中的特殊字符进行处理后再进行字条串连接.
      

  3.   

    比如说你的登录用的Sql语句是:
    Select Count(*) from [User] where UserName='"+name+"' and Pwd='"+pwd+"'";
    攻击时可以通过输入的用户名来注入Sql元素,比如说:
    name="thf ' or 1=1 --";
    pwd=任意
    这是执行的实际语句是:
    Select Count(*) from [User] where UserName='thf' or 1=1"
    后面的pwd已经被注释掉了
    解决方案:用参数代替拼装字符串
    Select Count(*) from [User] where UserName=@UserName and Pwd=@Pwd;
      

  4.   

    http://msdn2.microsoft.com/en-us/security/bb977435.aspx