Loading HuntDB...

CVE-2022-23522

HIGH
Published 2023-03-30T18:04:56.599Z
Actions:

Expert Analysis

Professional remediation guidance

Get tailored security recommendations from our analyst team for CVE-2022-23522. We'll provide specific mitigation strategies based on your environment and risk profile.

CVSS Score

V3.1
8.5
/10
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:L/A:N
Base Score Metrics
Exploitability: N/A Impact: N/A

EPSS Score

v2025.03.14
0.007
probability
of exploitation in the wild

There is a 0.7% chance that this vulnerability will be exploited in the wild within the next 30 days.

Updated: 2025-06-25
Exploit Probability
Percentile: 0.703
Higher than 70.3% of all CVEs

Attack Vector Metrics

Attack Vector
NETWORK
Attack Complexity
LOW
Privileges Required
LOW
User Interaction
NONE
Scope
CHANGED

Impact Metrics

Confidentiality
HIGH
Integrity
LOW
Availability
NONE

Description

MindsDB is an open source machine learning platform. An unsafe extraction is being performed using `shutil.unpack_archive()` 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.unpack_archive()` 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.

Available Exploits

No exploits available for this CVE.

Related News

No news articles found for this CVE.

Affected Products

GitHub Security Advisories

Community-driven vulnerability intelligence from GitHub

✓ GitHub Reviewed MODERATE

Arbitrary file write in mindsdb when Extracting Tarballs retrieved from a remote location

GHSA-7x45-phmr-9wqp

Advisory Details

### Summary An unsafe extraction is being performed using `shutil.unpack_archive()` 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.unpack_archive()` 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 `download_file()` 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.unpack_archive()`. The vulnerable code is [L128..L129](https://github.com/mindsdb/mindsdb/blob/69c76e727b8067f32b06ab83bb835a8c416c4f21/mindsdb/interfaces/storage/fs.py#L128..L129) in [fs.py](https://github.com/mindsdb/mindsdb/blob/69c76e727b8067f32b06ab83bb835a8c416c4f21/mindsdb/interfaces/storage/fs.py) file. ```python3 def __init__(self): super().__init__() if 's3_credentials' in self.config['permanent_storage']: self.s3 = boto3.client('s3', **self.config['permanent_storage']['s3_credentials']) else: self.s3 = boto3.client('s3') # User provided remote storage! self.bucket = self.config['permanent_storage']['bucket'] def get(self, local_name, base_dir): remote_name = local_name remote_ziped_name = f'{remote_name}.tar.gz' local_ziped_name = f'{local_name}.tar.gz' local_ziped_path = os.path.join(base_dir, local_ziped_name) os.makedirs(base_dir, exist_ok=True) # Retrieve a potentially malicious tarball self.s3.download_file(self.bucket, remote_ziped_name, local_ziped_path) # Perform an unsafe extraction shutil.unpack_archive(local_ziped_path, base_dir) os.system(f'chmod -R 777 {base_dir}') os.remove(local_ziped_path) ``` ### 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.unpack_archive("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.

Affected Packages

PyPI mindsdb
ECOSYSTEM: ≥0 <22.11.4.3

CVSS Scoring

CVSS Score

5.0

CVSS Vector

CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:L/A:N

Advisory provided by GitHub Security Advisory Database. Published: March 30, 2023, Modified: October 1, 2024

References

Published: 2023-03-30T18:04:56.599Z
Last Modified: 2025-02-12T14:56:13.708Z
Copied to clipboard!