☰
WEB SECURITY / PRACTICE

Auditing and Securing WordPress Must-Use Plugins

Auditing and Securing WordPress Must-Use Plugins

The wp-content/mu-plugins directory contains must-use plugins—special WordPress modules that load automatically. They do not appear in the standard plugin list and usually cannot be disabled from the administration panel.

This mechanism is useful for system integrations, caching, environment control, and corporate policies. At the same time, mu-plugins are convenient for persistence of malicious code: a file can remain unnoticed during a superficial audit even if the administrator has checked regular plugins.

What Are Mu-Plugins and Why Do They Require a Separate Audit?

WordPress must-use plugins are primarily stored in the wp-content/mu-plugins directory. WordPress automatically loads PHP files from this directory during startup. As a result, such a module may run on every request before an administrator even opens the regular plugin management page.

It is important to account for the directory structure. WordPress generally detects PHP files located directly in the mu-plugins root. If a module is placed in a subdirectory, a separate loader file in the root is often used to load it. For this reason, you must check not only filenames but also all subdirectories and related loaders.

The presence of an mu-plugin does not by itself indicate an infection. It may have been installed by a hosting provider, deployment system, developer, or legitimate optimization package. The purpose of an audit is to establish the origin, function, and compliance of each file with the expected configuration.

  • the regular plugin list is not a complete inventory of the PHP code executed by WordPress;
  • mu-plugins do not always have a clear name or settings page;
  • accidentally deleting a system module can break caching, authentication, deployment, or integrations.

How to Perform an Initial Directory Inventory

Start by creating a backup of the files and database. For an investigation, it is better to preserve a copy in a separate location without overwriting the suspicious file. Record the audit date, domain, WordPress version, active theme, regular plugins, and the site's deployment method.

Next, create a complete list of files in wp-content/mu-plugins, including hidden files, subdirectories, archives, and files with unusual extensions. Pay particular attention to PHP files that have no obvious connection to a known module.

  • compare the list with hosting documentation, the repository, or the deployment manifest;
  • check creation or modification dates if the filesystem preserves them;
  • record the owner, group, and access permissions;
  • check whether files appeared at the same time as suspicious changes to the theme, regular plugins, or server configuration;
  • save cryptographic hashes of known legitimate files for later comparison.
find wp-content/mu-plugins -type f -printf '%M %u:%g %TY-%Tm-%Td %TH:%TM %p\n' | sort

Checking PHP Code for Signs of Compromise

Searching for dangerous functions is useful as a quick filter, but it is not proof of an infection. eval or base64_decode may appear in legitimate software, although their presence in a small system module requires an explanation. Likewise, the absence of these terms does not guarantee safety: malicious code can be written without obfuscation or distributed across multiple files.

Check the context in which functions are called. Particularly suspicious are chains in which data from an HTTP request, cookie, header, or WordPress parameter is decoded and passed for PHP execution. Hidden HTTP requests, dynamic file inclusion, writing to wp-content, creating administrative users, and changing roles increase the risk.

Also check autoloading through require, include, spl_autoload_register, and searches for files based on variables. A malicious loader may look harmless while including code from another directory or from temporary files.

  • eval, assert with dynamic data, base64_decode, gzinflate, gzuncompress, str_rot13, and similar constructs;
  • long, unclear strings, encrypted arrays, and code that is difficult to read without an explanation;
  • calls to shell_exec, system, passthru, proc_open, or unsafe file operations;
  • requests to external domains without a clear business purpose;
  • creating users, changing passwords or roles, adding cron jobs, or modifying site settings without a documented reason.
grep -RInE 'eval[[:space:]]*\(|base64_decode|gzinflate|gzuncompress|shell_exec|passthru|proc_open|assert[[:space:]]*\(' wp-content/mu-plugins

How to Distinguish a Legitimate Mu-Plugin from a Malicious One

Evaluate the file based on the overall combination of indicators, not its name. A trustworthy module has a clear purpose, an identifiable author or source, a logical structure, comments or documentation, and matches records in the change-control system. A name such as cache.php or security.php does not prove legitimacy.

Compare the code with the repository version or with a reference copy supplied by the developer. If the file was installed by the hosting provider, ask the provider to confirm its origin and function. Do not rely solely on the modification date: an attacker may preserve an old timestamp, while a routine update or restoration from a backup may change it.

