Pentesting Drupal
Drupal is written in PHP and supports using MySQL or PostgreSQL for the backend.
Important Drupal files and directories
A Drupal website can be identified in several ways, including by the header or footer message Powered by Drupal, the standard Drupal logo, the presence of a CHANGELOG.txt file or README.txt file, via the page source, or clues in the robots.txt file such as references to /node.
Another way to identify Drupal CMS is through nodes. 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>
.
Version
It does not work on all versions:
Make sure to heck the CVE associated at: https://www.cvedetails.com/vulnerability-list/vendor_id-1367/product_id-2387/Drupal-Drupal.html
Users
Drupal supports three types of users by default:
- Administrator: This user has complete control over the Drupal website.
- Authenticated User: These users can log in to the website and perform operations such as adding and editing articles based on their permissions.
- Anonymous: All website visitors are designated as anonymous. By default, these users are only allowed to read posts.
Leveraging the PHP Filter Module
Unlike some CMS', obtaining a shell on a Drupal host via the admin console is not as easy as just editing a PHP file found within a theme or uploading a malicious PHP script.
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." From here, we could tick the check box next to the module and scroll down to Save configuration
. Next, we could go to Content --> Add content and create a Basic page
.
From version 8 onwards, the PHP Filter module is not installed by default. To leverage this functionality, we would have to install the module ourselves. Since we would be changing and adding something to the client's Drupal instance, we may want to check with them first. We'd start by downloading the most recent version of the module from the Drupal website.
Once downloaded go to Administration
> Reports
> Available updates
.
From here, click on Browse, select the file from the directory we downloaded it to, and then click Install.
Uploading a Backdoored Module
Drupal allows users with appropriate permissions to upload a new module. A backdoored module can be created by adding a shell to an existing module.
1. Download the archive and extract its contents.
2. Create a PHP web shell with the contents:
3. 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.
4. 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.
5. 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.inlanefreight.local/admin/modules/install Browse to the backdoored Captcha archive and click Install.
Drupalgeddon
CVE-2014-3704 known as Drupalgeddon, affects versions 7.0 up to 7.31 and was fixed in version 7.32. This was a pre-authenticated SQL injection flaw that could be used to upload a malicious form or create a new admin user.
Download from: https://www.exploit-db.com/exploits/34992
Once logged in as admin, try to obtain a shell.
Drupalgeddon2
CVE-2018-7600, also known as Drupalgeddon2, is a remote code execution vulnerability, which affects versions of Drupal prior to 7.58 and 8.5.1. The vulnerability occurs due to insufficient input sanitization during user registration, allowing system-level commands to be maliciously injected.
Download from: https://www.exploit-db.com/exploits/44448
We can check quickly with cURL
and see that the hello.txt
file was indeed uploaded.
Now let's modify the script to gain remote code execution by uploading a malicious PHP file.
Output:
Next, let's replace the echo
command in the exploit script with a command to write out our malicious PHP script.
Now, run the script:
And to get the reverse shell running, browse to:
Drupalgeddon3
CVE-2018-7602, also known as Drupalgeddon3, is a remote code execution vulnerability that affects multiple versions of Drupal 7.x and 8.x. This flaw exploits improper validation in the Form API.
It requires a user to have the ability to delete a node. We can exploit this using Metasploit, but we must first log in and obtain a valid session cookie. Once we have the session cookie, we can set up the exploit module as follows.