Hacked! - Review of a Module for Drupal
During a website audit, it is possible to detect whether changes have been made to the Drupal core, modules and contrib themes. How to do that? The most effective way to do this is to use the Hacked! module.
Dates
The module was released on 8 October 2009, and the last modification was introduced on 13 February 2020. Hacked! has a version for both Drupal 7 and 8.
Module's popularity
Drupal.org reports that the module is being used by approximately 16,000 pages of which 15,100 are Drupal 7 pages and 900 are Drupal 8 pages. In the case of the Hacked! however, this is not very reliable information, as it is a module that should only be used in development environments for a short time and should be uninstalled after the work is done. So, one could rather say that 16,000 pages have the module installed incorrectly.
Module's creators
The user ivnish is maintaining the Drupal 7 module. Nobody maintains it for Drupal 8 at the moment.
What is the module used for?
The Hacked! module is an indispensable tool in the work of every professional Drupal agency. At Droptica, every new webpage accepted for Drupal support is being scanned with the Hacked! module for changes in modules.
We carry out checks in order to find any manual modifications to the Drupal modules and core. There are several goals for finding such changes:
- If possible, the Drupal core and contrib modules should not be changed. Drupal is a very flexible system, and, in most cases, you can achieve the desired results by acting according to good practices. If we find changes introduced by previous teams in the code, we try to transfer them to our modules and implement them in accordance with the Drupal standards.
- If the changes cannot be introduced into our own code, we move them to the tracked patches to be able to track them automatically and apply them with every module update.
We follow the above steps to be able to update modules easily and quickly to the latest versions without the risk that we will remove or break any functionality that someone has hidden in a contrib module. At this point, I encourage you to read the article on how to Keep Your Website Safe And Up-To-Date With Drupal Support.
Without the Hacked! Module, we do not have easy insight into changes introduced to a given contrib module, and in the case of an update, tracking down the modifications without using this module will be time-consuming.
Unboxing
In order to install the Hacked! module, go to the project's page at drupal.org or use the Composer we wrote a separate article:
composer require drupal/hacked
After the installation, you can configure the module by going to
/admin/reports/hacked/settings
The module has one configuration option:
Ignore line endings/include line endings: Depending on the operating system on which the module was modified, line endings are being determined differently. Setting this option to "Ignore line endings" will ensure that all line ending coding differences will be ignored.
In other words: if the developer opens the file in Windows and saves it while "Include line endings" is selected in these settings, then differences in line endings will be listed during the file check.
Generating a change report
After installing the module, go to
/admin/reports/hacked/check
or use the drush command:
drush hacked-list-projects
alias:
drush hlp
The report generation process takes up to several minutes, depending on the number of files to be checked.
Review of changes
The Hacked! module provides a page with the report. We can find it under:
/admin/reports/hacked
or by going to the "reports" tab in the admin menu, and then using the "hacked" link
In the given example, you can see that the module "Better exposed filters" contains some changes. Let us check them out:
If you have the additional Diff module, you can easily see the exact changes in each file:
Changes can also be observed using drush commands. In order to list the modules containing changes, use the command:
drush hlp
In order to list the names of the files containing changes, type:
drush hacked-details [the module machine name]
or use the alias:
drush hd [the module machine name]
In order to list the modifications in individual files in a given module, use the command:
drush hacked-diffd [the module machine name]
which will return changes between files in the same way that the git diff command does
Changes to the sample file:
Alternative modules
There are several file integrity checking modules, including MD5 Check, File Integrity Check, but they are not widely used. MD5 Check generates a checksum for files and on this basis informs the admin about changes. File Integrity Check, on the other hand, creates a "fingerprint" of the entire page and informs the admin if there are modifications to it.
Extension modules
We recommend installing the Diff module, which allows one to clearly track the changes between the current version of the file and the one downloaded by the Hacked! module.
Summary
The Hacked! module solves the problem of searching for modifications in the Drupal core and contrib module files. It provides a functionality which, in combination with the Diff module, allows you to see the differences between the original and modified files clearly.