asp SQL 주입 방지 함수

'SQL 주입 방지 함수, 호출 방법, 주입 방지 가 필요 한 곳 에서 이전 request ("XXXX") 를 SafeRequest ("XXXX") 로 교체 합 니 다.  
'www.yongfa365.com   
  
Function SafeRequest(ParaValue)   
    ParaValue = Trim(Request(ParaValue))   
    If ParaValue = "" Then  
        SafeRequest = ""  
        Exit Function  
    End If  
    '걸 러 낼 문 자 는 "," 로 구분 합 니 다.  
    LockValue = "',Select,Update,Delete,insert,Count(,drop table,truncate,Asc(,Mid(,char(,xp_cmdshell,exec master,net localgroup administrators,And,net user,Or"  
    LockValue = Split(LockValue, ",")   
    '주입 여 부 를 판단 하 다.  
    For i = 0 To UBound(LockValue)   
        If InStr(LCase(ParaValue), LCase(LockValue(i)))>0 Then  
            errmsg = 1   
            Exit For  
        End If  
    Next  
    '주입 처리  
    If errmsg = 1 Then  
        Response.Write " alert ('수상 한 SQL 주입 요청!'); window. history. go (- 1); < / script > "  
        response.End  
    Else  
        SafeRequest = ParaValue   
    End If  
End Function  
'SQL     ,    ,              request("XXXX") SafeRequest("XXXX")
'www.yongfa365.com

Function SafeRequest(ParaValue)
    ParaValue = Trim(Request(ParaValue))
    If ParaValue = "" Then
        SafeRequest = ""
        Exit Function
    End If
    '       ","  
    LockValue = "',Select,Update,Delete,insert,Count(,drop table,truncate,Asc(,Mid(,char(,xp_cmdshell,exec master,net localgroup administrators,And,net user,Or"
    LockValue = Split(LockValue, ",")
    '       
    For i = 0 To UBound(LockValue)
        If InStr(LCase(ParaValue), LCase(LockValue(i)))>0 Then
            errmsg = 1
            Exit For
        End If
    Next
    '    
    If errmsg = 1 Then
        Response.Write "<script language='javascript'>alert('   SQL    !');window.history.go(-1);</script>"
        response.End
    Else
        SafeRequest = ParaValue
    End If
End Function


다음은 정규 표현 식 으로 걸 러 내 는 예 입 니 다.
view plain copy to clipboard print ?
  
'SQL 주입 방지 함수, 호출 방법, 주입 방지 가 필요 한 곳 에서 이전 request ("XXXX") 를 SafeRequest ("XXXX") 로 교체 합 니 다.      
'www.yongfa365.com      
     
Function SafeRequest(ParaValue)   
    ParaValue = Trim(Request(ParaValue))   
    '정규 표현 식 필터  
    Set re = New RegExp  
    '사용 하지 않 는 주입 문자  
    re.Pattern = "/'|Select|Update|Delete|insert|Count|drop table|truncate|Asc|Mid|char|xp_cmdshell|exec master|net localgroup administrators|And|net user|Or"  
    re.IgnoreCase = True  
    re.Global = True  
    Set Matches = re.Execute(ParaValue)   
    RegExpTest = Matches.count  
    '주입 처리  
    If RegExpTest >0 Then  
        Response.Write " alert ('수상 한 SQL 주입 요청!'); window. history. go (- 1); < / script > "  
        response.End  
    Else  
        SafeRequest = ParaValue   
    End If  
End Function  

좋은 웹페이지 즐겨찾기