Summary
A 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.
Affected Version
Llama Factory versions <=0.9.0 are affected by this vulnerability.
Root Cause
The 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.
Vulnerable snippet:
# https://github.com/hiyouga/LLaMA-Factory/blob/bd639a137e6f46e1a0005cc91572f5f1ec894f74/src/llamafactory/webui/runner.py#L304-L323
def _launch(self, data: Dict["Component", Any], do_train: bool) -> Generator[Dict["Component", Any], None, None]:
...
args = self._parse_train_args(data) if do_train else self._parse_eval_args(data)
...
self.trainer = Popen(f"llamafactory-cli train {save_cmd(args)}", env=env, shell=True)
yield from self.monitor()
Proof of Concept (PoC)
Steps to Reproduce
Deploy llama factory
Execute the exploitation script from: https://gist.github.com/superboy-zjc/f2d2b93ae511c445ba97e144b70e534d
python3 llama-factory-rce.py --url http://127.0.0.1:7861 --cmd "curl XXX" --trace
Bad actors are able to execute any OS command as they want.
Remediation Recommendations
Avoid using shell=True in Popen.
- Instead, pass the command and its arguments as a list. This prevents user inputs from being executed as part of a shell command.
cmd = [
"llamafactory-cli",
"train",
*save_cmd(args).split(),
]
self.trainer = Popen(cmd, env=env)
Impact
Exploitation of this vulnerability allows attackers to:
- Execute arbitrary OS commands on the server.
- Potentially compromise sensitive data or escalate privileges.
- Deploy malware or create persistent backdoors in the system.
This significantly increases the risk of data breaches and operational disruption.
Untrusted input reaches a shell command, allowing arbitrary commands to run on the host. Typical impact: code execution in the application's environment.
CVE-2024-52803 has a CVSS score of 7.5 (High). The vector is network-reachable, no privileges required, and no user interaction. A CVSS score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether this affects your application depends on whether the vulnerable code is present and reachable in your environment. A fixed version is available (0.9.1); upgrading removes the vulnerable code path.
Affected versions
Security releases
Kodem intelligence
Severity tells you how bad this could be in the worst case. It does not tell you whether you are exposed. Exploitability and impact are functions of runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A vulnerable package can sit in your dependency tree and never run.
Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter. Kodem's runtime-powered SCA identifies whether this CVE is reachable in your applications.
Remediation advice
Kodem Kai can prioritize this vulnerability in your dependency tree and generate a fix recommendation.
Frequently Asked Questions
- What is CVE-2024-52803? CVE-2024-52803 is a high-severity OS command injection vulnerability in llamafactory (pip), affecting versions <= 0.9.0. It is fixed in 0.9.1. Untrusted input reaches a shell command, allowing arbitrary commands to run on the host.
- How severe is CVE-2024-52803? CVE-2024-52803 has a CVSS score of 7.5 (High). This score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether it represents real risk in your environment depends on whether the vulnerable code is present and reachable.
- Which versions of llamafactory are affected by CVE-2024-52803? llamafactory (pip) versions <= 0.9.0 is affected.
- Is there a fix for CVE-2024-52803? Yes. CVE-2024-52803 is fixed in 0.9.1. Upgrade to this version or later.
- Is CVE-2024-52803 exploitable, and should I be worried? Whether CVE-2024-52803 is exploitable in your environment depends on whether the vulnerable code is present and reachable. A CVSS score is a worst-case rating; it does not account for your specific deployment, configuration, or usage patterns. Kodem, an Intelligent Application Security platform, uses runtime intelligence to show which vulnerabilities actually execute in production, so you can focus on the ones that represent real risk. Get a demo
- What actually determines whether CVE-2024-52803 is exploitable, and how bad it is? Exploitability and impact are not fixed properties of a CVE. They depend on runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A high CVSS score on a dependency that never runs is not the same as real risk. Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter.
- How do I fix CVE-2024-52803? Upgrade
llamafactoryto 0.9.1 or later.