CVE-2022-21661: Exposing Database Info via WordPress SQL Injection
A SQL injection vulnerability in WordPress's WP_Query class allowed an attacker to expose data stored in a connected database when a plugin used the vulnerable class with specific parameters. The bug could be exploited without authentication via a plugin's AJAX action.
In October of this year, we received a report from ngocnb and khuyenn from GiaoHangTietKiem JSC covering a SQL injection vulnerability in WordPress. The bug could allow an attacker to expose data stored in a connected database.
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 clean_query method failed to validate the terms parameter when the taxonomy parameter was empty and the field parameter was set to 'term_taxonomy_id', allowing user input to be injected into an SQL statement.
Impact
An attacker could read data stored in the WordPress database, which may include sensitive information, though the vulnerability requires a plugin that uses the vulnerable WP_Query class.
What the attacker needed
A plugin that uses WP_Query with user input; No authentication required
The fix
The patch adds additional checks to the terms parameter to prevent further SQL injections.
How it was found
- Send a request to wp-admin/admin-ajax.php with the action parameter set to ecsload.
- The request is handled without authentication, triggering the wp_ajax_nopriv_ecsload hook.
- The hook calls the get_document_data method, which creates a WP_Query object with user-supplied parameters.
- The WP_Query object processes the parameters, and due to the validation flaw, the terms parameter is used in the SQL query.
- The crafted SQL query is executed, allowing the attacker to read the WordPress database.
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 uses a class called WP_Query to fetch posts from its database. A mistake in how it checked certain input meant that a specially crafted request could sneak extra database commands into the query. This let an attacker read information from the database, though they needed a plugin that used the vulnerable code.
What is SQL injection?
Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.