Il tuo indirizzo IP

Eccolo: 38.107.179.220
Home Script Notes asp SQL-Injection
SQL-Injection E-mail
Valutazione attuale: / 0
ScarsoOttimo 
Venerdì 13 Giugno 2008 18:48

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, ">", "&gt;")
    srcTmp = fnKillChars(srcTmp)
    PuliziaInjection = srcTmp
End Function

Function fnPurifica(sTesto)

    Dim sArrTag, sTag, sDebug

    sTesto2 = Replace(Trim("" & sTesto), "&lt;", "<")
    sTesto2 = Replace(sTesto2, "&gt;", ">")

    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, "<", "&lt;")
    sTesto3 = Replace(sTesto3, ">", "&gt;")

    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
%>

Commenti
Nuovo
Commenta
Nome:
Email:
 
Titolo:
<<  

3.25 Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."