Wordpress iQ Block Country <= 1.2.13 - Admin+ Arbitrary File Deletion via Zip Slip

2 minute read

iQ Block Country is a Wordpress plugin that allows you to limit access to your website content. It can allow or disallow visitors from defined countries to (parts of) the content of the website.

The settings of the plugin can be exported or imported using its backup functionality. An authorized user can import preconfigured settings of the plugin by uploading a zip file. After the uploading process, files in the uploaded zip file are extracted one by one. During the extraction process, existence of a file is checked. If the file exists, it is deleted without any security control by only considering the name of the extracted file. This behavior leads to “Zip Slip” vulnerability.

Zip Slip can cause damage by overwriting configuration files or other sensitive resources. In this finding, An attacker can exploit this vulnerability and the behavior of the extraction process, to delete an arbitrary file in the server. For doing this, it is enough to upload a zip file containing a file that is named as the path of a file which is desired to be deleted.

Code Analysis

File: libs/blockcountry-settings.php

 1function iqblockcountry_settings_importexport() {
 2    $dir = wp_upload_dir();
 3
 4    // ...
 5    // ... Deleted lines about the export functionality and the user interface.
 6    // ...
 7
 8    // We care about the import functionality
 9    elseif (isset($_POST['import'])) {
10        $optarr = iqblockcountry_get_options_arr();
11        if (isset($_FILES['import']) && check_admin_referer('iqblockimport')) {
12            if ($_FILES['import']['error'] > 0) {
13                    wp_die(__("Something went wrong importing this file", 'iq-block-country'));
14            }
15            else {
16                require_once( ABSPATH . 'wp-admin/includes/class-pclzip.php' );
17                $zip      = new PclZip( $_FILES['import']['tmp_name'] );
18                $unzipped = $zip->extract( $p_path = $dir['path'] );
19
20                // ...
21                // ... Unnecessary lines
22                // ...
23
24                foreach ($unzipped as $zipfile)
25                {
26                    if (file_exists($zipfile['filename']))
27                    {
28                        //Attention! The existing file will be deleted.
29                        unlink($zipfile['filename']);
30                    }
31                }
32            }
33        }
34    }
35
36    // ...
37    // ... Deleted unnecessary lines
38    // ...
39}

Steps To Reproduce

  1. Install and activate the iQ Block Country plugin.
  2. Create a test file in the vulnerable system: (e.g. /var/www/html/test.txt)
  3. Create a zip file containing a file named as ../../../../test.txt. Absolute path at the end of this process will be: /var/www/html/wp-content/uploads/2022/01/../../../../test.txt
  4. Go back to the Wordpress, visit Settings > iQ Block Country > Import/Export tab.
  5. Click the “Browse” button and choose the zip file which is created in the Step 3.
  6. Click the “Restore settings” button.
  7. “Invalid file” message will be appeared but nevermind the message. Check whether the test.txt file is deleted or not.
comments powered by Disqus