|
Tre funzioni per ripulire e prevenire SQL-Injection. E' possibile utilizzare sia singolarmente la seconda e terza funzione oppure, per utilizzarle entrambe, basta richiamare la prima.
<%
Function PuliziaInjection(PAR_Testo)
Dim srcTmp
srcTmp = Trim("" & PAR_Testo)
srcTmp = fnPurifica(srcTmp)
srcTmp = Replace(srcTmp, ">", ">")
srcTmp = fnKillChars(srcTmp)
PuliziaInjection = srcTmp
End Function
Function fnPurifica(sTesto)
Dim sArrTag, sTag, sDebug
sTesto2 = Replace(Trim("" & sTesto), "<", "<")
sTesto2 = Replace(sTesto2, ">", ">")
sTag = "script,/script,iframe,/iframe"
sArrTag = Split(sTag, ",", -1, 1)
sTmp = UCase(sTesto2)
For sIndex = LBound(sArrTag) To UBound(sArrTag)
sSearch = UCase("<" & sArrTag(sIndex))
Do While (Instr(1, sTmp, sSearch) > 0)
If Ucase(sTmp) <> Ucase(sTesto2) Then
sTmp = Ucase(sTesto2)
End If
sPosInit = Instr(1, sTmp, sSearch)
If sPosInit > 0 Then
sPosEnd = Instr(sPosInit, sTmp, ">")
If (sPosEnd > sPosInit) Then
sTagLen = (sPosEnd - sPosInit) + 1
sReplace = Mid(sTesto2, sPosInit, sTagLen)
sTmpReplace = Mid(sTmp, sPosInit, sTagLen)
sTmp = Replace(sTmp, sTmpReplace, "")
sTesto2 = Replace(sTesto2, sReplace, "")
End If
End If
Loop
Next
sTesto3 = Replace(sTesto2, "<", "<")
sTesto3 = Replace(sTesto3, ">", ">")
fnPurifica = sTesto3
End Function
Function fnKillChars(strWords)
Dim badChars
Dim newChars
badChars = array("select", "drop", ";", "--", "insert", "delete", "xp_", "having")
newChars = strWords
For i = 0 To uBound(badChars)
newChars = replace(newChars, badChars(i), "")
Next
fnKillChars = newChars
End Function
%>
|