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

标签 .htaccess security drupal drupal-7

可以在未找到的消息中注入(inject)文本,以欺骗用户,让他访问网站或执行攻击者可能感兴趣的操作。

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

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

概念验证:

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 是“正常”的:

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 起可用)允许接受此类 URL,而无需暴露您的服务器,因此要修复此问题并让 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“找不到页面”页面可以在 admin/config/system/site-information 中轻松覆盖,以及 403“访问被拒绝”页面.

关于.htaccess - 可以在未找到的消息中插入文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57039846/

相关文章:

php - 使用 php 和 .htaccess 进行友好的 url 重写。相对链接到 css 图像和 js 的困难

security - 将安全信息从一台服务器传递到另一台服务器

php - Flash 和 PHP 脚本之间的安全通信

php - PHP中可以嵌入Python吗?

php - Drupal 7 中默认图像的 fid - Managed_file 字段。 fid的默认值设置为什么?

javascript - 使用 .htaccess 和 javascript 处理 404?

apache - 大规模虚拟托管和重写规则导致递归内部重定向

regex - .htaccess 仅允许来自 Chrome、Opera、Mozilla、Safari,从其他重定向

security - 无状态模式如何影响 Play! 中的安全性?框架?

drupal - 获取所有登录用户