超碰人人人人人,亚洲AV午夜福利精品一区二区,亚洲欧美综合区丁香五月1区,日韩欧美亚洲系列

LOGO OA教程 ERP教程 模切知識(shí)交流 PMS教程 CRM教程 開發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

兩個(gè)小函數(shù)讓你的ASP程序?qū)QL注入免疫!

admin
2011年2月16日 1:0 本文熱度 3360

兩個(gè)小函數(shù)讓你的ASP程序?qū)QL注入免疫!


Rem ## 長(zhǎng)整數(shù)轉(zhuǎn)換
Function toNum(s, default)
If IsNumeric(s) and s <> "" then
toNum = CLng(s)
Else
toNum = default
End If
End Function
Rem ## SQL 語(yǔ)句轉(zhuǎn)換
Function toSql(str)
If IsNull(str) Then str = ""
toSql = replace(str, "''", "''''")
End Function
示例:
Dim sql
Dim strWhere, strName, intAge
strName = toSql(request("user"))
intAge = toNum(request("age"), 20)
sql = "SELECT * FROM [USER]" & _
"WHERE [AGE] > " & strName & _
" AND [USERNAME] = ''" & intAge & "''"
一般情況下, 通過上面兩個(gè)函數(shù)的過慮, 可以杜絕網(wǎng)上的SQL注入攻擊!如果你覺得有需要, 可以加上對(duì)chr(0)的替換, 將toSql函數(shù)改為如下:
Function toSql(str)
If IsNull(str) Then str = ""
str = replace(str, chr(0), "")
toSql = replace(str, "''", "''''")
End Function
另注:
***********************************************************************
檢測(cè)外部提交的函數(shù)
Function CheckUrlRefer()
Dim strLocalUrl, intUrlLen, strUrlRefer
strLocalUrl = "intUrlLen = Len(strLocalUrl)
strUrlRefer = LCase(request.ServerVariables("HTTP_REFERER") & "")
''檢測(cè)前一個(gè)頁(yè)面是否來(lái)自 strLocalUrl
If Left(strUrlRefer, intUrlLen) = strLocalUrl Then
CheckUrlRefer = True
Else
CheckUrlRefer = False
End If
End Function
***********************************************************************
該函數(shù)可以幫助你抵擋外部的SQL注入測(cè)試, 只需要在頁(yè)面的頭部調(diào)用即可.
通過簡(jiǎn)單的兩個(gè)小函數(shù), 讓你的ASP程序更安全!
歡迎高手指正(請(qǐng)將繞過這兩個(gè)函數(shù)的方法寫出來(lái))!
相關(guān)討論頁(yè)面:
http://community.csdn.net/Expert/TopicView.asp?id=3585010
http://community.csdn.net/Expert/TopicView.asp?id=3582230
http://community.csdn.net/Expert/topic/3589/3589480.xml?temp=.4866449
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
dim qs,errc,iii
qs=request.servervariables("query_string")
dim nothis(18)
nothis(0)="net user"
nothis(1)="xp_cmdshell"
nothis(2)="/add"
nothis(3)="exec%20master.dbo.xp_cmdshell"
nothis(4)="net localgroup administrators"
nothis(5)="select"
nothis(6)="count"
nothis(7)="asc"
nothis(8)="char"
nothis(9)="mid"
nothis(10)="''"
nothis(11)=":"
nothis(12)=""""
nothis(13)="insert"
nothis(14)="delete"
nothis(15)="drop"
nothis(16)="truncate"
nothis(17)="from"
nothis(18)="%"
errc=false
for iii= 0 to ubound(nothis)
if instr(qs,nothis(iii))<>0 then
errc=true
end if
next
if errc then
Response.Write("對(duì)不起,非法URL地址請(qǐng)求!")
response.end
end if
***************************************************************
當(dāng)然這方法做得太“絕”了,但是我也是沒有辦法啊。這個(gè)方法是在網(wǎng)上看到的,運(yùn)行于一個(gè)網(wǎng)站上,現(xiàn)在一切良好。為了安全我只能這樣。我想只要有關(guān)SQL的敏感單詞都進(jìn)行過濾掉應(yīng)該沒有什么吧,當(dāng)然像樓主的做到那一步是基本上可以了,可以修補(bǔ)一下用用。記得我最初用的是《SQL注入天書》上面提供的防范方法,后來(lái)才改用這個(gè)。
將我以前用的代碼也帖出來(lái)供參考,大家有興趣可以去百度或GOOGLE中搜索一下《SQL注入天書》了解
使用這個(gè)函數(shù),對(duì)客戶端提交來(lái)的數(shù)據(jù)進(jìn)行驗(yàn)證。。。
<%
Function SafeRequest(ParaName,ParaType)
''--- 傳入?yún)?shù) ---
''ParaName:參數(shù)名稱-字符型
''ParaType:參數(shù)類型-數(shù)字型(1表示以上參數(shù)是數(shù)字,0表示以上參數(shù)為字符)
Dim ParaValue
ParaValue=Request(ParaName)
If ParaType=1 then
If not isNumeric(ParaValue) then
Response.write "參數(shù)" & ParaName & "必須為數(shù)字型!"
Response.end
End if
Else
ParaValue=replace(ParaValue,"''","''''")
End if
SafeRequest=ParaValue
End function%>


該文章在 2011/2/16 1:00:56 編輯過
關(guān)鍵字查詢
相關(guān)文章
正在查詢...
點(diǎn)晴ERP是一款針對(duì)中小制造業(yè)的專業(yè)生產(chǎn)管理軟件系統(tǒng),系統(tǒng)成熟度和易用性得到了國(guó)內(nèi)大量中小企業(yè)的青睞。
點(diǎn)晴PMS碼頭管理系統(tǒng)主要針對(duì)港口碼頭集裝箱與散貨日常運(yùn)作、調(diào)度、堆場(chǎng)、車隊(duì)、財(cái)務(wù)費(fèi)用、相關(guān)報(bào)表等業(yè)務(wù)管理,結(jié)合碼頭的業(yè)務(wù)特點(diǎn),圍繞調(diào)度、堆場(chǎng)作業(yè)而開發(fā)的。集技術(shù)的先進(jìn)性、管理的有效性于一體,是物流碼頭及其他港口類企業(yè)的高效ERP管理信息系統(tǒng)。
點(diǎn)晴WMS倉(cāng)儲(chǔ)管理系統(tǒng)提供了貨物產(chǎn)品管理,銷售管理,采購(gòu)管理,倉(cāng)儲(chǔ)管理,倉(cāng)庫(kù)管理,保質(zhì)期管理,貨位管理,庫(kù)位管理,生產(chǎn)管理,WMS管理系統(tǒng),標(biāo)簽打印,條形碼,二維碼管理,批號(hào)管理軟件。
點(diǎn)晴免費(fèi)OA是一款軟件和通用服務(wù)都免費(fèi),不限功能、不限時(shí)間、不限用戶的免費(fèi)OA協(xié)同辦公管理系統(tǒng)。
Copyright 2010-2025 ClickSun All Rights Reserved