Critical Vulnerabilities in PHP Everywhere Allow Remote Code Execution
The PHP Everywhere WordPress plugin allowed users with low privileges, such as subscribers, to execute arbitrary PHP code via a shortcode, and contributors to execute code via a metabox or Gutenberg block. An attacker with an account could run code on the server, leading to complete site takeover.
wordfence.com
Published on wordfence.com
On January 4, 2022, the Wordfence Threat Intelligence team began the responsible disclosure process for several Remote Code Execution vulnerabilities in PHP Everywhere, a WordPress plugin installed on over 30,000 websites. One of these vulnerabilities allowed any authenticated user of any level, even subscribers and…
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
PHP Everywhere is a WordPress plugin whose stated purpose is to let site owners execute PHP code anywhere on their site. Among its features, it allowed PHP code snippets to be embedded through WordPress shortcodes, through a metabox in the post editor, and through a Gutenberg block. The plugin slug is php-everywhere, it was developed by Alexander Fuchs, and at the time of disclosure it was installed on over 30,000 websites.
The vulnerabilities described here were found and reported by Ramuel Gall of the Wordfence Threat Intelligence team. Three separate issues were disclosed, all affecting versions <= 2.0.3 and all fixed in version 3.0.0. Each carries a CVSS score of 9.9 (Critical) with the vector CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H.
| CVE | Vector into the plugin | Minimum privilege |
|---|---|---|
| CVE-2022-24663 | Shortcode | Subscriber or Customer |
| CVE-2022-24664 | Metabox | Contributor (edit_posts) |
| CVE-2022-24665 | Gutenberg block | Contributor (edit_posts) |
Setup
The disclosure process began on January 4, 2022. The Wordfence team contacted the WordPress plugin repository with the disclosure in addition to reaching out to the plugin author directly. The author responded within a few hours, and the full disclosure was sent at that point. A largely rebuilt version of the plugin, 3.0.0, was released on January 10, 2022.
On the defensive side, Wordfence Premium users received a firewall rule protecting against these vulnerabilities on January 4, 2022. Wordfence Care and Wordfence Response customers received the rule immediately upon subscription. Sites on the free version of Wordfence received the same protection 30 days after the initial release, on February 3, 2022.
The exploitation conditions differ per vulnerability. The shortcode issue needs only an authenticated account of any level, including a Subscriber or a Customer. The metabox and block issues need the edit_posts capability, which by default the plugin granted to all users holding it, meaning Contributor-level accounts and above.
Finding it
The core observation is about how WordPress handles shortcodes. WordPress allows any authenticated user to execute shortcodes via the parse-media-shortcode AJAX action, and some plugins also allow unauthenticated shortcode execution. PHP Everywhere registered a shortcode that executes PHP. Combining the two means that the shortcode's code execution is reachable by any logged-in user, regardless of what that user is otherwise permitted to do.
For the other two vectors, the problem is the default capability check. The plugin allowed all users with the edit_posts capability to use the PHP Everywhere metabox, and by default also allowed them to use the PHP Everywhere Gutenberg block. It was possible to restrict this to admin-only, but that was not the default, because versions <= 2.0.3 could not add capability checks without disabling the Gutenberg Block editor. The Wordfence team worked with the plugin author to overcome that limitation when sending the disclosure.
Exploitation
Step 1: Shortcode execution as a low-privileged user (CVE-2022-24663)
A logged-in user, even one with almost no permissions such as a Subscriber or a Customer, sends a request to the parse-media-shortcode AJAX action with the shortcode parameter set to the PHP Everywhere shortcode wrapping arbitrary PHP:
[php_everywhere]<arbitrary PHP>[/php_everywhere]
The shortcode parameter carries the payload; WordPress parses it through the shortcode system, PHP Everywhere's handler evaluates the enclosed PHP, and the result is arbitrary PHP execution on the site. Executing arbitrary PHP on a WordPress site typically allows complete site takeover.
Step 2: Metabox execution as a Contributor (CVE-2022-24664)
A user with the edit_posts capability, such as a Contributor, creates a post, adds PHP code to the PHP Everywhere metabox, and then previews the post. The preview triggers evaluation of the code in the metabox, giving code execution on the site.
Step 3: Gutenberg block execution as a Contributor (CVE-2022-24665)
A user with the edit_posts capability creates a post, adds the PHP Everywhere block, adds code to it, and previews the post. As with the metabox, the preview executes the code.
Root cause
The plugin's design goal is to execute PHP supplied by users, so the security boundary has to be who is allowed to supply that PHP and through which path. Two mistakes break that boundary.
First, the shortcode path inherits WordPress's shortcode execution model. Because WordPress lets any authenticated user run shortcodes through parse-media-shortcode, and some plugins allow unauthenticated shortcode execution, a shortcode that evaluates PHP is effectively an unauthenticated or any-authenticated-user code execution primitive. The plugin did not account for this.
Second, the metabox and block paths defaulted to allowing everyone with edit_posts, rather than restricting the feature to administrators. The report states that admin-only was possible to configure but was not the default, because versions <= 2.0.3 could not add capability checks without disabling the Gutenberg Block editor. That constraint is why the default was left open, and the limitation was overcome together with the author during disclosure.
Impact
All three issues allow arbitrary PHP execution, which typically means complete site takeover. The shortcode issue requires only Subscriber or Customer level access, the lowest rung of authenticated users. The metabox and block issues require Contributor-level permissions, which imply some degree of trust and are more difficult to obtain than subscriber-level permissions; the report notes that they carry the same CVSS score as the shortcode issue but are less severe for that reason, and that the CVSS scoring system does not allow "Medium" in the "Privileges Required" field.
The report describes the vulnerabilities as very easy to exploit and usable to quickly and completely take over a site.
Fix
Version 3.0.0, released on January 10, 2022, is the fully patched version for all three CVEs. The report describes it as a largely rebuilt version of the plugin. One limitation is stated explicitly: 3.0.0 only supports PHP snippets via the Block editor, so users of the Classic Editor need to uninstall the plugin and find another solution. Older versions should not be run under any circumstances.
On the network side, a firewall rule was released on January 4, 2022 for Wordfence Premium, Care and Response customers, and became available to free Wordfence users on February 3, 2022.
Variants to test
- Other plugins registering PHP-evaluating shortcodes. Search installed plugins for
add_shortcodehandlers that calleval, include user-supplied files, or otherwise interpret their content as code. A positive result is that a Subscriber account can send the shortcode throughparse-media-shortcodeand observe its output or side effect. - Shortcode execution reachable without authentication. The report notes that some plugins allow unauthenticated shortcode execution. Test shortcode-bearing endpoints while logged out; a positive result is code output or a side effect from an unauthenticated request.
- Editor features gated on
edit_postsrather thanmanage_options. Look for metaboxes and blocks that execute code or perform privileged actions and check their default capability. A positive result is a Contributor being able to trigger the feature through a post preview. - Preview as the trigger. For any editor-integrated feature that runs code, create a draft and preview it with a low-privileged account. A positive result is execution occurring at preview time, before any publish or review step.
- Capability defaults that can be tightened but are not. Where a plugin offers an admin-only setting, check its out-of-the-box value on a fresh install. A positive result is the permissive default being active without configuration.
What happened, in plain words
A plugin called PHP Everywhere, used on more than 30,000 WordPress websites, let people run PHP code on a site. PHP is the programming language WordPress itself is written in, and code that runs on the server can do almost anything: read files, change settings, take the site over. The plugin's whole purpose was to let a site owner put PHP snippets into pages, so the question that mattered was who else could get their code run.
The answer turned out to be almost anyone. The Wordfence Threat Intelligence team found three separate ways into the plugin, all fixed in version 3.0.0. One of them needed only a Subscriber or Customer account, the lowest level of authenticated user. From there, an attacker could run their own code on the server.
This article walks through what the plugin does, what went wrong, how each of the three problems could be triggered, and what to do if you run the plugin. It is written for someone who uses a browser and a computer and has never studied security.
Some background first
What WordPress is
WordPress is a system for building websites. You install it on a web server (a computer that answers requests from browsers), and it gives you an admin area where you write posts and pages. The content you write is stored in a database, and when a visitor opens a page, WordPress assembles it from that stored content and sends it back.
What a plugin is
A plugin is an add-on. WordPress on its own does the basics; plugins add features, like a contact form, a shop, or in this case the ability to run PHP. You install a plugin by dropping it into your WordPress installation, and it then runs as part of your site. Plugins are written by third parties, so their quality and their security vary.
What PHP is
PHP is a programming language that runs on the web server, not in your browser. When you load a page, the server runs PHP to build the page and sends the result. Because it runs on the server, PHP code can read and write files, talk to the database, and send email. That is why running someone else's PHP is dangerous: it is not a picture or a comment, it is instructions to the machine that holds your site.
What a shortcode is
A shortcode is a small tag you type into a post that WordPress replaces with something else when the page is shown. It looks like a word in square brackets. For example, a plugin might give you a tag that, when the page is displayed, is swapped for a photo gallery or a button. The site owner writes the tag; WordPress and the plugin do the work of turning it into output.
What a metabox and a block are
When you edit a post in WordPress, the screen has the main text area plus smaller panels around it. Those panels are called metaboxes. A plugin can add its own panel, for example one where you type PHP.
A block is the newer way WordPress lets you build posts. Instead of one big text area, you add separate pieces (a paragraph, an image, a quote), and each piece is a block. A plugin can add a new kind of block, for example a PHP block.
What an AJAX action is
A web page can talk to the server without reloading. When you click something and a small part of the page updates, the browser has sent a request in the background. WordPress calls these background requests AJAX actions, and each one has a name. One of them is called parse-media-shortcode, and its job is to take a shortcode and return what it produces.
What a capability is
WordPress does not treat all logged-in users the same. Each account has a role, and each role has a set of permissions called capabilities. A Subscriber can read posts and comment. A Contributor can write posts but not publish them. An Administrator can do everything. When a piece of code checks a capability before doing something, it is asking "is this user allowed?". If that check is missing or too loose, the wrong people get in.
What remote code execution means
Remote code execution, usually shortened to RCE, means an attacker can make the server run code of their choosing, from a distance, through the normal web interface. It is treated as the most serious kind of web vulnerability because the attacker is no longer limited to what the website's forms allow. They are running their own program on the machine.
What CVSS is
CVSS is a scoring system for the severity of a vulnerability. Scores run from 0 to 10, and 9.0 and above is labelled Critical. The score is built from a vector, a string of codes describing the conditions. The three issues here all scored 9.9 with the vector CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H. In plain terms: the attack works over the network, is easy to carry out, needs a logged-in account, needs no action from a victim, can affect more than the vulnerable component, and has a high impact on confidentiality, integrity and availability.
The plugin and the three problems
PHP Everywhere is a WordPress plugin whose stated purpose is to let site owners execute PHP code anywhere on their site. It offered three ways to put PHP into a page: a shortcode, a metabox in the post editor, and a Gutenberg block. The plugin's internal name, its slug, is php-everywhere. It was developed by Alexander Fuchs, and at the time of disclosure it was installed on over 30,000 websites.
The vulnerabilities were found and reported by Ramuel Gall of the Wordfence Threat Intelligence team. Three separate issues were disclosed, all affecting versions <= 2.0.3 and all fixed in version 3.0.0. Each carries a CVSS score of 9.9 (Critical) with the vector above.
| CVE | How the attacker gets in | Lowest account that works |
|---|---|---|
| CVE-2022-24663 | Shortcode | Subscriber or Customer |
| CVE-2022-24664 | Metabox | Contributor (edit_posts) |
| CVE-2022-24665 | Gutenberg block | Contributor (edit_posts) |
A CVE is a public identifier for a known vulnerability, so people can refer to the same issue unambiguously. The table is the whole story in one glance: the shortcode route needs only the weakest account, while the other two need a Contributor, someone trusted enough to write posts.
How the disclosure and the fix unfolded
The disclosure process began on January 4, 2022. The Wordfence team contacted the WordPress plugin repository with the disclosure, and also reached out to the plugin author directly. Contacting the repository matters because that is where WordPress users download plugins from; the people running it can act on a dangerous plugin. The author responded within a few hours, and the full disclosure was sent at that point. A largely rebuilt version of the plugin, 3.0.0, was released on January 10, 2022.
On the defensive side, Wordfence Premium users received a firewall rule protecting against these vulnerabilities on January 4, 2022. A firewall rule is a filter that inspects incoming requests and blocks the ones that look like an attack, so sites with the rule were shielded even before they updated the plugin. Wordfence Care and Wordfence Response customers received the rule immediately upon subscription. Sites on the free version of Wordfence received the same protection 30 days after the initial release, on February 3, 2022.
The conditions for exploiting each issue differ. The shortcode issue needs only an authenticated account of any level, including a Subscriber or a Customer. The metabox and block issues need the edit_posts capability, which by default the plugin granted to all users holding it, meaning Contributor-level accounts and above.
How the problems were found
The core observation is about how WordPress handles shortcodes. WordPress allows any authenticated user to execute shortcodes via the parse-media-shortcode AJAX action, and some plugins also allow unauthenticated shortcode execution. PHP Everywhere registered a shortcode that executes PHP. Put those two facts together and the shortcode's code execution is reachable by any logged-in user, regardless of what that user is otherwise permitted to do.
Think of it like a building where the front desk will pass any message to any office, and one office is a workshop that builds whatever the message describes. The front desk is not doing anything wrong by its own rules; the problem is that the workshop accepts instructions through it.
For the other two routes, the problem is the default permission check. The plugin allowed all users with edit_posts to use both the PHP Everywhere metabox and the PHP Everywhere Gutenberg block. It was possible to restrict this to admin-only, but that was not the default, because versions <= 2.0.3 could not add capability checks without disabling the Gutenberg Block editor. The Wordfence team worked with the plugin author to overcome that limitation when sending the disclosure.
How each issue could be triggered
Step 1: Shortcode execution as a low-privileged user (CVE-2022-24663)
A logged-in user, even one with almost no permissions such as a Subscriber or a Customer, sends a request to the parse-media-shortcode AJAX action with the shortcode parameter set to the PHP Everywhere shortcode wrapping arbitrary PHP:
[php_everywhere]<arbitrary PHP>[/php_everywhere]
Line by line, in plain words:
[php_everywhere]is the opening tag. It tells WordPress "this is the PHP Everywhere shortcode, hand what follows to that plugin".<arbitrary PHP>is a placeholder for whatever PHP the attacker wants to run. The angle brackets are not part of the code; they mark the spot where the attacker's own instructions go.[/php_everywhere]is the closing tag, marking the end of the code the plugin should handle.
The shortcode parameter carries the payload. WordPress parses it through the shortcode system, PHP Everywhere's handler evaluates the enclosed PHP, and the result is arbitrary PHP execution on the site. Executing arbitrary PHP on a WordPress site typically allows complete site takeover.
Why this step matters: the attacker does not need to be an administrator, or even a Contributor. A brand-new account, the kind anyone can create on a site that allows registration, is enough. That is why this is the most serious of the three in practice.
Step 2: Metabox execution as a Contributor (CVE-2022-24664)
A user with the edit_posts capability, such as a Contributor, creates a post, adds PHP code to the PHP Everywhere metabox, and then previews the post. The preview triggers evaluation of the code in the metabox, giving code execution on the site.
Why the preview: previewing asks WordPress to render the post as it would appear, which means running everything the post contains, including the plugin's metabox content. The attacker never has to publish anything, so nothing appears on the public site and no review step gets in the way.
Step 3: Gutenberg block execution as a Contributor (CVE-2022-24665)
A user with the edit_posts capability creates a post, adds the PHP Everywhere block, adds code to it, and previews the post. As with the metabox, the preview executes the code.
This is the same idea as Step 2 through a different door. The block and the metabox are two separate features, and each got its own CVE.
The root cause
The plugin's design goal is to execute PHP supplied by users, so the security boundary has to be who is allowed to supply that PHP and through which path. Two mistakes break that boundary.
First, the shortcode path inherits WordPress's shortcode execution model. Because WordPress lets any authenticated user run shortcodes through parse-media-shortcode, and some plugins allow unauthenticated shortcode execution, a shortcode that evaluates PHP is effectively an unauthenticated or any-authenticated-user code execution primitive. The plugin did not account for this.
Second, the metabox and block paths defaulted to allowing everyone with edit_posts, rather than restricting the feature to administrators. The report states that admin-only was possible to configure but was not the default, because versions <= 2.0.3 could not add capability checks without disabling the Gutenberg Block editor. That constraint is why the default was left open, and the limitation was overcome together with the author during disclosure.
A useful comparison: a key that opens every door is convenient, but if you hand it out to everyone who needs to enter one room, you have not secured the building. The plugin handed out the key by default and relied on nobody trying the other doors.
What the impact is
All three issues allow arbitrary PHP execution, which typically means complete site takeover. The shortcode issue requires only Subscriber or Customer level access, the lowest rung of authenticated users. The metabox and block issues require Contributor-level permissions, which imply some degree of trust and are more difficult to obtain than subscriber-level permissions. The report notes that they carry the same CVSS score as the shortcode issue but are less severe for that reason, and that the CVSS scoring system does not allow "Medium" in the "Privileges Required" field.
The report describes the vulnerabilities as very easy to exploit and usable to quickly and completely take over a site.
The fix
Version 3.0.0, released on January 10, 2022, is the fully patched version for all three CVEs. The report describes it as a largely rebuilt version of the plugin. One limitation is stated explicitly: 3.0.0 only supports PHP snippets via the Block editor, so users of the Classic Editor need to uninstall the plugin and find another solution. Older versions should not be run under any circumstances.
On the network side, a firewall rule was released on January 4, 2022 for Wordfence Premium, Care and Response customers, and became available to free Wordfence users on February 3, 2022.
If you run the plugin, the practical steps are:
- Update to 3.0.0 or later.
- If you use the Classic Editor, remove the plugin and look for another way to do what you need.
- Do not keep an older version running while you decide.
Similar things to look for
These are patterns worth checking in other plugins, not just this one.
- Other plugins registering PHP-evaluating shortcodes. Search installed plugins for
add_shortcodehandlers that calleval, include user-supplied files, or otherwise interpret their content as code. A positive result is that a Subscriber account can send the shortcode throughparse-media-shortcodeand observe its output or side effect. - Shortcode execution reachable without authentication. The report notes that some plugins allow unauthenticated shortcode execution. Test shortcode-bearing endpoints while logged out; a positive result is code output or a side effect from an unauthenticated request.
- Editor features gated on
edit_postsrather thanmanage_options. Look for metaboxes and blocks that execute code or perform privileged actions and check their default capability. A positive result is a Contributor being able to trigger the feature through a post preview. - Preview as the trigger. For any editor-integrated feature that runs code, create a draft and preview it with a low-privileged account. A positive result is execution occurring at preview time, before any publish or review step.
- Capability defaults that can be tightened but are not. Where a plugin offers an admin-only setting, check its out-of-the-box value on a fresh install. A positive result is the permissive default being active without configuration.
Glossary
- AJAX action: a named background request a web page sends to the server without reloading the page.
- Capability: a permission WordPress checks before letting a user do something, such as
edit_postsfor writing posts. - Classic Editor: the older WordPress post editing screen, as opposed to the newer block-based editor.
- Contributor: a WordPress role that can write and manage its own posts but not publish them.
- CVE: a public identifier for a known vulnerability, so the same issue can be referred to unambiguously.
- CVSS: a scoring system for vulnerability severity, from 0 to 10, with 9.0 and above labelled Critical.
- CVSS vector: the string of codes that describes the conditions behind a CVSS score.
- Customer: a WordPress role, typically created by a shop plugin, with very limited permissions.
- Firewall rule: a filter that inspects incoming requests and blocks ones that look like an attack.
- Gutenberg block: a separate piece of content in the newer WordPress editor, such as a paragraph or an image.
- Metabox: a small panel on the WordPress post editing screen, often added by a plugin.
- PHP: a programming language that runs on the web server and is used to build WordPress pages.
- Plugin: an add-on that adds features to WordPress, written by a third party.
- Remote code execution (RCE): making a server run code of the attacker's choosing through a normal web interface.
- Role: a named set of capabilities in WordPress, such as Subscriber, Contributor or Administrator.
- Shortcode: a tag in square brackets that WordPress replaces with something else when the page is displayed.
- Slug: the internal name of a plugin, here
php-everywhere. - Subscriber: the lowest WordPress role, able to read posts and comment.
- WordPress: a system for building and running websites.
edit_posts: the WordPress capability that allows a user to write posts.manage_options: the WordPress capability that allows a user to change site-wide settings, normally held by administrators.parse-media-shortcode: the WordPress AJAX action that takes a shortcode and returns what it produces.