防范sql注入式攻擊js版本_Mssql數(shù)據(jù)庫(kù)教程
推薦:怎樣做sql server數(shù)據(jù)庫(kù)的還原以下為引用的內(nèi)容: void restoreButton_Click(object sender, System.EventArgs e) { string path = pathTextBox.Text; string dbname
SQL注入式攻擊是利用是指利用設(shè)計(jì)上的漏洞,在目標(biāo)服務(wù)器上運(yùn)行Sql命令以及進(jìn)行其他方式的攻擊 。
動(dòng)態(tài)生成Sql命令時(shí)沒(méi)有對(duì)用戶(hù)輸入的數(shù)據(jù)進(jìn)行驗(yàn)證是Sql注入攻擊得逞的主要原因。
比如:
如果你的查詢(xún)語(yǔ)句是select * from admin where username=''"&user&"'' and password=''"&pwd&"''" 那么,如果我的用戶(hù)名是:1'' or ''1''=''1
那么,你的查詢(xún)語(yǔ)句將會(huì)變成:
select * from admin where username=''1 or ''1''=''1'' and password=''"&pwd&"''"
這樣你的查詢(xún)語(yǔ)句就通過(guò)了,從而就可以進(jìn)入你的管理界面。
所以防范的時(shí)候需要對(duì)用戶(hù)的輸入進(jìn)行檢查。特別式一些特殊字符,比如單引號(hào),雙引號(hào),分號(hào),逗號(hào),冒號(hào),連接號(hào)等進(jìn)行轉(zhuǎn)換或者過(guò)濾。
需要過(guò)濾的特殊字符及字符串有:
以下為引用的內(nèi)容: net user |
下面是我寫(xiě)的兩種關(guān)于解決注入式攻擊的防范代碼,供大家學(xué)習(xí)參考!
js版的防范SQL注入式攻擊代碼:
以下為引用的內(nèi)容: <script language="****"> |
asp版的防范SQL注入式攻擊代碼~:
以下為引用的內(nèi)容: <% On Error Resume Next Dim strTemp If LCase(Request.ServerVariables("HTTPS")) = "off" Then strTemp = strTemp & Request.ServerVariables("SERVER_NAME") strTemp = strTemp & Request.ServerVariables("URL") If Trim(Request.QueryString) <> "" Then strTemp = strTemp & "?" & Trim(Request.QueryString) strTemp = LCase(strTemp) If Instr(strTemp,"select ") or Instr(strTemp,"insert ") or Instr(strTemp,"delete from") or Instr(strTemp,"count(") or Instr(strTemp,"drop table") or Instr(strTemp,"update ") or Instr(strTemp,"truncate ") or Instr(strTemp,"asc(") or Instr(strTemp,"mid(") or Instr(strTemp,"char(") or Instr(strTemp,"xp_cmdshell") or Instr(strTemp,"exec master") or Instr(strTemp,"net localgroup administrators") or Instr(strTemp,":") or Instr(strTemp,"net user") or Instr(strTemp,"''") or Instr(strTemp," or ") then |
以下是較為簡(jiǎn)單的防范方法,這些都是大家比較熟悉的方法,希望能給你一點(diǎn)幫助~
主要是針對(duì)數(shù)字型的變量傳遞:
id = Request.QueryString("id")
If Not(isNumeric(id)) Then
Response.Write "非法地址~"
Response.End
End If