转义在防止SQL注入中依然不够

转自:http://www.webappsec.org/projects/articles/091007.shtml

 

mysql_real_escape_string对于防止SQL注入还是不够的。对于某些参数的值来说,用引号包含起来是可以的。但是对于某些,比如columns, tables or databases,这些值不能用引号将值包含起来,鉴于mysql_real_escape_string的仅对有限字符转义,因此这些时候存在隐患。

 

mysql_real_escape_string() is a necessary, but not sufficient measure. Here are the "checklist" rules one must follow to make sure the dynamic SQL code is not vulnerable to SQL injection:

 

  • Write properly quoted SQL:
    1. Single quotes around values (string literals and numbers)
    2. Backtick quotes around identifiers (databases, tables, columns, aliases)
  • Properly escape the strings and numbers:
    1. mysql_real_escape_string() for all values (string literals and numbers)
    2. intval() for all number values and the numeric parameters of LIMIT
    3. Escape wildcard/regexp metacharacters (addcslashes('%_') for LIKE, and you better avoid REGEXP/RLIKE)
    4. If identifiers (columns, tables or databases) or keywords (such as ASC and DESC) are referenced in the script parameters, make sure (and force) their values are chosen only as one of an explicit set of options
    5. No matter what validation steps you take when processing the user input in your scripts, always do the escaping steps before issuing the query. Validation is not a substitute for escaping!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值