ASP安全检测类

作者:孤剑

时间: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 系统属性定义区域
  public property get Version()
   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
  end property
  rem ----------------------------------------------------------------------
  
  '**********************************
  ' 获得此过程中产生的错误信息
  '----------------------------------
  Public property let HexError(hnum) '2006-9-18 添加编码属性
   if(isnumeric(hnum)) then
    if(cint(hnum)=16) then p_hex=true
   end if
  End Property
  rem ----------------------------------------------------------------------  
  Public property let ShowErrorNum(value) '2006-09-18 添加条事实显示详细的错误信息
   if(value) then
    p_errdetails=true
   else
    p_errdetails=false
   end if
  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
  End Property
  rem ----------------------------------------------------------------------  
  Public Property Get ErrDescription()
   if(len(trim(p_msg))<1) then
    ErrDescription="<li>系统正常!</li>"
   else
    ErrDescription=p_msg
   end if
  End Property
  '***********************************
  rem ----------------------------------------------------------------------
  rem 属性定义结束
  rem **********************************************************************
  
  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
   else
    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 if
  End Function
  rem ----------------------------------------------------------------------
 
  '******************************
  '名称: 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>"
   Else
    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 & " 是被系统禁止的."
    if (p_errDetails) then p_msg=p_msg & "(错误码:"& hex(p_hError) &")"
    p_msg =p_msg & "</li>"
    ChkInvStr=TRUE
   end if
  End Function
  rem ----------------------------------------------------------------------
 
  '******************************
  '名称: GetIP
  '参数:NULL
  '返回值: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")
   else
    p_herror=&H11010201
    p_msg =p_msg & "<li>您使用了代理 "
    if (p_errDetails) then p_msg=p_msg & "(错误码:"& hex(p_hError) &")"
    p_msg =p_msg & "</li>"
   End If
   GetIp=p_IpAdd
  End Function
  rem ----------------------------------------------------------------------
  rem ********************************************************************** 
  
 end class
%>

原文地址:https://www.cnblogs.com/AloneSword/p/2237574.html