Skip to content
RCE Write-up Advanced

How Can CVE-2022-21663 Be Exploited in WordPress?

A PHP object injection vulnerability in WordPress core allowed a malicious super-admin to inject a serialized string that bypassed the is_serialized() check and was later deserialized by an upgrade script, potentially leading to remote code execution if a suitable gadget chain was present.

Simon Scannell Follow

Published on blog.sonarsource.com

At the time of writing, WordPress powers 43% of websites on the Internet. Its simplicity and robustness enable millions of users to host their blog, eCommerce site, forum, or static website.

Simon Scannell (@scannell_simon), Karim El Ouerghemmi, on blog.sonarsource.com

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.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The is_serialized() function did not recognise serialized strings starting with 'C' (for special objects), and the upgrade_280() function used unserialize() directly instead of maybe_unserialize(), breaking the symmetry that normally prevents double serialization.

Impact

A malicious super-admin could trigger deserialization of a crafted object, potentially leading to remote code execution if a suitable gadget chain is present in an installed plugin.

What the attacker needed

Super-admin privileges on a multi-site WordPress; a plugin with a suitable gadget chain installed

The fix

The vulnerability was fixed by using maybe_unserialize($data) in the vulnerable upgrade_280() function to restore symmetry with maybe_serialize($data).

How it was found

  1. Inject a PHP serialized string of a special object carrying malicious pop chain gadgets as properties into the database as an option value.
  2. maybe_serialize() won’t recognize the payload as a serialized string and does not double serialize it.
  3. Modify the database version option to trigger the vulnerable upgrade script
  4. The upgrade script passes the PHP serialized string directly to unserialize(), which recognizes the string and deserializes it, triggering the pop chain.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

PHP object injection is a flaw where an attacker can sneak in a specially crafted piece of text that, when processed by the application, creates objects of the attacker's choosing. In this case, a WordPress administrator could store such text in a setting, and a later upgrade step would process it without the usual safety check, potentially running harmful code if other code (a gadget chain) is present.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More from WordPress

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.