阻止执行上传的php文件?
在我的项目中,允许用户上传任何类型的文件。我需要确保安全性,以防止执行可由 php 解析的上传文件(*.php、*.html 等)。
有没有办法告诉 apache 不要在 web/uploads 中解析任何带有 php 的文件,并将它们简单地显示为纯文本?还有什么其他选择?
In my project users are allowed to upload files of any type. I need to ensure security against execution of uploaded files that can parsed by php (*.php, *.html, etc.)
Is there a way to tell apache not to parse any files with php in web/uploads and simply display them as plain text? What are other options?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将它们全部保存在同一文件夹下,并在目录的
.htaccess
文件中设置此行:这还将处理其他漏洞,例如在 .gif 文件中嵌入 PHP 代码。
Keep them all under the same folder and set this line in the directory's
.htaccess
file:That will also take care of other exploits such as embedding PHP code in .gif files.
您需要 Apache SetHandler 指令: http://httpd.apache.org/ docs/current/mod/core.html#sethandler
这使您可以强制目录中的所有文件由特定处理程序处理。因此,大致如下:
应该做你想做的事。
You want the Apache SetHandler directive: http://httpd.apache.org/docs/current/mod/core.html#sethandler
This lets you force all files in a directory to be processed by a certain handler. So something along the lines of:
should do what you want.
为什么不在上传到
.phps
时重命名文件扩展名呢?澄清 PHPS 是 PHP 文件的源代码视图:
澄清:
file.php
=>file.phps
快速谷歌示例:
why not just rename the file extensions upon upload to
.phps
?To clarify PHPS is the source code view of a PHP file:
To clarify:
file.php
=>file.phps
quick google example: