dongzhengzhong1282 2013-10-23 20:02
浏览 66
已采纳

限制在PHP中访问父目录

I have seen from other questions that I can set open_basedir to restrict access to parent folders. However, I decided to do a bit of experimenting to find out what I could do.

First test was to see if I could manually set open_basedir using the ini_set function. Thankfully, it appears that this function can set a more restrictive basedir, but it cannot be used to lessen the restriction. That's all good.

However my next test was somewhat disturbing:

ini_set("open_basedir","/path/to/desired/root/limited");
echo file_get_contents("/some/outsite/file.txt"); // error: basedir restriction
echo `cat /some/outside/file.txt`; // outputs the file

I can't seem to find any way to restrict shell access to stuff.

So I guess my real question is, what can I do to ensure that parent folders are safe? Clearly, open_basedir doesn't cut it.

  • 写回答

2条回答 默认 最新

  • dongmo2324 2013-10-23 20:33
    关注

    open_basedir generally doesn't restrict backdoor access like that. There was a "safe_mode" in PHP which prevented such calls like system() and exec(). Full list here: http://www.php.net/manual/en/features.safe-mode.functions.php

    But that's been deprecated as of PHP 5.3 because there are many ways around it.

    You could use suPHP and chroot, as suggested by another StackOverflow answer: PHP safemode alternative

    "A better approach is use suphp to run your application as a jailed user. This uses the security of the operating system to protect your application. You run your php code as an account that doesn't have access to a shell. You remove write privileges from everything owned by that user chmod 500 -R /. Or go a step further and run your application within a chroot."

    Useful links:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?