Note 001Updated 05 DEC 2026

Building the WordPress Core RCE Gadget Chain

A retrospective on the WordPress core POP chain, from an object-injection sink in term metadata to a callable dispatch primitive, and what changed in WordPress 6.3.2.

Building the WordPress Core RCE Gadget Chain録PANDHACKER / RESEARCHPH-469FILE 001 / NOTES800 / 520Fig. 00Generative note plate / NotesPH-001

In October 2023, WPScan published a detailed walkthrough of an RCE gadget chain in WordPress core. The research started from a plausible object-injection sink in wp_termmeta and ended with a chain that reached a callable dispatch primitive using only classes shipped in core. I reproduced the chain and added a WordPress/RCE/1 gadget chain to PHPGGC.

This note is a retrospective on the construction, not a new disclosure. WordPress fixed the relevant unserialize paths in 6.3.2.

Overview of the WordPress core gadget chain: a SQL injection writes a serialized object into wp_termmeta, maybe_unserialize rebuilds the object, a string conversion starts the chain, ArrayAccess pivots reach a Requests session, and its hooks dispatch an attacker-controlled callable.
Fig. 1. The full path, sink to command execution. The SQL injection is only the way into wp_termmeta. The reusable part is the object graph that turns maybe_unserialize() into a callable dispatch. Every class in that graph ships with WordPress core.

The starting point

The original context was a SQL injection challenge that inserted rows into wp_termmeta. Metadata values are passed through maybe_unserialize() when read back, so an attacker who can write a crafted value may be able to trigger PHP object injection. The usual assumption was that WordPress core had no useful POP chain without a plugin. The research tested that assumption.

The chain begins with WP_Theme::__toString(), which calls $this->display('Name') and then $this->get('Name'). Because the attacker controls the serialized object, WP_Theme’s internal properties can be replaced with other objects, including classes that implement ArrayAccess.

public function __toString() {
    return (string) $this->display( 'Name' );
}

The string conversion is the trigger. display() reaches get(), and get() assumes $this->headers is an array. In a crafted object it can be any object implementing ArrayAccess, so the next method call is selected by the attacker.

The pivots

The chain then uses WP_Block_List, whose offsetGet() treats the requested index as a block lookup and can instantiate a WP_Block from attacker-controlled properties. The WP_Block constructor calls WP_Block_Type_Registry::get_registered(), which gives another controlled array lookup.

public function offsetGet( $index ) {
    $block = $this->blocks[ $index ];

    if ( isset( $block ) && is_array( $block ) ) {
        $block = new WP_Block( $block, $this->available_context, $this->registry );
        $this->blocks[ $index ] = $block;
    }

    return $block;
}

That lookup leads back to WP_Theme::offsetGet('Parent Theme'). The method calls $this->parent()->get('Name'), and parent() returns another attacker-controlled object. A WpOrg\Requests\Session object has a compatible get() method, so the chain pivots into the bundled Requests library.

The PHPGGC WordPress RCE 1 object graph. WP_Theme holds a WP_Block_List, which builds a WP_Block, which calls a controlled WP_Block_Type_Registry. That registry reaches a second WP_Theme, whose parent is a Requests Session. The Session merges controlled options and reaches a Hooks object, which dispatches a callback.
Fig. 2. The object graph used by WordPress/RCE/1. Each arrow is a method call that looks ordinary in isolation. The chain works because the serialized payload controls both the class of every object and the values of every property along the path.

Session::request() merges attacker-controlled properties into the request options and hands the result to Requests::request(). That method dispatches the requests.before_request hook through $options['hooks']->dispatch(). Since the attacker controls the hooks object, the dispatch can be recursed once to shift parameters and reach a callable of the attacker’s choosing.

Why it worked

Three properties made the chain possible:

  • Core shipped many magic methods and ArrayAccess implementations that were safe in normal use but composable when an attacker controls the entire object graph.
  • The Requests library exposed a dispatch hook whose callable was taken from object state.
  • The source of the object injection, term metadata, was reachable from a realistic SQL injection primitive.

The chain does not require a plugin, a writable file, or an administrator account. That is what made it worth packaging as a reusable PHPGGC gadget chain rather than treating it as a one-off CTF trick.

The fix

WordPress 6.3.2 changed the classes used in the final chain so that several of them can no longer be unserialized, and restricted what some unserialized properties may contain. The underlying lesson is not specific to WordPress: every class with a magic method or a callback property becomes part of the attack surface for any object-injection sink in the same codebase.

WordPress 6.3.2 fix. Before the fix, the serialized WP_Theme, WP_Block_List, WP_Block, registry, Requests Session, and Hooks graph composes into a callable. After the fix, several chain classes are rejected at unserialize time and some properties are restricted, so the graph no longer reaches the callback.
Fig. 3. What 6.3.2 changes. The sink can still be reached, but the composable graph is cut at the class boundary. Several classes in the final chain can no longer be unserialized, and other properties are constrained after unserialization.

If you are reviewing a PHP application, enumerate the sinks first. unserialize(), maybe_unserialize(), session decoding, cache backends, and queue payloads all qualify. Then look for classes whose destructors, wakeup methods, string conversions, or array access can reach a callable. The sink is usually the easy part to find. The chain is the work.

References

Click outside or press Esc to close