https://cve.circl.lu/comments/feed Most recent comment. 2025-01-05T07:52:54.108041+00:00 Vulnerability Lookup info@circl.lu python-feedgen Contains only the most 10 recent comments. https://cve.circl.lu/comment/5e1cc667-8f06-4cde-b167-203c95a1038c Unauthorized Plugin Installation/Activation in Hunk Companion | WPScan 2025-01-05T07:52:54.115218+00:00 Alexandre Dulaunoy http://cve.circl.lu/user/adulau # Unauthorized Plugin Installation/Activation in Hunk Companion | WPScan Ref: https://wpscan.com/blog/unauthorized-plugin-installation-activation-in-hunk-companion/ This report highlights a vulnerability in the [Hunk Companion plugin](https://wordpress.org/plugins/hunk-companion/) < 1.9.0 that allows unauthenticated POST requests to install and activate plugins directly from the WordPress.org repository. This flaw poses a significant security risk, as it enables attackers to install vulnerable or closed plugins, which can then be exploited for attacks such as Remote Code Execution (RCE), SQL Injection, Cross‑Site Scripting (XSS), or even the creation of administrative backdoors. By leveraging these outdated or unmaintained plugins, attackers can bypass security measures, manipulate database records, execute malicious scripts, and gain unauthorized administrative access to the site. Method of Exploitation ---------------------- While tracing an infection on a WordPress site, we uncovered a live vulnerability currently being exploited in a two‑step process: 1. **Unauthenticated Installation/Activation**: Attackers exploit a flaw to install and activate the now‑closed and vulnerable plugin, [WP Query Console](https://wordpress.org/plugins/wp-query-console/) 2. **Remote Code Execution (RCE)**: The vulnerability in WP Query Console is then exploited to evaluate arbitrary and malicious PHP code. In the infections we’ve analyzed, attackers use the RCE to write a PHP dropper to the site’s root directory. This dropper allows continued unauthenticated uploads via GET requests, enabling persistent backdoor access to the site. Investigation ------------- The vulnerability was uncovered during an investigation into the entry point for an infection caused by its exploitation. Access logs revealed that the `change timestamp` of a randomly named PHP file located in the root of the WordPress installation (`/htdocs/aea74fff3c02.php`) was preceded by requests to the following endpoints: * Time: Nov 27, 2024 @ 08:21:41.812 * request_url: /aea74fff3c02.php * http_user_agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2735.76 Safari/537.36 * request_type: GET * Time: Nov 27, 2024 @ 08:21:41.561 * request_url: /?rest_route=/wqc/v1/query * http_user_agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2735.76 Safari/537.36 * request_type: POST * Time: Nov 27, 2024 @ 08:21:40.354 * request_url: /wp-json/hc/v1/themehunk-import * http_user_agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2735.76 Safari/537.36 * request_type: POST * Time: Nov 27, 2024 @ 08:21:08.151 * request_url: /wp-json/hc/v1/themehunk-import * http_user_agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2735.76 Safari/537.36 * request_type: POST Further investigation revealed that the plugins responsible for these endpoints are **Hunk Companion** and **WP Query Console**, respectively. Each observed infection’s modification times aligned with POST requests to these same endpoints. The Remote Code Execution (RCE) vulnerability in WP Query Console, reported under [CVE‑2024‑50498](https://www.cve.org/CVERecord?id=CVE-2024-50498), remains unpatched. Meanwhile, the unauthenticated plugin installation/activation vulnerability in Hunk Companion was reportedly fixed in version 1.8.5 and greater, as documented in [CVE‑2024‑9707](https://www.cve.org/CVERecord?id=CVE-2024-9707). Upon further review, we confirmed that this infection did, in fact, occur with the latest version of Hunk Companion at that time, 1.8.7, indicating that the vulnerability had persisted in the current version. Code Analysis ------------- An analysis of the code responsible for the `themehunk‑import` endpoint revealed the vulnerability being exploited. Within the file `hunk‑companion/import/core/class‑installation.php`, the class `HUNK_COMPANION_SITES_BUILDER_SETUP` is executed by the endpoint and handles plugin installation and activation. On line 204, the following code demonstrates that the WordPress.org URL is hardcoded, restricting installations to plugins hosted on the WordPress.org repository: ``` $temp_file = download_url('https://downloads.wordpress.org/plugin/'.$slug.'.zip'); ``` However, this URL allows the download of plugins, even if they have been closed or removed from the repository. This behavior introduces a significant vector for exploitation, enabling attackers to install vulnerable plugins. The vulnerability stems from the weakness found in `hunk‑companion/import/app/app.php`: ``` register_rest_route( 'hc/v1', 'themehunk-import', array( 'methods' => 'POST', 'callback' => array( $this, 'tp_install' ), 'permission_callback' => function () { // Check if the user is logged in if ( ! is_user_logged_in() ) { //return new WP_REST_Response( 'Unauthorized: User not logged in', 401 ); } // Debug: Log the user role and capabilities to see what they have $current_user = wp_get_current_user(); // error_log( 'Current user: ' . $current_user->user_login ); // error_log( 'User roles: ' . implode( ', ', $current_user->roles ) ); // error_log( 'User capabilities: ' . print_r( $current_user->allcaps, true ) ); // Ensure the user has the 'install_plugins' capability if ( ! current_user_can( 'install_plugins' ) ) { return new WP_REST_Response( 'Unauthorized: Insufficient capabilities', 401 ); } // Get the nonce from the request header $nonce = $request->get_header('X-WP-Nonce'); // Verify the nonce if ( ! wp_verify_nonce( $nonce, 'hc_import_nonce' ) ) { return new WP_REST_Response( 'Unauthorized: Invalid nonce', 401 ); } return true; // Permission granted }, ) ); ``` Lines 28‑59 register the REST API route for `themehunk‑import`. In version 1.8.5, the plugin author introduced a `permission_callback` to restrict access. However, for [`permission_callback`](https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/#permissions-callback) to work correctly, it must return a boolean (`false` to reject requests, `true` to accept) or a `WP_Error` object. In this case, failed conditions return `new WP_REST_Response`, which is not a boolean or `WP_Error`. As a result, the `permission_callback` always evaluates to `true`, allowing unauthenticated requests to bypass the intended checks. This flaw enables the execution of the `tp_install` function, which invokes the `HUNK_COMPANION_SITES_BUILDER_SETUP` class, leading to the installation and activation of arbitrary plugins. ### Recommended Fix To address this issue, the `themehunk‑import` and `ai‑site‑import` endpoints needed to be patched. Specifically, the return statements for failed conditions needed to be changed. For example, replace: ``` return new WP_REST_Response( 'Unauthorized: User not logged in', 401 ); ``` With: ``` return new WP_Error( 'unauthorized', __( 'You must be logged in.' ), array( 'status' => 401 ) ); ``` This change ensures the `permission_callback` correctly denies unauthorized requests, mitigating the vulnerability. As of 1.9.0, the author implemented the necessary patch, and we have confirmed that the exploit is no longer present. Conclusion ---------- This vulnerability represents a significant and multifaceted threat, targeting sites that use both a [ThemeHunk theme](https://profiles.wordpress.org/themehunk/#content-themes) and the Hunk Companion plugin. With over 10,000 active installations, this exposed thousands of websites to anonymous, unauthenticated attacks capable of severely compromising their integrity. What makes this attack particularly dangerous is its combination of factors—leveraging a previously patched vulnerability in Hunk Companion to install a now‑removed plugin with a known Remote Code Execution flaw. The chain of exploitation underscores the importance of securing every component of a WordPress site, especially third‑party themes and plugins, which can become critical points of entry for attackers. As WordPress remains the most popular content management system in the world, such vulnerabilities serve as a stark reminder of the ongoing challenges in maintaining site security. It’s imperative for developers, site owners, and plugin authors alike to adopt proactive measures, such as regularly updating plugins and themes, auditing for known vulnerabilities, and disabling unused or unnecessary extensions. Timeline -------- **Nov 27th, 2024** – Internal discovery of this vulnerability. We reported issue to Hunk Companion **Dec 10th, 2024** – Hunk Companion confirms acknowledges issue and releases a patch. **Dec 10th, 2024** – We published this advisory. _The PoC will be displayed on January 14, 2025, to give users the time to update._ Credits ------- Original research: Daniel Rodriguez **Acknowledgments**: Special thanks to the WPScan team and Ashley Robicheau for feedback, help, and corrections. 2024-12-15T06:47:50.105587+00:00