徹底解決asp注入漏洞的方法

來源:互聯網
上載者:User

 

本人最近研究徹底解決asp注入漏洞的方法!希望大家多提建議
原理,就是象java一樣使用preparestatement.
下面例子串連的是sql server資料庫
代碼如下:
PrepareSql.asp
<%
' 定義資料庫操作常量
 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 = 20, adBoolean = 11, adChar = 129, adDate = 7, adInteger = 3, adSmallInt = 2, adTinyInt = 16, 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, 100, 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
%> 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.