Authenticated Persistent Cross-Site Scripting (XSS) Vulnerability in Closed WordPress Plugin Responsive Menu
On Monday, the WordPress plugin Responsive Menu was closed on WordPress Plugin Directory. Due to that being one of the 1,000 most popular plugins in that directory (it has 100,000+ installs), our systems warned us about the closure and we started checking over the plugin to see if there was a vulnerability we should be warning customers of our service about if they are using the plugin. We found the plugin contains a fairly serious security vulnerability, an authenticated persistent cross-site scripting (XSS) vulnerability, as well as other vulnerabilities because of the poor security of the code.
We tested and confirmed that two of the existing protections in our new firewall plugin for WordPress would individually stop exploitation of the authenticated persistent XSS vulnerability, even before we discovered the vulnerability, as part of its protection against zero-day vulnerabilities. An additional protection being added to the plugin in the next release, based on a vulnerability fixed and exploited in another plugin last week, also would provide protection against this.
Authenticated Persistent Cross-Site Scripting (XSS)
The plugin registers various of its functions to be accessible through WordPress’ AJAX functionality to anyone logged in to WordPress. That includes a function, rmp_import_menu(), to import one of the plugin’s menu:
58 | add_action( 'wp_ajax_rmp_import_menu', [ $this, 'rmp_import_menu' ] ); |
That function is only intended to be accessed by users with the Administrator role, but at the beginning of that function, which is located in the file /v4.0.0/inc/classes/class-admin.php, there isn’t a capabilities check to enforce that. The only security is a nonce check to prevent cross-site request forgery (CSRF):
573 574 575 | public function rmp_import_menu() { check_ajax_referer( 'rmp_nonce', 'ajax_nonce' ); |
Normally that check would restrict access to only those with the right capability (even though isn’t intended for that purpose), but as we will get to in a moment, that isn’t the case with this plugin.
The rest of that function will import the data from a file sent with the request:
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 | if( empty( $_FILES['file']['name'] ) ) { wp_send_json_error( [ 'message' => __('Please add file !', 'responsive-menu-pro') ] ); } $file_type = pathinfo( basename( $_FILES["file"]["name"] ), PATHINFO_EXTENSION ); if( empty( $_FILES['file']['tmp_name'] ) || 'json' != $file_type ) { wp_send_json_error( [ 'message' => __('Please add json file !', 'responsive-menu-pro') ] ); } $menu_id = sanitize_text_field( $_POST['menu_id'] ); if ( empty( $menu_id ) ) { wp_send_json_error( [ 'message' => __('Select menu !', 'responsive-menu-pro') ] ); } $file_contents = file_get_contents( $_FILES['file']['tmp_name'] ); $import_options = json_decode( $file_contents, true ); $option_manager = Option_Manager::get_instance(); $exist_option = $option_manager->get_options( $menu_id ); // Some required options replced in imported settings with existing menu settings. $import_options['menu_name'] = $exist_option['menu_name']; $import_options['theme_type'] = 'default'; $import_options['menu_theme'] = null; $import_options['menu_to_use'] = $exist_option['menu_to_use']; $import_options['menu_to_use_in_mobile'] = $exist_option['menu_to_use_in_mobile']; update_post_meta( $menu_id, 'rmp_menu_meta' , $import_options ); |
As the proof of concept below confirms, that code doesn’t sanitize the input, so JavaScript code can be added to the menu data and it will run on the website.
The value needed for the nonce check is generated in the function admin_enqueue_scripts() in the file /v4.0.0/inc/classes/class-assets.php. That will add the nonce to admin pages as long as the GET input “post_type” is set to “rmp_menu”:
92 93 94 95 96 97 98 99 100 101 102 103 | public function admin_enqueue_scripts( $hook_suffix ) { $post_type = get_post_type(); if ( empty( $post_type ) && ! empty( $_GET['post_type'] ) ) { $post_type = $_GET['post_type']; } if ( 'rmp_menu' !== $post_type ) { return; |
So anyone logged in to WordPress that can access the admin area can get a valid nonce.
The plugin also makes its export functionality available in the same way as the import functionality, so an attacker could export the menu being used and the re-import it with malicious code. Among the other functionality accessible due to that is changing the plugin’s settings, which would also be utilized to exploit this.
WordPress Causes Full Disclosure
As a protest of the moderators of the WordPress Support Forum’s continued inappropriate behavior we changed from reasonably disclosing to full disclosing vulnerabilities for plugins in the WordPress Plugin Directory in protest, until WordPress gets that situation cleaned up, so we are releasing this post and then leaving a message about that for the developer through the WordPress Support Forum. (For plugins that are also in the ClassicPress Plugin Directory, we will follow our reasonable disclosure policy.)
You can notify the developer of this issue on the forum as well.
Hopefully, the moderators will finally see the light and clean up their act soon, so these full disclosures will no longer be needed (we hope they end soon). You would think they would have already done that, but considering that they believe that having plugins, which have millions installs, remain in the Plugin Directory despite them knowing they are vulnerable is “appropriate action”, something is very amiss with them (which is even more reason the moderation needs to be cleaned up).
If the moderation is cleaned up, it would also allow the possibility of being able to use the forum to start discussing fixing the problems caused by the very problematic handling of security by the team running the Plugin Directory, discussions which they have for years shut down through their control of the Support Forum.
Update: To clear up the confusion where developers claim we hadn’t tried to notify them through the Support Forum (while at the same time moderators are complaining about us doing just that), here is the message we left for this vulnerability:
Is It Fixed?
If you are reading this post down the road the best way to find out if this vulnerability or other WordPress plugin vulnerabilities in plugins you use have been fixed is to sign up for our service, since what we uniquely do when it comes to that type of data is to test to see if vulnerabilities have really been fixed. Relying on the developer’s information can lead you astray, as we often find that they believe they have fixed vulnerabilities, but have failed to do that.
Proof of Concept
With the plugin’s “Use external files” setting disabled (an attacker can change the plugin’s settings) change the value of the “menu_title_hover_colour” in export of the plugin’s menu to the following and then import that file.
</style><script>alert(document.cookie);</script>
That will cause any available cookies to be shown in an alert box on frontend pages of the website.
Replace “[path to WordPress]” with the location of WordPress, “[menu id]” with the id of an existing menu, and “[nonce]” with the value for the “ajax_nonce” from the page /wp-admin/?post_type=rmp_menu.
<html> <body> <form action="http://[path to WordPress]/wp-admin/admin-ajax.php?action=rmp_import_menu" enctype="multipart/form-data" method="POST"> <input type="hidden" name="menu_id" value="[menu id]" /> <input type="hidden" name="ajax_nonce" value="[nonce]" /> <input type="file" name="file" /> <input type="submit" value="Submit" /> </form> </body>