Solution of ASP Injection Vulnerability

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.