可以在未找到的消息中插入文本

It's possible to inject text in the not-found message

可以在未找到的消息中插入文本,以诱骗用户访问网站或做一些攻击者可能感兴趣的事情。

它正在返回未找到消息正文中的用户输入。这可能会以多种方式被滥用。

  1. 攻击者注入文本可以将用户重定向到恶意站点。
  2. 攻击者注入文本可以向用户提示虚假消息。

概念验证:

https://drupal7.example/.htcaccess/***Attention!***%2f../Site%20has%20been%20replace%20by%20a%20new%20one%20https://www.google.com%20so%20go%20to%20the%20new%20one%20since%20this%20one

在其他一些情况下,例如

https://drupal7.example/htaccess // without dot for example

一切都很好并且

# Make Drupal handle any 404 errors.                                                                                                               
ErrorDocument 404 /index.php

.htaccess 文件按预期工作,Drupal 处理所有 404 错误。

知道如何解决这个问题并让 Drupal 处理所有 404 错误,包括示例中的错误吗?

此行为是由于 URL 中存在 %2F(编码斜杠 /)。

Apache 使用 AllowEncodedSlashes 指令来确定是否允许通过 URL 中的编码路径分隔符。默认为 Off,在这种情况下,当您在 URL 中有 %2f 时,获取 Apache 404 而不是 Drupal 404 是 "normal" :

The AllowEncodedSlashes directive allows URLs which contain encoded path separators (%2F for / and additionally %5C for \ on accordant systems) to be used in the path info.

  • Off : such URLs are refused with a 404 (Not found) error.

  • On : such URLs are accepted, and encoded slashes are decoded like all other encoded characters.

  • NoDecode : such URLs are accepted, but encoded slashes are not decoded but left in their encoded state.

默认值为 Off 因为让 Apache 盲目解码路径分隔符会使您的计算机暴露于 目录遍历 攻击(参见 CVE-2007-0450),将此指令设置为On 不安全。

希望 NoDecode 选项(自版本 2.3.12 起可用)允许在不暴露您的服务器的情况下接受这样的 URLs,因此要修复它并让 Drupal 在 404 或无论如何,只需在 httpd.conf 中添加指令:

AllowEncodedSlashes NoDecode

注意:虚拟主机不会从全局上下文继承此指令,需要在虚拟主机容器中将指令重置为所需值,否则它将采用默认值.

现在,如果您仍然得到服务器 404 而不是 drupal 404,那可能是因为指令 ErrorDocument 404 未被考虑在内,或者在某处被覆盖。

检查此指令是否实际加载的一种快速方法是准确地设置静态内容(顺便说一下,在这种情况下没有输入显示问题;):

ErrorDocument 404 "Page not found"

也许 Apache 的正确行为是将这种 url 捕获为 403,并让 drupal 处理它,您可以设置 ErrorDocument 403 /index.php

还值得注意的是,通用 drupal 404 "page not found" 页面可以在 admin/config/system/site-information 以及 403 "access denied" 页面轻松覆盖。