PHP安全信息问题


php secure info issues

嗨,我正在运行PHP安全信息,我得到以下问题。

Warning
allow_url_fopen is enabled. This could be a serious security risk. You should disable allow_url_fopen and consider using the PHP cURL functions instead.
Current Value:  1
Recommended Value:  0

谁能解释一下我该如何解决这个问题?

Warning
PHP may be executing as a "privileged" group, which could be a serious security vulnerability.
Current Value:  99
Recommended Value:  100
Warning
PHP may be executing as a "privileged" user, which could be a serious security vulnerability.
Current Value:  99
Recommended Value:  100

我喜欢人们花时间保护你的PHP设置;所以感谢你!

是的,您应该关闭allow_url_fopen,因为这将使您在执行远程脚本时面临许多安全问题。你可以编辑php。ini文件;通常位于/etc/php.ini,但只是为了确保检查你的phpinfo(),看看它在哪里说"加载的配置文件"。找到它后,更改以下值:

allow_url_fopen = 0

至于PHP作为"特权"组执行,您需要检查您的apache用户与哪个组相关联。如果您有shell访问权限,您可以通过命令行执行此操作:

id {username}

其中{username}是您的apache用户名…可以是"apache"可以是"php"可以是"www-data"等等。建议apache用户在自己的用户组中:

apache.apache
要做到这一点,您可以使用以下命令:
useradd -G {group-name} username

所以它看起来像:

useradd -G apache apache

第一条消息的意思就是它所说的,allow_url_fopen在你的php.ini中是启用的,它允许基于fopen的函数打开URL,例如:

fopen('http://www.example.com/somefile.txt');

恶意用户可以使用这个来加载他们的远程文件到你的web服务器。

第二个消息块意味着您正在以"特权"用户(在大多数情况下是root用户)的身份运行PHP解释器(很可能是通过您的web服务器,如Apache或nginx)。这是一个非常糟糕的主意,因为该用户具有无限的系统访问权限,然后您将其传递给web服务器。这将使你的web服务器上的任何安全漏洞给任何入侵者完全的root访问权限。

因此,如果你想要这些消息被修复,可以做两件事:

  1. 在php.ini中设置allow_url_fopen为0。
  2. 确保你不以root用户启动你的web浏览器,而是像www-data或apache这样的用户(在大多数系统中,apache是通过包管理器安装的)。