如果某人具有全局读/写权限,是否可以在服务器上读取或写入我的 .php 文件?

发布于 2024-11-11 15:12:30 字数 160 浏览 1 评论 0原文

如果我将 PHP 文件设置为 chmod 777,有人可以窃取或更改它们吗?

我有一个 EC-2 实例,即使我以 EC2 用户身份登录,如果我将它们设置为 chmod 755,我也无法更改我的文件。仅当我将文件设置为 chmod 777 时,我才能对文件进行更改。

Can someone steal or change my PHP files if I have set them to chmod 777?

I have an EC-2 instance and even when I'm logged in as EC2-user I cant change my file if I have set them to chmod 755. I can only make changes to the file when I have set them to chmod 777.

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

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

发布评论

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

评论(4

最冷一天 2024-11-18 15:12:30

是的,也不是。任何通过网络查看文件的人都可以吗?不可以。但是,任何能够登录到您的计算机的人都可以更改这些文件(因为它们是全世界可读/可写的)。一般来说,这不是一个好的做法。我建议不要允许超过 775。如果您处于托管环境中,这应该不是问题。

Yes and no. Can anyone who is viewing the files over the net? No. However, anyone with the ability to log on to your machine could change the files (since they are world readable / writable.) In general, this isn't a good practice. I'd advise not permitting more than 775. If you are in a hosted environment, this shouldn't be a problem though.

天荒地未老 2024-11-18 15:12:30

其实这里大家都错了,755 for a file 是非常错误的。

这意味着,由所有者读/写/执行。
由小组和其他人阅读/执行。

目录应该是 755,因为目录上的执行位意味着用户可以列出其内容,因为您显然无法执行目录。

执行对于网络托管脚本没有意义,因为执行位仅由 shell 解释,而不是 php。

简而言之,目录最多应为 755 (rwx,rx,rx),文件应最多为 644 (rw,r,r)。

如果他们对您的文件具有全局读取访问权限,您的文件很容易在共享托管环境中被盗。

可以通过三种方式使用 PHP 配置 Web 主机

  1. 作为 apache 模块(无论如何,所有脚本都以同一用户身份运行)
  2. 作为监狱/chroot 中的 CGI 二进制文件(可以以同一用户身份运行,但文件会被其他文件锁定)文件系统的文件系统,因此其他人无法访问它们,您也无法访问他们的文件系统)
  3. 使用SuExec或suPHP(php作为网站所有者运行)

如果您的主机作为模块运行(1),那么您的文件必须是664并且目录 755,服务器上的每个人都可以读取。

如果您的主机在监狱/chroot (2) 中运行,那么您的文件可能必须为 664,目录必须为 755,但它们受到保护。

如果您的主机使用suExec或suPHP,那么您的php文件应该是640,目录应该是750,否则其他人可以访问您的脚本。您甚至可以将其进一步限制为 600 和 700,但 apache 仍然需要读取纯文件(而不是脚本),因此您需要更进一步并确保这些文件归您所有,但在Web 服务器运行的组。

Actually, everyone here is incorrect, 755 for a file is very wrong.

This means, read/write/execute by the owner.
read/execute by the group and everyone else.

Directories should be 755 as the execute bit on a directory means that the user can list its contents, as you obviously cant execute a directory.

Execute does not make sense for webhosting scripts as the execute bit is only interpreted by the shell, not php.

In short, directories should be at the most, 755, (rwx,rx,rx), files should be 644 (rw,r,r).

Your files can be stolen in a shared hosting environment very easily if they have global read access to your files.

There are three ways the webhost can be configured with PHP

  1. As an apache module (all scripts run as the same user regardless)
  2. As a CGI binary in a jail/chroot (may run as the same user, but the files are jailed from the rest of the filesystem, so others cant access them, and you cant access theirs)
  3. Using SuExec or suPHP (php is run as the owner of the website)

If your host is running as a module (1), then your files must be 664 and directories 755, and are readable by everyone on the server.

If your host is running in a jail/chroot (2), then your files probably have to be 664 and directories 755, but they are protected.

If your host is using suExec or suPHP then your php files should be 640 and directories 750, otherwise others can access your scripts. You may even be able to restrict it further to 600, and 700, but apache still needs to read the plain files (not scripts), so you need to take this one step further and make sure the files are owned by you, but in the group the web-server is running as.

寂寞陪衬 2024-11-18 15:12:30

如果他们有权访问您的服务器并拥有有效的用户名/密码,他们就可以修改/窃取您的文件。 chmod 777 允许任何人读取和写入您的文件(以及执行它们)。

因此,例如,如果您将网站托管在共享服务器上,则该服务器上运行的其他网站将能够访问您的文件并修改它们,即使它们在不同的用户上下文中运行也是如此。

They can modify / steal your files if they have access to your server and have a working username / password. chmod 777 lets anyone read and write to your files (as well as execute them).

So, for example, if you're hosting your website on a shared server, other websites running on that server would be able to access your files and modify them, even though they run in a different user context.

枫以 2024-11-18 15:12:30

偷是的
如果你不使用 .htacces 是的:)
为什么使用 chmod 777 ?

更新
任何人都可以下载文件吗?
wget http://xxx.xxx/update.php~ 有效

Steal yep
If your not use .htacces yeah :)
Why you use chmod 777 ?

UPDATE
anyone can download file no ?
wget http://xxx.xxx/update.php~ works

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