SQL过滤

xsunx 2005-01-13 11:15:37
有如下代码方案。
Function SQLEncode(ByVal fString) 'SQL过滤
If Not isnull(fString) Then
fString = Replace(fString, "'","''")
fString = Replace(fString, ";","")
fString = Replace(fString,Chr(34), "''")
SQLEncode = fString
End If
End Function

但我觉得不够好,这样的话。
;就不能输入了。因为会被过滤。
在SQL中究竟那些字符需要过滤。
那些字符有特殊的符号代替输入如:''代表'
insert into [test]([fields1]) values ('a''a')实际上插入的内容为a'a

...全文
131 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
xsunx 2005-01-14
  • 打赏
  • 举报
回复
现在的关键问题是如果我要输入这些
   net user
   xp_cmdshell
   /add
   exec master.dbo.xp_cmdshell
   net localgroup administrators
   select
   count
   Asc
   char
   mid
   '
   :
   "
   insert
   delete from
   drop table
   update
   truncate
   from
字符又怎么处理呢
就如同:''代表'可以解决'的输入
其它的怎么解决呢!
alern_zyb 2005-01-13
  • 打赏
  • 举报
回复
Function SafeRequest(ParaName,ParaType)
   '--- 传入参数 ---
   'ParaName:参数名称-字符型
   'ParaType:参数类型-数字型(1表示以上参数是数字,0表示以上参数为字符) 

   Dim ParaValue
   ParaValue=Request(ParaName)
   If ParaType=1 then
   If not isNumeric(ParaValue) then
   Response.write "参数" & ParaName & "必须为数字型!"
   Response.end
   End if
   Else
   ParaValue=replace(ParaValue,"'","''")
   End if
   SafeRequest=ParaValue
  End function
xsunx 2005-01-13
  • 打赏
  • 举报
回复
怎么没有高手发言!!
qfacy 2005-01-13
  • 打赏
  • 举报
回复
过滤不好真的很容易有漏洞!
lemon_lyk 2005-01-13
  • 打赏
  • 举报
回复
http://www.gzicp.com/tech/db/sql/1094333842760.shtml
lemon_lyk 2005-01-13
  • 打赏
  • 举报
回复
http://www.gzicp.com/tech/db/sql/1094333842760.shtml
世界因你而小 2005-01-13
  • 打赏
  • 举报
回复
学习
xsunx 2005-01-13
  • 打赏
  • 举报
回复
日期的合法性检测应该怎么写????
xsunx 2005-01-13
  • 打赏
  • 举报
回复

我主要想要,,,防止SQL注入攻击 .
我主要想要,,,防止SQL注入攻击 .

我主要想要,,,防止SQL注入攻击 .

我主要想要,,,防止SQL注入攻击 .

itera 2005-01-13
  • 打赏
  • 举报
回复

Public Function CheckStrg(Str) '适用字符型 功能是过滤掉'
If Isnull(Str) Then
CheckStrg = ""
Exit Function
End If
CheckStrg = Replace(Str,"'","''")
End Function
Public Function CheckNum(NumPara) '适用数值型参数
If NumPara="" or not isNumeric(NumPara) then
Response.write "参数必须为数字型!"
Response.end
End if
CheckNum=NumPara
End Function

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