Описание
mindsdb arbitrary file write when extracting a remotely retrieved Tarball
Summary
An unsafe extraction is being performed using tarfile.extractall()
from a remotely retrieved tarball. Which may lead to the writing of the extracted files to an unintended location. Sometimes, the vulnerability is called a TarSlip or a ZipSlip variant.
Details
I commented the following snippet of code as a vulnerability details. The code is from file.py#L26..L134
So, a remotely available tarball is being retrieved and written to the server filesystem in chunks, and then, if the extension ends with .tar.gz
of a compressed tarball, the mindsdb app applies tarfile.extractall()
directly with no checks for the destination.
However, according to the following warning from the official documentation;
Warning: Never extract archives from untrusted sources without prior inspection. It is possible that files are created outside of path, e.g. members that have absolute filenames starting with "/" or filenames with two dots "..".
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.
Attack Scenario
An attacker could craft a malicious tarball with a filename path, such as ../../../../../../../../etc/passwd, and then serve the archive remotely, proceed to the PUT request of the tarball through mindsdb and overwrite the system files of the hosting server for instance.
Mitigation
Potential mitigation could be to:
- Use a safer module, like
zipfile
. - Use an alternative of
tarfile
, such astarsafe
. - Validate the location or the absolute path of the extracted files and discard those with malicious paths such as relative path
../../..
or absolute path such as/etc/password
. A simple wrapper could be written to raise an exception when a path traversal may be identified.
This is similar to the other report GHSA-7x45-phmr-9wqp.
Ссылки
- https://github.com/mindsdb/mindsdb/security/advisories/GHSA-2g5w-29q9-w6hx
- https://nvd.nist.gov/vuln/detail/CVE-2023-30620
- https://github.com/mindsdb/mindsdb/commit/4419b0f0019c000db390b54d8b9d06e1d3670039
- https://github.com/mindsdb/mindsdb/blob/afedd37c16e579b6dc075b0814e42d0505ccdc07/mindsdb/api/http/namespaces/file.py#L26..L134
- https://github.com/mindsdb/mindsdb/releases/tag/v23.2.1.0
- https://github.com/pypa/advisory-database/tree/main/vulns/mindsdb/PYSEC-2023-27.yaml
Пакеты
mindsdb
< 23.2.1.0
23.2.1.0
Связанные уязвимости
mindsdb is a Machine Learning platform to help developers build AI solutions. In affected versions an unsafe extraction is being performed using `tarfile.extractall()` from a remotely retrieved tarball. Which may lead to the writing of the extracted files to an unintended location. Sometimes, the vulnerability is called a TarSlip or a ZipSlip variant. An attacker may leverage this vulnerability to overwrite any local file which the server process has access to. There is no risk of file exposure with this vulnerability. This issue has been addressed in release `23.2.1.0 `. Users are advised to upgrade. There are no known workarounds for this vulnerability.