防範SQL注入攻擊的代碼_PHP教程

來源:互聯網
上載者:User
SQL注入式攻擊是利用是指利用設計上的漏洞,在目標伺服器上運行Sql命令以及進行其他方式的攻擊,動態產生Sql命令時沒有對使用者輸入的資料進行驗證是Sql注入攻擊得逞的主要原因。比如:
  如果你的查詢語句是select * from admin where username=‘"&user&"‘ and password=‘"&pwd&"‘"
  那麼,如果我的使用者名稱是:1‘ or ‘1‘=‘1
  那麼,你的查詢語句將會變成:
select * from admin where username=‘1 or ‘1‘=‘1‘ and password=‘"&pwd&"‘"
  這樣你的查詢語句就通過了,從而就可以進入你的管理介面。
  所以防範的時候需要對使用者的輸入進行檢查。特別式一些特殊字元,比如單引號,雙引號,分號,逗號,冒號,串連號等進行轉換或者過濾。
  需要過濾的特殊字元及字串有:
net user
xp_cmdshell
/add
exec master.dbo.xp_cmdshell
net localgroup administrators
select
count
Asc
char
mid

:
"
insert
delete from
drop table
update
truncate
from
%
  下面是我寫的兩種關於解決注入式攻擊的防範代碼,供大家學習參考!
  js版的防範SQL注入式攻擊代碼~:
[CODE START]  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.