MS SWIFT Remote Code Execution via unsafe PyYAML deserialization
链接: https://github.com/advisories/GHSA-fm6c-f59h-7mmg
仓库 Star: 9003
参考链接:
https://github.com/modelscope/ms-swift/security/advisories/GHSA-fm6c-f59h-7mmg
https://github.com/modelscope/ms-swift/commit/b3418ed9b050dc079553c275c5ed14cfb2b66cf7
描述:
Description
A Remote Code Execution (RCE) vulnerability exists in the modelscope/ms-swift project due to unsafe use of yaml.load()
in combination with vulnerable versions of the PyYAML library (≤ 5.3.1). The issue resides in the tests/run.py
script, where a user-supplied YAML configuration file is deserialized using yaml.load()
with yaml.FullLoader
.
If an attacker can control or replace the YAML configuration file provided to the --run_config
argument, they may inject a malicious payload that results in arbitrary code execution.
Affected Repository
- Project: modelscope/ms-swift
- Affect versions: latest
- File:
tests/run.py
- GitHub Permalink: https://github.com/modelscope/ms-swift/blob/e02ebfdf34f979bbdba9d935acc1689f8d227b38/tests/run.py#L420
- Dependency: PyYAML <= 5.3.1
Vulnerable Code
1 |
|
Proof of Concept (PoC)
Step 1: Create malicious YAML file (exploit.yaml
)
1 |
|
Step 2: Execute with vulnerable PyYAML (<= 5.3.1)
1 |
|
This results in execution of os.system
, proving code execution.
Mitigation
- Replace
yaml.load()
withyaml.safe_load()
- Upgrade PyYAML to version 5.4 or later
Example Fix:
1 |
|
Author
- Discovered by: Yu Rong (戎誉) and Hao Fan (凡浩)
- Contact: [anchor.rongyu020221@gmail.com]