wp2shell - Code Trace Deep Dive
WordPress's REST batch endpoint could pair a request object with a route handler chosen for a different subrequest, because a malformed path added an entry to the validation array but not the matches array. This let an unauthenticated attacker reach the posts query with an unvalidated scalar value, producing SQL injection that could be used to recover the admin password and then upload a plugin for code execution.
WordPress is one of the most common platforms out there for blogs and general sites, which is what makes it a prime target for researchers and adversaries alike. The codebase is mostly written in PHP and is on the 7th version with sub-versions and beta versions.
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
Likely an index-alignment mistake in the batch validation loop, where a malformed subrequest was appended to the validation array but not the matches array, so later requests were dispatched with another route's handler and skipped that route's schema validation, letting a scalar reach an unparameterised SQL clause.
Impact
An unauthenticated attacker could inject SQL through the public batch endpoint and, with the recovered admin password, upload a plugin to execute code on the server; the text notes that a strong admin password makes exploitation take longer, and that timing checks can be disturbed by network jitter, filtering or backported fixes.
What the attacker needed
No authentication for the SQLi stage; admin password recovered or known; REST batch endpoint reachable
The fix
WordPress 7.0.2 was fixed by keeping the matches and validation arrays aligned, blocking re-entrant REST dispatch, and normalising the author exclusion value into an integer list at the SQL sink.
How it was found
- Send a batch request containing a malformed path so that parsing fails and a WP_Error entry is created
- Include further subrequests so that the shifted arrays pair a request object with the posts collection handler
- Supply the author exclusion parameter as a scalar carrying a conditional time delay
- Measure response times to calibrate a fast false condition against a slow true condition
- Use the timing difference to extract database values character by character
- Log in with recovered administrator credentials and upload a PHP plugin to run commands
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.
WordPress has a feature that lets a client send several API requests in one batch. Each request is supposed to be checked against the rules of the route it names. A mistake meant that when one entry in the batch was broken, the remaining entries were checked against one route but run using another route's code, so a value that should have been a list of numbers arrived unchecked and ended up inside a database query.
What is SQL injection?
Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.