【问题标题】:Ensuring security of files in folder on public_html确保 public_html 文件夹中文件的安全性
【发布时间】:2013-04-22 20:50:17
【问题描述】:

我的 public_html 中有一个图像目录结构,如下所示:

public_html/
   design_images/
       product_11/
           112342_234/ ... a bunch of images stored here for this product
           112343_910/ ... images for this product
           more image folders/...
           ...

public_html 文件夹中,我在产品文件夹中有用于图像处理和PDF 转换的php 文件。我只是担心有人可能会以某种方式在某处注入一些脚本并删除其中一个产品文件夹。我将所有这些目录保存在 public_html 上,因为我经常需要在整个网站中动态显示产品文件夹中的图像。

我怎样才能避免这种情况?我在虚拟服务器上使用 Apache,并且可以访问我的托管包中的 root。

我在 public_html/js 中也有 javascript 文件,是否有任何流氓来编辑它们?

【问题讨论】:

标签: php apache security directory-structure


【解决方案1】:

移出私有 html 文件夹并制作一个类似(伪)的脚本:

加载图片.php

<?
$imageName = $_GET['image']
$file = (abstract folder name and file name from $imagename)
$file = (sanatize all variables before passing it to the filesystem)

$sizeAndType = getimagesize($file);
header('Content-Type:'.$sizeAndType['mime']);
header('Content-Length: ' . filesize($file));
readfile($file);

并使用 www.example.com/loadimage.php?image=product_1234_something.jpg 调用(或者您选择构建名称。

那么最好用 mod_rewrite 编写一个 htaccess 来清理 url,这样你就可以使用旧的,或者更好的 url 构建。

但是,这并不能保护您免受一切伤害。您仍然需要确保服务器的其余部分没有像 777 公用文件夹等严重漏洞。

【讨论】:

  • 我确实有一个 777 公用文件夹。有什么办法只允许我自己的php文件访问这些文件夹,而不允许其他人访问它们?
  • 不,不要只让您的文件访问它。但真正的危险是apache可以将文件放入其中。所以人们可以把文件放在那里并执行。所以如果你有任何公共 777 文件夹,至少用 .htaccess 屏蔽它们
  • 我刚刚意识到我没有公共 777 文件夹,它们是 755。这些文件夹中的文件是 644。可以吗?
  • 是的,没关系,它提供读取和执行权限,但不提供写入权限
  • 在这种情况下 - 我现在看到我所有的图像文件夹也是 755。是否仍然存在有人删除这些文件夹的危险,是否仍然建议将这些文件夹移出 public_html?
猜你喜欢
  • 1970-01-01
  • 2016-02-17
  • 2021-12-22
  • 2011-06-05
  • 1970-01-01
  • 1970-01-01
  • 2018-06-29
  • 2010-09-07
  • 1970-01-01
相关资源
最近更新 更多