// For flags

CVE-2023-50731

MindsDB has arbitrary file write in file.py

Severity Score

9.1
*CVSS v3.1

Exploit Likelihood

*EPSS

Affected Versions

*CPE

Public Exploits

1
*Multiple Sources

Exploited in Wild

-
*KEV

Decision

-
*SSVC
Descriptions

MindsDB is a SQL Server for artificial intelligence. Prior to version 23.11.4.1, the `put` method in `mindsdb/mindsdb/api/http/namespaces/file.py` does not validate the user-controlled name value, which is used in a temporary file name, which is afterwards opened for writing on lines 122-125, which leads to path injection. Later in the method, the temporary directory is deleted on line 151, but since we can write outside of the directory using the path injection vulnerability, the potentially dangerous file is not deleted. Arbitrary file contents can be written due to `f.write(chunk)` on line 125. Mindsdb does check later on line 149 in the `save_file` method in `file-controller.py` which calls the `_handle_source` method in `file_handler.py` if a file is of one of the types `csv`, `json`, `parquet`, `xls`, or `xlsx`. However, since the check happens after the file has already been written, the files will still exist (and will not be removed due to the path injection described earlier), just the `_handle_source` method will return an error. The same user-controlled source source is used also in another path injection sink on line 138. This leads to another path injection, which allows an attacker to delete any `zip` or `tar.gz` files on the server.

MindsDB es un servidor SQL para inteligencia artificial. Antes de la versión 23.11.4.1, el método `put` en `mindsdb/mindsdb/api/http/namespaces/file.py` no valida el valor del nombre controlado por el usuario, que se usa en un nombre de archivo temporal, que se muestra posteriormente. abierto para escritura en las líneas 122-125, lo que conduce a inyección de ruta. Más adelante en el método, el directorio temporal se elimina en la línea 151, pero como podemos escribir fuera del directorio utilizando la vulnerabilidad de inyección de ruta, el archivo potencialmente peligroso no se elimina. Se pueden escribir contenidos de archivos arbitrarios debido a `f.write(chunk)` en la línea 125. Mindsdb verifica más adelante en la línea 149 en el método `save_file` en `file-controller.py` que llama al método `_handle_source` en ` file_handler.py` si un archivo es de uno de los tipos `csv`, `json`, `parquet`, `xls` o `xlsx`. Sin embargo, dado que la verificación se realiza después de que el archivo ya se haya escrito, los archivos seguirán existiendo (y no se eliminarán debido a la inyección de ruta descrito anteriormente), solo el método `_handle_source` devolverá un error. La misma fuente controlada por el usuario también se utiliza en otro receptor de inyección de ruta en la línea 138. Esto conduce a otra inyección de ruta, que permite a un atacante eliminar cualquier archivo `zip` o `tar.gz` en el servidor.

*Credits: N/A
CVSS Scores
Attack Vector
Network
Attack Complexity
Low
Privileges Required
None
User Interaction
None
Scope
Unchanged
Confidentiality
None
Integrity
High
Availability
High
* Common Vulnerability Scoring System
SSVC
  • Decision:-
Exploitation
-
Automatable
-
Tech. Impact
-
* Organization's Worst-case Scenario
Timeline
  • 2023-12-11 CVE Reserved
  • 2023-12-22 CVE Published
  • 2024-01-06 EPSS Updated
  • 2024-08-02 CVE Updated
  • 2024-08-02 First Exploit
  • ---------- Exploited in Wild
  • ---------- KEV Due Date
CWE
  • CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
  • CWE-918: Server-Side Request Forgery (SSRF)
CAPEC
Affected Vendors, Products, and Versions
Vendor Product Version Other Status
Vendor Product Version Other Status <-- --> Vendor Product Version Other Status
Mindsdb
Search vendor "Mindsdb"
Mindsdb
Search vendor "Mindsdb" for product "Mindsdb"
< 23.11.4.1
Search vendor "Mindsdb" for product "Mindsdb" and version " < 23.11.4.1"
-
Affected