文件上传安全 - chmod 执行限制不起作用
在网络应用程序中,我有一个上传文件夹,其中存储了所有用户的文件,我需要消除执行它们的可能性。
正如维基百科中所见:
chmod -R a-x+X 目录
删除目录树中所有文件的执行权限,同时允许目录浏览。
但是,在成功地将其应用到上传文件夹后,当我在浏览器中打印它们的地址时,我出于测试目的而放置在那里的所有随附的 php、perl 和 python 脚本(并且我怀疑所有其他类型的可执行文件)确实会被执行。
为什么会发生这种情况?我可以采取什么措施来解决这个问题?
In a web application I have an upload folder where all users' files are stored, I need to eliminate the possibility of executing them.
As seen in Wikipedia:
chmod -R a-x+X directory
remove the execute permission on all files in a directory tree, while allowing for directory browsing.
But after successfully applying this to upload folder all the enclosed php, perl and python scripts that I've placed there for test purposes (and I suspect all the other types of executable files) do get executed when I print their addresses in browser.
Why is this happening and what can I do to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
perl、php 和 python 解释器都会愉快地执行传递给它们的输入文件,无论其输入文件的执行权限位是否打开。 (在
另一方面,如果文件有一个 shebang 行指定要使用哪个解释器,
将尊重执行权限。但情况可能并非如此
你的情况。)
你必须通过配置你的网络服务器来解决这个问题(限制
它认为可执行的目录),而不是在文件系统级别。
如果您使用 Apache,您可能需要查看 ScriptAlias 指令,
在全局配置或本地 .htaccess 文件中,如此处所述。
The perl, php, and python interpreters will happily execute input files passed to them, whether the execute permission bit for their input files is turned on or not. (On
the other hand, if the file has a shebang line specifying which interpreter to use,
the execute permission will be respected. But that is probably not the case for
your situation.)
You'll have to address this issue by configuring your web server (restricting
the directories that it considers executable), rather than at the filesystem level.
If you're using Apache, you'll probably want to look at the ScriptAlias directive,
either in the global configuration or local .htaccess files, as described here.