如何禁用 PHP 的“复活节彩蛋”URL?

php
2022-08-30 09:11:51

我最近发现了PHP中所谓的“复活节彩蛋URL”

以下是可以添加到 PHP 网页末尾以查看(在某种程度上)隐藏图像或网页的四个 QUERY 字符串:

  1. ?=PHPE9568F36-D428-11d2-A769-00AA001ACF42

这是最有趣的,展示了一个“复活节彩蛋”图像,要么是房子里的兔子(斯特林休斯的兔子,名叫卡梅拉),草地上的棕色狗,一只黑色的苏格兰梗犬,一个草率的孩子手绘,蜡笔色的php标志,一个拿着面包棒(看起来像铅笔或炸薯条)的家伙像海象一样从嘴里伸出来, 或 PHP 大象徽标。

enter image description here

其他包括:

  • ?=PHPE9568F34-D428-11d2-A769-00AA001ACF42(PHP 徽标)
  • ?=PHPE9568F35-D428-11d2-A769-00AA001ACF42(Zend标志)
  • ?=PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000(PHP Credits)

我震惊地发现,这确实适用于许多网站,包括我自己的网站。我认为这是愚蠢的,并希望禁用它,但是从我听到的唯一方法是在php中.ini,并且不能在运行时设置。expose_php = Offini_set()

我无法直接访问live服务器上的php.ini。但是,我已经想出了如何在 中或在 PHP 代码中使用 Header unset X-Powered-By 来取消设置标头X-Powered-By.htaccessheader('X-Powered-By: ')

有没有其他方法可以禁用这些“复活节彩蛋”,或者我是否必须在主要设置中更改此设置(这确实是禁用这些URL的正确/唯一方法)?php.ini


答案 1

在 php 中.ini

; Decides whether PHP may expose the fact that it is installed on the server
; (e.g. by adding its signature to the Web server header).  It is no security
; threat in any way, but it makes it possible to determine whether you use PHP
; on your server or not.
; http://php.net/expose-php
 expose_php = Off

这将有效地去除复活节彩蛋


答案 2

快速的HTACCESS全局重写可以在每个URL中正则表达式确切的字符串,从而摆脱PHP中唯一有趣的部分,而无需触摸ini文件,也不需要在每个文件的开头都有一个函数。

尚未对此进行测试,但这应该有效:

RewriteEngine On
RewriteCond %{QUERY_STRING} \PHPE9568F36-D428-11d2-A769-00AA001ACF42\ [NC]
RewriteRule .* - [F]

当然,只需为每个可能的查询复制最后2行,或者编写一个更通用的正则表达式。我不擅长正则表达式。:)

这个版本涵盖了所有复活节彩蛋的乐趣,可以在这里找到:

RewriteEngine On
RewriteCond %{QUERY_STRING} \=PHP[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12} [NC]
RewriteRule .* - [F]

推荐