Attack | Original ##############################################
This article all code copyright belongs to [rain wave], reprint please declare
##############################################
ASP is not the most vulnerable technology, but to prevent hacker attacks
And no matter how it's attacked, it's two.
Through QueryString and form
As long as these two defenses are good, the problem is solved.
Here are some of my own original code, for your reference
A. Anti-querystring SQL attack
General SQL can attack the page is usually in the parameter is a number of pages
1. First we do a warning process
The "' Sub-process function: Error message prompt '" "" "" "" ""
"' Parameter description: ERRMSG error message description var processing mode 1 return does not refresh 2 return to Page 3" "" "" "" '
Public Sub Alarm (errmsg,var)
Response. Write ("<table width=514 height=293 border=0 align=center cellpadding=0")
Response. Write ("<tr><td height=43></td></tr><tr> ")
Response. Write ("<td height=239 valign=top>")
Response. Write ("<table width= ' 100% ' height= ' 100%" cellpadding=0 cellspacing=1 ' bgcolor= ' #cccccc ' style= ' border-left:1px Solid #DDDDDD border-right:1px solid #DDDDDD ' > ')
Response. Write ("<tr bgcolor= ' #FFFFFF ' ><td width= ' 57% ' align= ' center ' ></td> ')
Response. Write ("<td width= ' 43% ' align= ' center ' ><div align= ' center ' style= ' line-height:150% ><font ' color= ') 0099FF ' style= ' font-size:9pt ' > for operation failure We apologize! <br> If there is still a problem, please send us error report </font></div></td></tr> ")
Response. Write ("<tr bgcolor= ' #FFFFFF ' ><td height=25 colspan=2> <strong><font color= #0099FF style= '" Font-size:9pt ' > Possible causes of Failure:</font></strong></td></tr> ')
Response. Write ("<tr bgcolor= ' #FFFFFF ' ><td height=86 colspan=2>")
Response. Write ("<table width= ' 100% ' border=0 cellspacing=0 cellpadding=0>")
Response. Write ("<tr><td width= ' 2% ' > </td>")
Response. Write ("<td width= ' 98% ' ><font style= ' font-size:9pt ' color= ' #FF0000 ' >" &errmsg& "</font> </td> ")
Response. Write ("</tr></table></td></tr><tr align=center bgcolor= ' #FFFFFF ' ><td height=49 Colspan=2> ")
If Var=1 Then
Response. Write ("<a href= ' Javascript:history.go ( -1) ' ></a> ')
ElseIf var=2 Then
Response. Write ("<a href= ' javascript:location.href= '" &request. ServerVariables ("Http_referer") & "' ></a> ')
ElseIf Var=3 Then
Response. Write ("<a href= ' javascript:window.close () ' ></a> ')
End If
Response. Write ("</td></tr></table></td></tr><tr>")
Response. Write ("<td height=9></td></tr></table> ")
End Sub
2. Write a function that verifies numbers
' Function: Detect whether it is a number and whether the number is valid ' "', '" ' "'
"" "" "" "" "," "" "", "" "", "" "", "" "" "" "" "
Public function Isinteger (para)
If IsNumeric (para) =false then isinteger=false
Dim str
Dim l,i
If ISNULL (para) Then
Isinteger=false
Exit function
End If
STR=CSTR (para)
If trim (str) = "" Then
Isinteger=false
Exit function
End If
L=len (str)
For I=1 to L
If Mid (str,i,1) > "9" or mid (str,i,1) < "0" then
Isinteger=false
Exit function
End If
Next
Isinteger=true
End Function
3. Write a validation process for querysting parameters as numbers
' ' ' Sub-procedure function to verify that the parameter is a number
' ' parameter description: Manage processing mode: 1 = prompt information and close the page, 2 = Turn the page, 3 = First prompt and then turn to Redi when the error turned to the page, str: The variable to accept the test
Public Sub Integerok (MANAGE,REDI,STR)
if Isinteger (str) =false Then
Select Case Manage
Case 1
Response. Write ("<script language=javascript>alert (" parameter error in the Address bar, this page will automatically close); Window.close ();</script> ")
Case 2
Response.Write "<script language=javascript>location.href= '" &redi& "' </Script>"
Case 3
Response.Write "<script language=javascript>alert (' parameter error in the Address bar, this page will automatically guide other pages '); location.href= ' &redi& ' ';</script> '
End Select
End If
End Sub
4. Write a subroutine that validates the whole qureystring
"" "" "Parameter Description: Manage processing mode: 1 = prompt information and close the page, 2 = Turn to page, 3 = First prompt and then turn to Redi when the error turned to the page
Public Sub Saferush (Manage,redi