ASP veya bir başka dil farketmez. Mantık aynı. Normalde ID gelmesi gereken yere select komutu uygularsın ve injection yapmış olursunuz. ID normalde integerdir. Yani sayısal değer alır.
Link: sayfa.asp?id=1 şeklindedir ve bu HayroLa arkadaşın verdiği kodla normal olarak çalışmasını devam ettirecektir. Çünkü 1 Numerictir. Injection yaparken link şu şekilde değişiecektir;
sayfa.asp?id=-1 union+select+0+from+admin gibi...
Kalın çizdiğim yerler numeric'e girmiyor. Arkadaşın verdiği kodda ID numeric değilse yönlensin diyor ve normal bir koruma yapıyor. En basitiyle bu şekilde korunulunabilir. Ama yok ben illa fonksiyon yazıcam öyle korunucam derseniz;
<%
Function inject(Str)
Str = Replace(Str, "*", "[YASAK]",1,-1,1)
Str = Replace(Str, "=", "[YASAK]",1,-1,1)
Str = Replace(Str, "<", "[YASAK]",1,-1,1)
Str = Replace(Str, ">", "[YASAK]",1,-1,1)
Str = Replace(Str, ";", "[YASAK]",1,-1,1)
Str = Replace(Str, "(", "[YASAK]",1,-1,1)
Str = Replace(Str, ")", "[YASAK]",1,-1,1)
Str = Replace(Str, "+", "[YASAK]",1,-1,1)
Str = Replace(Str, "#", "[YASAK]",1,-1,1)
Str = Replace(Str, "'", "[YASAK]", 1, -1, 1)
Str = Replace(Str, "&", "[YASAK]", 1, -1, 1)
Str = Replace(Str, "%", "[YASAK]", 1, -1, 1)
Str = Replace(Str, "?", "[YASAK]", 1, -1, 1)
Str = Replace(Str, "´", "[YASAK]", 1, -1, 1)
Str = Replace(Str, ",", "[YASAK]",1,-1,1)
Str = Replace(Str, "UNION", "[YASAK]",1,-1,1)
Str = Replace(Str, "SELECT", "[YASAK]",1,-1,1)
Str = Replace(Str, "WHERE", "[YASAK]",1,-1,1)
Str = Replace(Str, "LIKE", "[YASAK]",1,-1,1)
Str = Replace(Str, "FROM", "[YASAK]",1,-1,1)
Str = Replace(Str, "UPDATE", "[YASAK]",1,-1,1)
Str = Replace(Str, "INSERT", "[YASAK]",1,-1,1)
Str = Replace(Str, "ORDER", "[YASAK]",1,-1,1)
Str = Replace(Str, "GROUP", "[YASAK]",1,-1,1)
Str = Replace(Str, "ALTER", "[YASAK]",1,-1,1)
Str = Replace(Str, "ADD", "[YASAK]",1,-1,1)
Str = Replace(Str, "MODIFY", "[YASAK]",1,-1,1)
Str = Replace(Str, "RENAME", "[YASAK]",1,-1,1)
Str = Replace(Str, Chr(39), "[YASAK]", 1, -1, 1)
If InStr(1,Str,"[YASAK]",1) then
Response.Redirect "/Default.asp"
end if
inject = Str
End Function
%>
şeklinde fonksiyon oluşturur,
inject(Request.QueryString("id")) olarak veriyi çektiririz. Buda fonksiyonla koruma sağlar.