注入攻擊
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 框架中使用的版本