2013-02-12 48 views
1

我的網站遭受SQL注入攻擊。我的網站開發人員拒絕承認參加遊說的查詢說他的轉義腳本已經足夠。有人可以請幫助通過顯示如何將以下經典asp寫入的查詢轉換爲一個參數化查詢?如何將此查詢轉換爲經典ASP中的參數化查詢?

conn.Execute "insert into tblGROUPcomments ([thecomment], [date_of_entry], [groupid], [submittedby]) " _ 
      & "values ('" _ 
      & Server.HTMLEncode(cleanuptext(request.form("txtcomments"))) & _ 
      "','" & FormatMediumDate(date()) & _ 
      "','" & session("groupid") & _ 
      "','" & session("userid") & "')" 
      session("errmessageT") = "" 
      session("varcommentT") = "" 
    response.redirect("../showallcommentsGROUPS.asp?gid=" & session("groupid")) & "#comments" 
+0

什麼味道的SQL?這是SQL Server,oracle,IBM嗎?而且哪個版本也可能有所幫助。還有什麼是「逃生腳本」? – twoleggedhorse 2013-02-12 14:57:18

+1

你是否搜索過?如果您搜索「防止ASP中的SQL注入」之類的東西,您會看到幾個例子。像這樣 - [如何:保護SQL注入在ASP.NET](http://msdn.microsoft.com/en-us/library/ff648339.aspx) – 2013-02-12 14:58:17

+0

道歉我做了搜索,但我會更好地瞭解是否有人向我展示瞭如何轉換我的一個查詢。再次道歉。 – user2065107 2013-02-12 15:50:05

回答

1

首先創建像下面

Dim cmd 
Set cmd = Server.CreateObject("ADODB.Command") 
' set command to your previously opened connection 
Set cmd .ActiveConnection = connContent 
SQL = " insert into tblGROUPcomments ([thecomment], [date_of_entry]) values (?, ?)" 

Set newParameter = cmd.CreateParameter("@thecomment", ad_nVarChar, ad_ParamInput, Server.HTMLEncode(cleanuptext(request.form("txtcomments"))), thecomment) 
    cmd.Parameters.Append newParameter 
Set newParameter = cmdConn.CreateParameter("@date_of_entry", ad_Integer, ad_ParamInput, FormatMediumDate(date()), date_of_entry) 
    cmdConn.Parameters.Append newParameter 

cmd.CommandText = SQL 
cmd.Execute 

我已經在查詢中使用僅2列(thecomment和data_of_entry)命令對象。只需修改newParameter中的列類型即可。可能有語法問題,我猜你可以輕鬆解決。如果完成參數化查詢後出現任何錯誤,請聯繫。 希望你有起點。

+0

Ash我的網站開發人員說這是桌面開發。不基於網絡。他對嗎? – user2065107 2013-02-18 09:36:39

+0

我可以看到他已經在他的代碼中編寫了response.redirect,然後對我來說這是web開發 – DevelopmentIsMyPassion 2013-02-18 10:15:34

+0

沒有對不起Ash。我的網頁開發人員說你的代碼是桌面開發。他對嗎? – user2065107 2013-02-18 15:40:50

0
maxCommentSize=1073741823 
    comments=Server.HTMLEncode(cleanuptext(request.form("txtcomments") 
    comments=left(comments,maxCommentSize) 

    Set cmdAdd = Server.CreateObject ("ADODB.Command") 
    cmdAdd.ActiveConnection = connection_string 
    cmdAdd.CommandText = "INSERT INTO nsert into tblGROUPcomments ([thecomment], [date_of_entry], [groupid], [submittedby]) VALUES (?, ?, ?, ?)" 
    cmdAdd.Prepared = true 
    cmdAdd.Parameters.Append cmdAdd.CreateParameter("param1", 203, 1, maxCommentSize, comments) 
    cmdAdd.Parameters.Append cmdAdd.CreateParameter("param2", 135, 1, -1, FormatMediumDate(date())) 
    cmdAdd.Parameters.Append cmdAdd.CreateParameter("param2", 5, 1, -1, session("groupid")) 
    cmdAdd.Parameters.Append cmdAdd.CreateParameter("param2", 5, 1, -1, session("userid")) 
    cmdAdd.Execute 
    cmdAdd.ActiveConnection.Close 

    session("errmessageT") = "" 
    session("varcommentT") = "" 
    response.redirect("../showallcommentsGROUPS.asp?gid=" & session("groupid")) & "#comments" 
相關問題