作者:孤劍
時間:2006-9-27
<%
class security
Private p_InvaildWords
Private p_hError,p_Hex,p_errDetails
Private p_msg
Private P_ipAdd
Private Sub Class_Initialize
p_hError=&H00000000
p_msg=""
p_Hex=TRUE
p_errDetails=false
p_InvaildWords="from|select|update|delete|insert|--|;|'|#|%|xp|cmd|shell|drop|create"
End Sub
rem **********************************************************************
rem 系統屬性定義區域
version="Security 2.0.1.24"
end property
rem ----------------------------------------------------------------------
public property let Filter(words)
if(lcase(left(trim(words),7))="default") then
p_InvaildWords =p_InvaildWords & right(trim(words),len(trim(words))-7)
else
p_InvaildWords=words
end if
'**********************************
' 獲得此過程中産生的錯誤資訊
'----------------------------------
Public property let HexError(hnum) '2006-9-18 添加編碼屬性
if(isnumeric(hnum)) then
if(cint(hnum)=16) then p_hex=true
End Property
rem ----------------------------------------------------------------------
Public property let ShowErrorNum(value) '2006-09-18 添加條事實顯示詳細的錯誤資訊
if(value) then
p_errdetails=true
p_errdetails=false
End Property
rem ----------------------------------------------------------------------
Public Property Get ErrNum()
If (p_hex) then 'Hex Code
ErrNum=hex(p_hError)
Else
ErrNum=p_hError 'D Code
End if
Public Property Get ErrDescription()
if(len(trim(p_msg))<1) then
ErrDescription="<li>系統正常!</li>"
ErrDescription=p_msg
'***********************************
rem 屬性定義結束
rem 功能函數
'******************************
'名稱: ChkPost
'參數:NULL
'傳回值:True:本站/False:未知來源
'建立時間:2005年5月5日
'作用:檢查被送出的資料來源
Public Function ChkPost()
Dim Server_v1,Server_v2
ChkPost=false
Server_v1=CStr(Request.ServerVariables("HTTP_REFERER"))
Server_v2=CStr(Request.ServerVariables("SERVER_NAME"))
If Mid(Server_v1,8,Len(Server_v2))=Server_v2 Then
ChkPost=True
p_hError=&H11010301
p_msg=p_msg & "<li><font color=red>資料來源不确定,請從正常入口進入!</font>"
if (p_errDetails) then p_msg=p_msg & "(錯誤碼:"& hex(p_hError) &")"
p_msg =p_msg & "</li>"
End Function
'名稱: ChkInvStr
'參數:Str
'傳回值:True(有特殊字元)/False(無特殊字元)
'建立時間:2006年9月16日
'作用:檢查參數是否有非法字元
Public Function ChkInvStr(Str)
Rem 定義需要過濾得非法字元
Dim InvaildWord,inWords,i
Dim m_msg
m_msg=""
Str=CStr(Str)
ChkInvStr=FALSE
If Len(Replace(p_InvaildWords,Chr(0),""))<1 Then
p_hError=&H10010001
p_msg =m_msg & "<li>系統設定有誤!"
if (p_errDetails) then p_msg=p_msg & "(錯誤碼:"& hex(p_hError) &")"
p_msg = p_msg & "</li>"
InvaildWord=Split(p_InvaildWords,"|")
inWords=LCase(Trim(Str))
For i=LBound(InvaildWord) To UBound(InvaildWord)
If Instr(inWords,trim(InvaildWord(i)))>0 and len(InvaildWord(i))>0 Then
p_hError=&H11010102 '發現非法字元
m_msg = m_msg & " <font color=""red"">" & InvaildWord(i) & "</font> "
End If
Next
End If
if (p_hError=&H11010102) then
p_msg=p_msg &"<li>"& m_msg & " 是被系統禁止的."
ChkInvStr=TRUE
'名稱: GetIP
'傳回值:NULL
'建立時間:2005年5月3日
'作用:得到使用者的ip位址
Public Function GetIP()
p_IpAdd=Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If IsNull(p_IpAdd) OR p_IpAdd="" Then
p_IpAdd=Request.ServerVariables("REMOTE_ADDR")
p_herror=&H11010201
p_msg =p_msg & "<li>您使用了代理 "
GetIp=p_IpAdd
rem **********************************************************************
end class
%>