dsbgltg159136540 2017-10-17 21:58
浏览 59
已采纳

php安全性以防止恶意软件插入

I am writing a program to be run on a server that takes input from clients in the form http://mywebsite.com/program.php?input=42

I'm concerned that having the client be able to give any value in place of the 42 above could be a security risk because they could put code there that might run on my server. I would like to know if checking that this input is only alphanumberic before proceeding to do anything with it is sufficient protection. If not what should I do to be secure, if so, are there any safety concerns regarding the way in which I do this checking (for example, while checking that the input is alphanumberic could the input if it is malicious code some how get run?)

Thanks

  • 写回答

1条回答 默认 最新

  • duanji6997 2017-10-17 22:10
    关注

    It’s all about how you’re interpreting and using that $_GET['input']

    If you do such a code:

    exec($_GET['input']);
    

    or

    if($_GET['input']) == 66) {
         exec("rm -r /");
    }
    

    That’s obvious that people can do something dangerous. But it’s less critical than what you think.

    The problem of php it’s that its type system doesn’t encourage people checking their input before using it.

    An usual example is the SQL injectable code:

    $db->query("SELECT * FROM table WHERE id = '. $_GET['id'].'");
    

    Which is really unsafe.

    In your example, if your input should be an integer you can check if that’s an integer:

    if (!is_integer($_GET['input'])) die("invalid");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部