mySql 注入攻击

时间:2023-03-09 16:34:29
mySql 注入攻击

注入攻击

  1.原理:

      a.只要是带有参数的动态网页且此网页访问了数据库,那么就有可能存在SQL注入;

      b.字符串拼接和没有判断用户输入是否合法------>导致用户可以玩填字游戏----->SQL注入攻击会导致的数据库安全风险包括:刷库、拖库、撞库。

  2.简单解决方法:

      预防字符串拼接---->可以使用变量绑定避免注入攻击.

        以查询语句为例:

      正确输入名称与密码   

            name = "hello"  password = "wangergou"

            "select price from houses where name = %s and paswd = %s"%(name,password)

      非法输入名称与密码

            name = "'' a' or 1=1 or ('1'='1' "  password = " 'abc') or '1'='1' "

            "select price from houses where name = %s and paswd = %s"%(name,password)

            "select price from houses where name =' a' or 1=1 or ('1'='1' and paswd = 'abc') or '1'='1'

      解决方式:  "select price from houses where name = %s and paswd = %s",name,password    ----->Tornado 框架中使用的版本