安全防護,如何做到安全防護?想要防護就要知道對方是如何進行攻擊。有很多文章都在寫如何攻下某站點,其實其攻擊的途徑也不過是以下幾種:
1. 簡單的腳本攻擊
此類攻擊應該屬于無聊搗亂吧。比如javascript :alert(); </table>等等,由于程序上過濾的不嚴密,使攻擊者既得不到什么可用的,但又使的他可以進行搗亂的目的。以目前很多站點的免費服務,或者是自身站點的程序上也是有過濾不嚴密的問題。
2. 危險的腳本攻擊
這類腳本攻擊已經過度到可以竊取管理員或者是其他用戶信息的程度上了。比如大家都知道的cookies竊取,利用腳本對客戶端進行本地的寫操作等等。
3. Sql Injection 漏洞攻擊
可以說,這個攻擊方式是從動網論壇和BBSXP開始的。利用SQL特殊字符過濾的不嚴密,而對數據庫進行跨表查詢的攻擊。比如:
http://127.0.0.1/forum/showuser.asp?id=999 and 1=1
http://127.0.0.1/forum/showuser.asp?id=999 and 1=2
http://127.0.0.1/forum/showuser.asp?id=999 and 0<>(select count(*) from admin)
<%
function CHK(fqyString)
fqyString = replace(fqyString, `>`, `>`)
fqyString = replace(fqyString, `<`, `<`)
fqyString = replace(fqyString, `&#`, `&`)
fqyString = Replace(fqyString, CHR(32), ` `)
fqyString = Replace(fqyString, CHR(9), ` `)
fqyString = Replace(fqyString, CHR(34), ```)
fqyString = Replace(fqyString, CHR(39), ``)
fqyString = Replace(fqyString, CHR(13), ``)
fqyString = Replace(fqyString, CHR(10) & CHR(10), `</P><P> `)
fqyString = Replace(fqyString, CHR(10), `<BR> `)
CHK = fqyString
end function
%>
`以下是應用實例
<%=CHK(Username)%>
Username=CHK(replace(request(“username”),”`”,””))
使用Include把函數寫在公有頁面上,這樣效率是最好的。
程序體(1)
另外,值得我們注意的是,很多站點在用戶注冊,或者是用戶資料修改的頁面上也缺少腳本的過濾,或者是只在其中之一進行過濾,注冊進入后修改資料仍然可以進行腳本攻擊。對用戶提交的數據進行檢測和過濾,程序體(2) 如下:
`以下是過濾函數
If Instr(request(`username`),`=`)>0 or
Instr(request(`username`),`%`)>0 or
Instr(request(`username`),chr(32))>0 or
Instr(request(`username`),`?`)>0 or
Instr(request(`username`),`&`)>0 or
Instr(request(`username`),`;`)>0 or
Instr(request(`username`),`,`)>0 or
Instr(request(`username`),``)>0 or
Instr(request(`username`),`?`)>0 or
Instr(request(`username`),chr(34))>0 or
Instr(request(`username`),chr(9))>0 or
Instr(request(`username`),`?`)>0 or
Instr(request(`username`),`$`)>0 or
Instr(request(`username`),`>`)>0 or
Instr(request(`username`),`<`)>0 or
Instr(request(`username`),````)>0 then
response.write `朋友,你的提交用戶名含有非法字符,請更改,謝謝合作?。糰 href=javascript :window.history.go(-1);>返回</a>`
response.end
end if
程序體(2)
為了提供工作效率我們再將過濾內容程序化,這樣對多個參數的過濾效率將有很大程度上的提高:如 程序體(3)
`以下為程序主體
dim Bword(18)
Bword(0)=`?`
Bword(1)=`;`
Bword(2)=`>`
Bword(3)=`<`
Bword(4)=`-`
Bword(5)=```
Bword(6)=`””`
Bword(7)=`&`
Bword(8)=`%`
Bword(9)=`$`
Bword(10)=``
Bword(11)=`:`
Bword(12)=`|`
Bword(13)=`(`
Bword(14)=`)`
Bword(15)=`--`
Bword(16)=` chr(9)`
Bword(17)=` chr(34)`
Bword(18)=` chr(32)`
errc=false
`以下是應用實例部分
for i= 0 to ubound(Bword)
if instr(FQYs,Bword(i))<>0 then
errc=true
end if
next
if errc then
response.write `<script language=``javascript``>`
response.write `parent.alert(很抱歉!您的操作違法了);`
response.write `history,back();`
response.write `</script>`
response.end
end if
[1]