'Fonction : fonction de détection de chaîne sécurisée
'Nom : SafeCheck
'Paramètres : CheckString, CheckType, CheckLength
'illustrer:
'Checkstring La chaîne à détecter : n'importe quel caractère.
'Type de détection CheckType 0 caractère court normal 1 chiffre 2 date 3 argent 4 encodage HTML5 décodage HTML6 chaîne de connexion 7 détection anti-attaque
'CheckLength détecte la longueur du type : le type est un entier, lorsqu'il s'agit d'argent, c'est la position du point décimal
'Valeur de retour : S'il réussit le test, renvoie la chaîne correcte,
'En cas d'échec, renvoyez le code d'erreur SYSTEM_ERROR|ERROR_CODE
'Script écrit par :SnowDu(DU雪.NET)
'Web : http://www.snsites.com/
'Web : http://www.downcodes.com/
'---------------------------------------------
fonction SafeCheck(CheckString,CheckType,CheckLength)
En cas d'erreur, reprendre ensuite
ErreurRoot="SYSTEM_ERROR|"
si checkString="" alors
SafeCheck=ErreurRoot&"00001"
fonction de sortie
terminer si
CheckString=Replace(CheckString,"'","'")
sélectionner le cas CheckType
cas 0
CheckString=trim(CheckString)
SafeCheck = Gauche (CheckString, CheckLength)
cas 1
sinon c'est un numéro (CheckString) alors
SafeCheck=ErreurRoot&"00002"
fonction de sortie
autre
SafeCheck = Gauche (CheckString, CheckLength)
finir si
cas 2
tempVar=EstDate(CheckString)
si ce n'est pas TempVar alors
SafeCheck=ErreurRoot&"00003"
fonction de sortie
autre
sélectionner le cas CheckLength
cas 0
SafeCheck = FormatDateTime (CheckString, vbShortDate)
cas 1
SafeCheck = FormatDateTime (CheckString, vbLongDate)
cas 2
SafeCheck = Chaîne de contrôle
fin de la sélection
finir si
cas 3
tempVar=FormatCurrency(CheckString,0)
si Err alors
SafeCheck=ErreurRoot&"00004"
fonction de sortie
autre
SafeCheck=FormatCurrency(CheckString,CheckLength)
finir si
cas 4
sTemp = Chaîne de contrôle
Si IsNull(sTemp) = True Alors
SafeCheck=ErreurRoot&"00005"
Fonction de sortie
Fin si
sTemp = Remplacer(sTemp, "&", "&")
sTemp = Remplacer(sTemp, "<", "<")
sTemp = Remplacer(sTemp, ">", ">")
sTemp = Remplacer(sTemp, Chr(34), """)
sTemp = Remplacer(sTemp, Chr(10), "<br>")
SafeCheck = Gauche (sTemp,CheckLength)
cas 5
sTemp = Chaîne de contrôle
Si IsNull(sTemp) = True Alors
SafeCheck=ErreurRoot&"00006"
Fonction de sortie
Fin si
sTemp = Remplacer(sTemp, "&", "&")
sTemp = Remplacer(sTemp, "<", "<")
sTemp = Remplacer(sTemp, ">", ">")
sTemp = Remplacer(sTemp, """, Chr(34))
sTemp = Remplacer(sTemp, "<br>",Chr(10))
SafeCheck = Gauche (sTemp,CheckLength)
cas 6
s_BadStr = "' &<>?%,;:()`~!@#$^*{}[]|+-=" & Chr(34) & Chr(9) & Chr(32)
n = Len(s_BadStr)
IsSafeStr = Vrai
Pour i = 1 À n
Si Instr(CheckString, Mid(s_BadStr, i, 1)) > 0 Alors
IsSafeStr = Faux
Fin si
Suivant
si IsSafeStr alors
SafeCheck = gauche (CheckString, CheckLength)
autre
SafeCheck=ErreurRoot&"00007"
Fonction de sortie
finir si
cas 7
s_Filter="utilisateur net|xp_cmdshell|/add|select|count|asc|char|mid|'|""|"
S_Filter=S_Filter&"insérer|supprimer|drop|truncate|from|%|declare|-"
S_Filters=split(S_Filter,"|")
isFound=faux
pour i=0 à ubound(S_Filters)-1
si Instr(lcase(CheckString),lcase(S_Filters(i)))<>0 alors
isFound = vrai
sortie pour
finir si
suivant
si est trouvé alors
SafeCheck=ErreurRoot&"00008"
Fonction de sortie
autre
SafeCheck = gauche (CheckString, CheckLength)
finir si
fin de la sélection
fonction de fin