CVE-2022-23522: Arbitrary File Write when Extracting Tarballs retrieved from a remote location using in mindsdb

Published Mar 30, 2023
·
Updated

Summary

An unsafe extraction is being performed using shutil.unpackarchive() from a remotely retrieved tarball. Which may lead to the writing of the extracted files to an unintended location. This vulnerability is sometimes called a TarSlip or a ZipSlip variant.

Details

Unpacking files using the high-level function shutil.unpackarchive() from a potentially malicious tarball without validating that the destination file path remained within the intended destination directory may cause files to be overwritten outside the destination directory.

As can be seen in the vulnerable snippet code source, an archive is being retrieved using the downloadfile() function from a remote location which is a user-provided permanent storage bucket s3. Immediately after being retrieved, the tarball is unsafely unpacked using the function shutil.unpackarchive().

The vulnerable code is L128..L129 in fs.py file.

python3 def init(self): super().init() if 's3credentials' in self.config['permanentstorage']: self.s3 = boto3.client('s3', self.config['permanentstorage']['s3credentials']) else: self.s3 = boto3.client('s3') # User provided remote storage! self.bucket = self.config['permanentstorage']['bucket']

def get(self, localname, basedir): remotename = localname remotezipedname = f'{remotename}.tar.gz' localzipedname = f'{localname}.tar.gz' localzipedpath = os.path.join(basedir, localzipedname) os.makedirs(basedir, existok=True) # Retrieve a potentially malicious tarball self.s3.downloadfile(self.bucket, remotezipedname, localzipedpath)

# Perform an unsafe extraction shutil.unpackarchive(localzipedpath, basedir)

os.system(f'chmod -R 777 {basedir}') os.remove(localzipedpath)

PoC

The following PoC is provided for illustration purposes only. It showcases the risk of extracting a non-harmless text file sim4n6.txt to one of the parent locations rather than the intended current folder.

bash > tar --list -f archive.tar tar: Removing leading "../../../" from member names ../../../sim4n6.txt

> python3 Python 3.10.6 (main, Nov 2 2022, 18:53:38) [GCC 11.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import shutil >>> shutil.unpackarchive("archive.tar") >>> exit()

> test -f ../../../sim4n6.txt && echo "sim4n6.txt exists" sim4n6.txt exists

Attack Scenario

An attacker could craft a malicious tarball with a filename path, such as ../../../../../../../../etc/passwd, and then serve the archive remotely using a personal bucket s3, thus, retrieve the tarball through mindsdb and overwrite the system files of the hosting server.

Mitigation

Potential mitigation could be to: - Use a safer module, like zipfile. - Validate the location of the extracted files and discard those with malicious paths such as relative path .. or absolute path such as /etc/password. - Perform a checksum verification for the retrieved archive, but hard-coding the hashes may be cumbersome and difficult to manage.

Other sources

MindsDB is an open source machine learning platform. An unsafe extraction is being performed using shutil.unpackarchive() from a remotely retrieved tarball. Which may lead to the writing of the extracted files to an unintended location. This vulnerability is sometimes called a TarSlip or a ZipSlip variant. Unpacking files using the high-level function shutil.unpackarchive() from a potentially malicious tarball without validating that the destination file path remained within the intended destination directory may cause files to be overwritten outside the destination directory. An attacker could craft a malicious tarball with a filename path, such as ../../../../../../../../etc/passwd, and then serve the archive remotely using a personal bucket s3, thus, retrieve the tarball through mindsdb and overwrite the system files of the hosting server. This issue has been addressed in version 22.11.4.3. Users are advised to upgrade. Users unable to upgrade should avoid ingesting archives from untrusted sources.

Affected Software

2 affected componentsFixes available
pip/mindsdb<22.11.4.3
22.11.4.3
MindsDB MindsDB<22.11.4.3

Event History

Mar 30, 2023
CVE Published
via MITRE·06:04 PM
Data Sourced
via MITRE·06:04 PM
DescriptionSeverityWeakness
Data Sourced
via NVD·07:15 PM
DescriptionSeverityWeaknessAffected Software
Advisory Published
08:16 PM
Free Weekly Intel

Don't miss critical vulnerabilities

Join thousands of security professionals who receive our weekly digest of trending CVEs, zero-days, and exploited vulnerabilities.

No spam. Unsubscribe anytime.

Frequently Asked Questions

1

What is the severity of CVE-2022-23522?

CVE-2022-23522 has a medium severity rating due to the potential for unsafe extraction of files from a tarball.

2

How do I fix CVE-2022-23522?

To resolve CVE-2022-23522, upgrade to MindsDB version 22.11.4.3 or later where the vulnerability has been addressed.

3

What systems are affected by CVE-2022-23522?

CVE-2022-23522 affects versions of MindsDB prior to 22.11.4.3.

4

What does CVE-2022-23522 exploit?

CVE-2022-23522 exploits unsafe extraction methods in the `shutil.unpack_archive()` function, causing files to be extracted to unintended locations.

5

Can CVE-2022-23522 lead to data loss?

Yes, CVE-2022-23522 may potentially lead to data loss or unauthorized file manipulation due to improper file extraction.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203