CVE-2024-52803: Llamafactory LLama Factory Remote OS Command Vulnerability
HIGHCVE-2024-52803 is a HIGH (CVSS 7.5) llama factory remote os command vulnerability (CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')) affecting Llamafactory libraries in the PyPI ecosystem. The issue involves llama factory remote os command injection vulnerability. Remediation is available by upgrading affected packages to version 0.9.1.
CVE-2024-52803 at a Glance
Security Impact
CVSS: 7.5
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N).
How to Fix CVE-2024-52803
To remediate this vulnerability, upgrade all affected Llamafactory dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
pip install llamafactory>=0.9.1
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
pip show llamafactory
How to Check if You Are Affected
To determine whether your Python environment is affected by CVE-2024-52803, inspect your installed packages using pip:
pip show llamafactory
Analyze the terminal output to locate any version of Llamafactory in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.9.1), your application is affected.
Note: The pip show llamafactory command checks currently installed packages in your active Python environment.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection'), where the product constructs all or part of an os command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended os command when it is sent to a downstream component. In Llamafactory, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
CVE-2024-52803 Affected Llamafactory Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
llamafactory
|
PyPI |
< 0.9.1
|
0.9.1
|
References
Frequently Asked Questions
What is CVE-2024-52803?
Which Llamafactory versions are affected?
What version fixes CVE-2024-52803?
Is llamafactory affected?
What is the CVSS score of CVE-2024-52803?
What CWE is associated with CVE-2024-52803?
How can I check PyPI dependencies for CVE-2024-52803?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-hj3w-wrh4-44vp",
"modified" : "2025-08-27T18:40:58Z",
"published" : "2024-11-21T22:20:45Z",
"aliases" : [ "CVE-2024-52803" ],
"summary" : "LLama Factory Remote OS Command Injection Vulnerability",
"details" : "## Summary\n\nA critical remote OS command injection vulnerability has been identified in the Llama Factory training process. This vulnerability arises from improper handling of user input, allowing malicious actors to execute arbitrary OS commands on the host system. The issue is caused by insecure usage of the `Popen` function with `shell=True`, coupled with unsanitized user input. Immediate remediation is required to mitigate the risk.\n\n## Affected Version\n\nLlama Factory versions **<=0.9.0** are affected by this vulnerability.\n\n## Impact\n\nExploitation of this vulnerability allows attackers to:\n\n1. Execute arbitrary OS commands on the server.\n2. Potentially compromise sensitive data or escalate privileges.\n3. Deploy malware or create persistent backdoors in the system.\n\nThis significantly increases the risk of data breaches and operational disruption.\n\n## Root Cause\n\nThe vulnerability originates from the training process where the `output_dir` value, obtained from the user input, is injected into the popen function without any sanitization. Furthermore, popen is invoked in a unsafe way by enabling the interact shell (`shell=True`), leading to remote OS command injection vulnerability.\n\nVulnerable snippet: \n\n```python\n# https://github.com/hiyouga/LLaMA-Factory/blob/bd639a137e6f46e1a0005cc91572f5f1ec894f74/src/llamafactory/webui/runner.py#L304-L323\ndef _launch(self, data: Dict[\"Component\", Any], do_train: bool) -> Generator[Dict[\"Component\", Any], None, None]:\n\t\t\t\t...\n args = self._parse_train_args(data) if do_train else self._parse_eval_args(data)\n\t\t\t\t...\n self.trainer = Popen(f\"llamafactory-cli train {save_cmd(args)}\", env=env, shell=True)\n yield from self.monitor()\n```\n\n## Proof of Concept (PoC)\n\n### Steps to Reproduce\n\n- Deploy llama factory\n\n- Execute the exploitation script from: https://gist.github.com/superboy-zjc/f2d2b93ae511c445ba97e144b70e534d\n\n ```bash\n python3 llama-factory-rce.py --url http://127.0.0.1:7861 --cmd \"curl XXX\" --trace\n ```\n\n\n\nBad actors are able to execute any OS command as they want.\n\n## Remediation Recommendations\n\n**Avoid using `shell=True` in `Popen`.**\n\n- Instead, pass the command and its arguments as a list. This prevents user inputs from being executed as part of a shell command.\n\n```python\ncmd = [\n \"llamafactory-cli\",\n \"train\", \n \t*save_cmd(args).split(),\n]\nself.trainer = Popen(cmd, env=env)\n```",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "PyPI",
"name" : "llamafactory"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "0.9.1"
} ]
} ],
"database_specific" : {
"last_known_affected_version_range" : "<= 0.9.0"
}
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/hiyouga/LLaMA-Factory/security/advisories/GHSA-hj3w-wrh4-44vp"
}, {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-52803"
}, {
"type" : "WEB",
"url" : "https://github.com/hiyouga/LLaMA-Factory/commit/b3aa80d54a67da45e9e237e349486fb9c162b2ac"
}, {
"type" : "WEB",
"url" : "https://gist.github.com/superboy-zjc/f2d2b93ae511c445ba97e144b70e534d"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/hiyouga/LLaMA-Factory"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-78", "CWE-79" ],
"severity" : "HIGH",
"github_reviewed" : true,
"github_reviewed_at" : "2024-11-21T22:20:45Z",
"nvd_published_at" : "2024-11-21T17:15:24Z"
}
}