dsbgltg159136540 2017-10-18 05: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-18 06: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 vue使用gojs,需求在link中的虚线上添加方向箭头
  • ¥15 CSS通配符清除内外边距为什么可以覆盖默认样式?
  • ¥15 SPSS分类模型实训题步骤
  • ¥15 求解决扩散模型代码问题
  • ¥15 工创大赛太阳能电动车项目零基础要学什么
  • ¥20 limma多组间分析最终p值只有一个
  • ¥15 nopCommerce开发问题
  • ¥15 torch.multiprocessing.spawn.ProcessExitedException: process 1 terminated with signal SIGKILL
  • ¥15 QuartusⅡ15.0编译项目后,output_files中的.jdi、.sld、.sof不更新怎么解决
  • ¥15 pycharm输出和导师的一样,但是标红