如何将此查询转换为经典ASP中的参数化查询?
我的网站遭受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"
首先创建像下面
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中的列类型即可。可能有语法问题,我猜你可以轻松解决。如果完成参数化查询后出现任何错误,请联系。 希望你有起点。
Ash我的网站开发人员说这是桌面开发。不基于网络。他对吗? – user2065107 2013-02-18 09:36:39
我可以看到他已经在他的代码中编写了response.redirect,然后对我来说这是web开发 – DevelopmentIsMyPassion 2013-02-18 10:15:34
没有对不起Ash。我的网页开发人员说你的代码是桌面开发。他对吗? – user2065107 2013-02-18 15:40:50
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"
什么味道的SQL?这是SQL Server,oracle,IBM吗?而且哪个版本也可能有所帮助。还有什么是“逃生脚本”? – twoleggedhorse 2013-02-12 14:57:18
你是否搜索过?如果您搜索“防止ASP中的SQL注入”之类的东西,您会看到几个例子。像这样 - [如何:保护SQL注入在ASP.NET](http://msdn.microsoft.com/en-us/library/ff648339.aspx) – 2013-02-12 14:58:17
道歉我做了搜索,但我会更好地了解是否有人向我展示了如何转换我的一个查询。再次道歉。 – user2065107 2013-02-12 15:50:05