Asp classic SQL注入就是这样好吗

Asp classic SQL注入就是这样好吗,asp-classic,sql-injection,Asp Classic,Sql Injection,我在这方面做了很多研究,但我在理解上仍然有问题。然而,我想确保我得到了适当的保护。我在经典ASP中编写了一个函数,以帮助防止SQL注入或可能的对DB的暴力。如果我需要添加或删除内容,甚至纠正问题以使其更安全,你们能给我你们自己的意见和建议吗?提前非常感谢 在插入MySQL数据库之前,我会在下面使用它 插入示例: conn.execute("INSERT INTO " & employees & "(eid, first_name, last_name) VALUES('" &am

我在这方面做了很多研究,但我在理解上仍然有问题。然而,我想确保我得到了适当的保护。我在经典ASP中编写了一个函数,以帮助防止SQL注入或可能的对DB的暴力。如果我需要添加或删除内容,甚至纠正问题以使其更安全,你们能给我你们自己的意见和建议吗?提前非常感谢

在插入MySQL数据库之前,我会在下面使用它

插入示例:

conn.execute("INSERT INTO " & employees & "(eid, first_name, last_name) VALUES('" & Clng(strEID) & "','" & SQLClean(strfirstname) & "','" & SQLClean(strlastname) & "');")
职能:

私有函数SQLClean(ByVal strString)
如果字符串“”则
strString=微调(strString)
'从sql中删除malisous字符\
strString=replace(strString,“-shutdown”,”,1,-1,1)
strString=replace(strString,“\”,“\\”,1,-1,1)
strString=replace(strString,“=”,“\=”,1,-1,1)
strString=replace(strString,“,”,“\,”,1,-1,1)
strString=replace(strString,“`”,“\`”,1,-1,1)
strString=replace(strString,“&”、“\&”,1,-1,1)
strString=replace(strString,“/”,“\/”,1,-1,1)
strString=replace(strString,“[”,“\[”,1,-1,1)
strString=replace(strString,“]”,“\]”,1,-1,1)
strString=replace(strString,“{”,“\{”,1,-1,1)
strString=replace(strString,“}”,“\}”,1,-1,1)
strString=replace(strString,“(”,“\(”,1,-1,1)
strString=replace(strString,“)”,“\”,1,-1,1)
strString=replace(strString,“;”,“\;”,1,-1,1)
strString=replace(strString,“+”,“\+”,1,-1,1)
strString=replace(strString,“”,1,-1,1)
strString=replace(strString,“^”,“\^”,1,-1,1)
strString=replace(strString,“@”,“\@”,1,-1,1)
strString=replace(strString,“$”,“\$”,1,-1,1)
strString=replace(strString,“%”,“\%”,1,-1,1)
strString=replace(strString,“!”,“\!”,1,-1,1)
strString=replace(strString,“*”,“\*”,1,-1,1)
strString=replace(strString,“~”,“\~”,1,-1,1)
strString=replace(strString,“\”,“\ \”,1,-1,1)
strString=replace(strString,“?”,“\?”,1,-1,1)
strString=replace(strString,“'”,“\”,1,-1,1)
strString=replace(strString,“,“\”,1,-1,1)
strString=replace(strString,“选择”,“选择”,“1,-1,1)
strString=替换(strString,“插入”、“\insert”、1、-1、1)
strString=replace(strString,“更新”,“更新”,1,-1,1)
strString=replace(strString,“delete”,“\delete”,1,-1,1)
strString=替换(strString,“或”、“\或”、1、-1、1)
strString=replace(strString,“and”、“\and”、1、-1、1)
strString=replace(strString,“drop”、“\drop”、1、-1、1)
strString=replace(strString,“union”、“\union”,1,-1,1)
strString=replace(strString,“into”、“\into”、1、-1、1)
'返回已清除的值。
SQLClean=修剪(strString)
如果结束
端函数


还值得注意的是,您应该始终验证变量,在SQL查询中转储变量之前检查正确的值。检查有效值通常比检查人们可能塞进变量中的所有不好的东西容易。

请,在任何情况下都不要尝试编写自己的SQL转义代码,除非这纯粹是一个学术练习。你会弄错的。如果有人在你的网站上使用了一个新的工具,你将遭受严重的后果。商业和职业生涯已经被人们随意对待这件事的方式所摧毁

我花了三分钟的时间才找到了使用参数的经典ASP和MySQL查询


请,请,请使用官方设施,不要使用自己的。

谢谢您提供的信息。但是如果他们尝试运行诸如delete、drop、union等命令呢。。。将“更改为”(两个单引号)会停止吗?是的,因为命令将位于其中一个提交的变量的值内,因此脚本的引号将意味着它们将转换为文字值。因此,在函数中添加所有添加信息是一种浪费?我不需要做任何其他事情来保护自己不受它的影响?这当然不是浪费,我也不会告诉您删除它,因为SQL注入攻击者可能非常聪明。。。然而,双引号应该是所有你需要的。我还编辑了我的答案,其中包括一个关于正确验证变量(即检查适当的长度、值类型等)的注释,这将比大多数replace()语句更能帮助您。我会在转储到db之前检查,以确保变量中有数据、格式等。如果需要,我还将双重检查变量的数据,如数字等。然而,我也在客户端做这件事,但有时客户端并不那么可靠。非常感谢你。现在,我要像你说的那样保持SQLClean,它不会有任何伤害,在当今世界,任何额外的保护都是一个好主意。除此之外,我还有一个函数,可以将数据库中的数据清除回数据库。再次感谢您的帮助!!我不是MySQL的人,但我建议使用参数化存储过程是防止sql注入攻击的最佳实践。@Zia你能再解释一下参数化存储过程是什么意思吗?也许能举个小例子什么的?谢谢我不能在评论中发布一个样本,所以我在这里发布了一个链接来帮助我。什么是一个官方机构会做的而我做不到的?他们做什么样的事情?如果有人是一个相当优秀的SQL/php、.net、asp或其他任何编码人员,为什么我或其他人不能专门编写自己的SQL转义代码呢?它们和一些官方设施有什么区别?谢谢就我个人而言,我写我自己的,并不担心它,因为该网站是IP特定的,所以没有一个批准的IP地址,任何人都无法访问它。SQL部分