doulin9679 2013-04-07 10:41
浏览 88

反sql注入功能

I am using this function to prevent sql injections :

function filter($input)
{
  if(strpos(str_replace("''","","$input"),"'") != false)
  {
    return str_replace("'", "''", $input);
  }
  return $input;
}

is it safe to use it? can someone somehow bypass it? if is is possible to bypass it please give me a hint on how to secure this function or an example on how you see bypass for it

UPDATE : it is used on SQL Server

  • 写回答

3条回答 默认 最新

  • dongzhi9192 2013-04-07 10:43
    关注

    is it safe to use it?

    NO

    can someone somehow bypass it?

    YES

    1. It shouldn't be input filter by any means. But data formatter for the SQL query.
    2. At the very least it have to be

      function SQLstrFormat($str)
      {
          return "'".str_replace("'", "''", $str)."'";
      }
      

    this way it would be safe, when applicable.

    评论

报告相同问题?

悬赏问题

  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划