I recently studied how to completely solve the ASP injection vulnerabilities. I hope we can make more suggestions.
Principle is to use preparestatement like java.
The following example connects to a SQL Server database
The code is as follows:
Preparesql.asp
<%
' Define database Operation constants
Const adstateclosed = 0
Const adopenforwardonly = 0, adOpenKeyset = 1, adopendynamic = 2, adOpenStatic = 3
Const adlockreadonly = 1, adlockpessimistic = 2, adLockOptimistic = 3, adLockBatchOptimistic = 4
Const adCmdText = 1, adCmdTable = 2, adCmdStoredProc = 4, adExecuteNoRecords = 128
Const adBigInt = Adboolean = one, Adchar = 129, Addate = 7, adinteger = 3, adSmallInt = 2, Adtinyint = adVarChar = 200
Const ADPARAMINPUT = 1, adparamoutput = 2, adParamInputOutput = 3, adParamReturnValue = 4
%>
<%class Preparesql
Private Cmdprep
Private m_string
Private M_sql
Private M_conn
Public Function Setconn (conn)
Set M_conn=conn
End Function
Public Function Prepare (SQL)
Set cmdprep=nothing
SET cmdprep=server.createobject ("Adodb.command")
Set Cmdprep.activeconnection=m_conn
Cmdprep.commandtext =sql
End Function
Public Function Setint (thevalue)
CmdPrep.Parameters.Append Cmdprep.createparameter ("", Adinteger, adParamInput, Thevalue)
End Function
Public Function setdate (thevalue)
CmdPrep.Parameters.Append Cmdprep.createparameter ("", adVarChar, adParamInput, Thevalue)
End Function
Public Function SetBoolean (thevalue)
CmdPrep.Parameters.Append Cmdprep.createparameter ("", Adboolean, adParamInput, 1, thevalue)
End Function
Public Function setstring (thevalue)
if (Len (thevalue) =0) Then
CmdPrep.Parameters.Append Cmdprep.createparameter ("", adVarChar, adParamInput, 1, thevalue)
Else
CmdPrep.Parameters.Append Cmdprep.createparameter ("", adVarChar, adParamInput, LenB (thevalue), thevalue)
End If
End Function
Public Function Execute ()
Set Execute=cmdprep.execute
End Function
End Class%>
Test.asp
<!--#include file= ". /include/datastore.asp "-->
<!--#include file= ". /include/preparesql.asp "-->
<%
Dim PS
Dim cn
Set Cn=server. CreateObject ("Adodb.connection")
Dim STRCN
strcn= "Driver={sql server};server=127.0.0.1;uid=sa;pwd=test;database=pubs"
cn. Open STRCN
Set Ps=new Preparesql
Ps.setconn cn
Ps.prepare "SELECT * from user where id =?"
Ps.setint 1
Dim rs
Set Rs=ps.execute
%>