31 Jul

Our Proactive Monitoring Caught an Authenticated Arbitrary File Upload Vulnerability in Being Introduced in to uListing

One of the ways we help to improve the security of WordPress plugins, not just for our customers of our service, but for everyone using them, is our proactive monitoring of changes made to plugins in the Plugin Directory to try to catch serious vulnerabilities. Through that we caught an authenticated arbitrary file upload vulnerability being introduced in to the plugin uListing, which can also be exploited through cross-site request forgery (CSRF). The vulnerability occurs in code handled through WordPress’ REST API, which is increasingly a vector through which vulnerabilities in WordPress plugins are accessible. (We have included checking over functionality running through the REST API in our security reviews of WordPress plugins since earlier this year due the prevalence of issues.)

The plugin registers the function upload_file() to be accessible through WordPress REST API as part of new import/export functionality:

22
23
24
25
26
register_rest_route($namescape, 'upload_file', array(
		'methods' => 'POST',
		'callback' => 'upload_file',
	)
);

Since that functionality is intended to be accessed by someone logged in to WordPress there should be a permission callback to restrict access in that registration. That would cause protection against CSRF to be run when trying to access the function as well.

That function, which is located in the file /includes/lib/import-export/includes/routeHandler.php, then will save an uploaded file to the directory /wp-content/uploads/ulisting_import_tmp/:

57
58
59
60
61
62
63
64
65
66
67
68
function upload_file() {
 
    //$k = uListingImport::get_import_info(file_get_contents($_FILES['file']['tmp_name'], true));
    //$target_file = $_FILES['file']['tmp_name']. '/' . $_FILES['file']['name'];
    //$file = file_get_contents($_FILES['file']['tmp_name'], true);
 
    $file_name = $_FILES["file"]["name"];
 
    $target_dir  = wp_upload_dir()['basedir'];
    wp_mkdir_p($target_dir.'/ulisting_import_tmp');
    $target_file = $target_dir . '/ulisting_import_tmp/' . basename($file_name);
    move_uploaded_file($_FILES["file"]["tmp_name"], $target_file);

The user interface functionality related to that limits uploading to only files with the .json extension, but this code doesn’t have any similar restriction.

In reminder that you need to test possible vulnerabilities out to confirm there is an issue, while looking at that code it looks like there were no restrictions, when we tried exploiting this with the proof of concept below, when not logged in to WordPress, we got the following message:

You are not allowed to access this data!

A search of the plugin’s code showed that there in fact is a restriction in place due to the following code:

5
6
7
8
9
10
11
add_filter('rest_api_init', 'rest_only_for_authorized_users_uListing_import_export', 99);
function rest_only_for_authorized_users_uListing_import_export($wp_rest_server)
{
    if (!(current_user_can('administrator') || current_user_can('editor'))) {
        wp_die('You are not allowed to access this data!', 'Access denied', 403);
    }
}

That will restrict access to the REST API to those logged in as Administrator or Editors. That isn’t how you are supposed to restrict access and it seems like it might interfere with other usage of the API.

It would be a vulnerability for users logged in WordPress as Editors to be able to upload arbitrary files and since there is no protection against CSRF, this could be exploited to cause logged in Administrators or Editors to upload files without intending to.

The rest of the import/export functionality running through the REST API looks to also be insecure.

Full Disclosure

Due to the moderators of the WordPress Support Forum’s continued inappropriate behavior we are full disclosing vulnerabilities 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. 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).

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

The following proof of concept will upload the contents of the selected file to the directory /wp-content/uploads/ulisting_import_tmp/, when logged in as an Editor.

Make sure to replace “[path to WordPress]” with the location of WordPress.

<html>
<body>
<form action="http://[path to WordPress]/wp-json/uListing-import-export/upload_file" method="POST" enctype="multipart/form-data">
<input type="file" name="file" />
<input type="submit" value="Submit request" />
</form>
</body>
</html>

Concerned About The Security of the Plugins You Use?

When you are a paying customer of our service, you can suggest/vote for the WordPress plugins you use to receive a security review from us. You can start using the service for free when you sign up now. We also offer security reviews of WordPress plugins as a separate service.