Test the module's behavior on a staging copy of the site. For sites using Elementor, it is especially important to test the editor, forms, AJAX requests, REST API, and authentication, because system code may interfere with request processing and access permissions.

  • whether the module exists in the repository or on the approved component list;
  • whether its hashes match the expected version;
  • whether the code explains the stated function without unnecessary actions;
  • whether the file appeared outside the deployment process;
  • whether its installation and removal can be reproduced in a test environment.

Access Permissions and Filesystem Protection

The web server generally needs permission to read PHP files, but not to modify them. Write access to wp-content/mu-plugins should be available only to the file owner or a controlled deployment process. If the PHP process can write to this directory, a vulnerability in any plugin or theme can be turned into the installation of a new mu-plugin.

The exact permissions depend on the server's user model, containers, and deployment process. Do not change them mechanically on every host: first determine which user runs PHP, who performs deployments, and whether the site uses a shared filesystem group.

  • restrict write access to mu-plugins for the web process;
  • use a separate deployment user with the minimum required privileges;
  • prohibit the execution or storage of unnecessary uploaded files in site directories;
  • check permissions, ownership, and group after every update;
  • protect backups and repositories from writes by the web server.
find wp-content/mu-plugins -type f -exec stat -c '%A %U:%G %n' {} \;

What to Do After Finding a Suspicious File

Do not delete the file immediately if there is no active attack requiring urgent isolation. First preserve a copy, hash, metadata, and access logs. This will help establish how the intrusion occurred and determine whether the attacker left other access mechanisms.

If a compromise is confirmed, restrict access to the site or put it into maintenance mode, change credentials after cleanup, and check all persistence points: wp-config.php, cron, the database, users, themes, regular plugins, uploaded files, and web server settings.

The most reliable recovery method is to deploy a clean version of WordPress, the theme, and plugins from trusted sources rather than simply deleting one suspicious file. Database data must be migrated carefully, with users, options, and inserted JavaScript checked.

  • isolate the suspicious file and do not run it again on the production site;
  • check login, FTP/SSH, hosting-panel, and deployment logs;
  • change administrator, database, SSH, FTP, and API key credentials;
  • check for unknown users, cron jobs, and database changes;
  • after cleanup, repeat the scan and document the cause of the incident.

Continuous Monitoring and Prevention

A one-time audit does not prevent the file from reappearing. Create an approved list of mu-plugins with each module's name, purpose, source, owner, hash, and support contact. Store this list in version control or another location protected from changes made by the web server.

Configure monitoring for changes in wp-content/mu-plugins. Notifications should be generated not only when PHP code changes, but also when files are created, renamed, or have their permissions modified. Verify these alerts through the deployment process: every planned change should have an author, a task, and an expected diff.

Update WordPress, Elementor, themes, and plugins regularly, but create a backup before updating and test compatibility. A vulnerability in a regular plugin can provide a path for writing a malicious mu-plugin, so auditing hidden modules does not replace general system updates.

  • prohibit direct changes on production where possible;
  • check hashes and diffs during CI/CD;
  • audit the site after suspicious redirects, spam, new administrators, or form changes;
  • restrict access to SSH, the hosting panel, and the WordPress administration area;
  • store logs and backups separately from the main server.

Frequently asked questions

Are all files in wp-content/mu-plugins dangerous?

No. They may be legitimate system modules for hosting, caching, deployment, or corporate integrations. They become suspicious when they have no clear source, the code does not match their stated purpose, they contain obfuscation, or they appeared without authorization.

Can an mu-plugin be deleted through the WordPress administration area?

Usually, mu-plugins are not managed through the standard list of regular plugins. They are removed at the filesystem level, but you should first create a backup, check dependencies, and test the consequences.

Is base64_decode proof of an infection?

No. This function can be used legitimately, but its presence in an mu-plugin requires especially careful review. The important factors are the call context, the data source, what happens to the result afterward, and whether it matches the stated function.

What access permissions are considered safe for mu-plugins?

There is no universal value for every server. The general principle is that the web process should be able to read the required files but should not be able to modify or create PHP files in the directory. Write access should be reserved for the owner or a controlled deployment process.

Conclusion

Must-use plugins are not inherently a hidden mechanism, but they are easily missed during a typical WordPress audit. Check the complete file inventory, origin, code, ownership, access permissions, and changes over time.

A secure practice combines backups, controlled deployment, least-privilege access, filesystem monitoring, and a preapproved list of mu-plugins. If a file is confirmed to be malicious, clean not only that file but also all persistence mechanisms and the possible intrusion path.

← All web security materials