php - 为什么特别锁定 PHP 中的 phar 写入支持?

标签 php security phar

PHP 有 phar.readonly 设置,默认启用,只能通过配置文件禁用。

This option disables creation or modification of Phar archives using the phar stream or Phar object's write support. This setting should always be enabled on production machines, as the phar extension's convenient write support could allow straightforward creation of a php-based virus when coupled with other common security vulnerabilities.

http://php.net/manual/en/phar.configuration.php

在这种情况下支持默认阻止写入的原因是什么?

在 PHP 中有更通用和更容易获得的方式来编写,Phar 的写入支持的“便利性”究竟是什么使得它从安全角度来看是危险的?

最佳答案

如果您需要在不设置只读的情况下写入,那么您可以使用 ZIP 或 GZ 容器。参见 Head-to-head comparison of Phar, Tar and Zip了解更多信息。

从黑客的角度来看,拥有 PHAR 只读有效地锁定了它。如果您的 PHP 的 Web 版本(mod_php、php-cgi 或其他)具有默认值,那么这将很难破坏基于 Phar 的应用程序,因为 phar.readonly=1 可以在执行期间被覆盖。

还有一个性能优势,因为文件仅打开 R/O,并且 Web 请求(本质上可以是并发的)可以在没有文件锁定的情况下访问和使用 Phar。

您通常会像@scribu 描述的那样使用 CLI 包装器在您的测试配置上构建 Phar,然后只需将 Phar 复制到相关应用程序目录即可将其安装在您可公开访问的 Web 服务上。

关于php - 为什么特别锁定 PHP 中的 phar 写入支持?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18811657/

相关文章:

php - 使用 phar Stream 写入 PharData 文件

javascript - 当用户复制和粘贴文本在 WordPress 中不起作用时链接回网站

php - MYSQL PHP API - 在另一个表的行中显示和获取多行

ios - 如何从 Swift 3 获取 MS Translator 访问 token ?

php Phar - mysql 连接在页面之间保持打开状态?

php - 如何在 phar 文件代码中获取 .phar 文件的真实目录?

php - 将 url 绑定(bind)到复选框值

php - 制作条件语句以发送电子邮件警报

c# - WCF 服务、Windows 身份验证

java - Android 设备 session 管理的最佳实践