绕过 PHP 安全模式来写入服务器。 是否可以?

发布于 2024-07-08 08:44:20 字数 467 浏览 11 评论 0原文

由于服务器打开了安全模式,并且在不同用户下创建目录,因此我遇到了以下问题:

  1. 我将脚本上传到服务器,它显示为属于“user1”。 它所做的就是在创建新用户时创建一个新目录,以便可以在其中存储文件。
  2. 新目录已创建,但属于“apache”用户。
  3. 'user1' 和 'apache' 是不同的用户; 并且安全模式已开启。 因此 php 脚本无法写入新创建的目录。
  4. 现在我有一个问题!

一种解决方案是关闭安全模式。 此外,一位同事建议可以更改一些设置,以确保目录与脚本位于同一用户下。 所以我想看看后者是否可以完成。

但我不得不问。 有针对我的问题的编程解决方案吗?

我倾向于“不”,因为安全模式是为了在 php 级别解决这个问题而实现的。 此外,实际问题可能看起来像是在不同用户下创建的目录,因此程序性修复可能只是一个创可贴修复。

I have got the following problem since the server has safe mode turned on, and directories are being created under different users:

  1. I upload my script to the server, it shows as belonging to 'user1'. All it is doing is making a new directory when a new user is created so it can store files in it.
  2. New directory is created, but it belongs to 'apache' user.
  3. 'user1' and 'apache' are different users; and safe mode is turned on. So the php script cannot write to that newly created directory.
  4. Now I have a problem!

One solution is to turn off safe mode. Also, a coworker suggested that there are settings that can be changed to ensure the directories are under the same user as the script. So I am looking to see if latter can be done.

But I have to ask. Is there a programatical solution for my problem?

I am leaning to a 'no', as safe mode was implemented to solve it at the php level. Also the actual problem may seem like the directory being created under a different user, so a programatic fix might just be a band-aid fix.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情栀口红 2024-07-15 08:44:20

我使用了这个解决方法:

您可以使用适当的权限通过 FTP 创建目录,而不是 php mkdir。

    function FtpMkdir($path, $newDir) {
       $path = 'mainwebsite_html/'.$path;
       $server='ftp.myserver.com'; // ftp server
       $connection = ftp_connect($server); // connection


       // login to ftp server
       $user = "[email protected]";
       $pass = "password";
       $result = ftp_login($connection, $user, $pass);

       // check if connection was made
       if ((!$connection) || (!$result)) {
          return false;
          exit();
       } else {
         ftp_chdir($connection, $path); // go to destination dir
         if(ftp_mkdir($connection, $newDir)) { // create directory
             ftp_site($connection, "CHMOD 777 $newDir") or die("FTP SITE CMD failed.");
             return $newDir;
         } else {
           return false;
         }

         ftp_close($connection); // close connection
      }

  }  

I've used this workaround:

instead of php mkdir you can create directories by FTP with proper rights.

    function FtpMkdir($path, $newDir) {
       $path = 'mainwebsite_html/'.$path;
       $server='ftp.myserver.com'; // ftp server
       $connection = ftp_connect($server); // connection


       // login to ftp server
       $user = "[email protected]";
       $pass = "password";
       $result = ftp_login($connection, $user, $pass);

       // check if connection was made
       if ((!$connection) || (!$result)) {
          return false;
          exit();
       } else {
         ftp_chdir($connection, $path); // go to destination dir
         if(ftp_mkdir($connection, $newDir)) { // create directory
             ftp_site($connection, "CHMOD 777 $newDir") or die("FTP SITE CMD failed.");
             return $newDir;
         } else {
           return false;
         }

         ftp_close($connection); // close connection
      }

  }  
空宴 2024-07-15 08:44:20

您可以通过 .htaccess 文件(如果在 Apache 上)关闭特定目录的安全模式。

php_value safe_mode = Off

您可能需要让您的托管提供商在 httpd.conf 中为您进行此更改。

You might be able to turn safe mode off for a specific directory via a .htaccess file (if on Apache).

php_value safe_mode = Off

You might need to get your hosting provider to make this change for you though in the httpd.conf.

神也荒唐 2024-07-15 08:44:20

我在将上传目录的组位设置为粘性方面取得了一些成功。
然后 PHP 可以在其中创建目录并写入内容。

http://en.wikipedia.org/wiki/Setuid#setuid_and_setgid_on_directories

chmod g+s 目录

I have had some success with setting the group bit of the upload directory to sticky.
PHP can then create directories inside it and write to it.

http://en.wikipedia.org/wiki/Setuid#setuid_and_setgid_on_directories

chmod g+s directory

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文