How I Make Two SQL Injections Exploitable under the Magic Restricts in WordPress
Two WordPress plugins concatenated user-controlled input directly into database queries, creating SQL injection flaws. Because WordPress escapes special characters, the author could not terminate statements, but used time-based blind injection to extract administrator password hashes.
I am writing this article to share two SQL injection vulnerabilities (SQLi) I have discovered in WordPress plugins and submitted to the Patchsatck monthly competition in February 2024. In this write-up, I will not only tell you how I can locate these bugs but also reveal some tricks for exploiting them in the face of…
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 the plugins concatenated request parameters directly into SQL strings passed to $wpdb functions without parameterisation or sanitisation.
Impact
An authenticated contributor could extract administrator password hashes from the database, though the escaping of special characters and lack of FILE privilege limited the injection to time-based data extraction.
What the attacker needed
Contributor-level account; ability to reach plugin endpoints
The fix
The plugin vendors have patched both vulnerabilities.
How it was found
- Send a POST request to the plugin's related-episodes API endpoint with a crafted related value.
- Observe that the response is delayed when the injected condition is true, confirming time-based injection.
- Guess the administrator password hash character by character using the delay as an oracle.
- For the second plugin, send a GET request to the admin edit page with a crafted filter parameter.
- Use CHAR() and substr() comparisons instead of LIKE to work around escaping of percent signs.
- Enumerate each character position to recover the full password hash.
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.
SQL injection is when a program builds a database command by gluing together text that a user supplied, so the user can sneak in extra database instructions. Here the plugins did exactly that, but WordPress escapes characters like quotes and percent signs, so the attacker could not simply add new commands. Instead they asked the database to pause for a second only when a guessed character was correct, and measured the response time to recover passwords one character at a time.
What is SQL injection?
Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.