{"id":"CVE-2024-52803","aliases":["CVE-2024-52803","GHSA-hj3w-wrh4-44vp","PYSEC-2026-1575"],"related":[],"kind":"vulnerability","state":"published","title":"LLama Factory Remote OS Command Injection Vulnerability","summary":"LLama Factory enables fine-tuning of large language models. 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. This vulnerability is fixed in 0.9.1.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"LLama Factory enables fine-tuning of large language models. 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. This vulnerability is fixed in 0.9.1.","source":"cvelist"},{"lang":"en","text":"## 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![llama-factory-rce](https://api.2h0ng.wiki:443/noteimages/2024/11/21/00-33-37-5347128a141f8765e7d218c89d94162a.gif)\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```","format":"markdown","source":"ghsa"},{"lang":"es","text":"LLama Factory permite el ajuste fino de modelos de lenguaje de gran tamaño. Se ha identificado una vulnerabilidad crítica de inyección remota de comandos del sistema operativo en el proceso de entrenamiento de LLama Factory. Esta vulnerabilidad surge del manejo inadecuado de la entrada del usuario, lo que permite que actores maliciosos ejecuten comandos arbitrarios del sistema operativo en el sistema host. El problema se debe al uso inseguro de la función `Popen` con `shell=True`, junto con una entrada del usuario no desinfectada. Se requiere una solución inmediata para mitigar el riesgo. Esta vulnerabilidad se solucionó en la versión 0.9.1.","source":"nvd"}],"published":"2024-11-21T16:53:18.398Z","modified":"2026-07-07T17:57:01.974Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N","score":7.5,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N","score":7.5,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N","score":7.5,"rating":"HIGH"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H","score":9.8,"rating":"CRITICAL"},{"scorer":"PyPA Advisory Database","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N","score":7.5,"rating":"HIGH"}],"cwes":["CWE-78","CWE-79"],"affected":[{"ranges":[{"version":"< 0.9.1","status":"affected"}],"vendor":"hiyouga","product":"LLaMA-Factory","source":"cvelist"},{"ranges":[{"type":"custom","introduced":"0","fixed":"0.9.1","status":"affected"}],"vendor":"llama-factory","product":"llama-factory","cpe":"cpe:2.3:a:llama-factory:llama-factory:*:*:*:*:*:*:*:*","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"0.9.1"}],"ecosystem":"PyPI","package":"llamafactory","purl":"pkg:pypi/llamafactory","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"0.9.1"}],"vendor":"hiyouga","product":"llama-factory","cpe":"cpe:2.3:a:hiyouga:llama-factory:*:*:*:*:*:*:*:*","source":"nvd"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"0.9.1"}],"ecosystem":"PyPI","package":"llamafactory","purl":"pkg:pypi/llamafactory","source":"pysec"}],"references":[{"url":"https://github.com/hiyouga/LLaMA-Factory/security/advisories/GHSA-hj3w-wrh4-44vp","tags":["exploit","vendor-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/hiyouga/LLaMA-Factory/commit/b3aa80d54a67da45e9e237e349486fb9c162b2ac","tags":["patch","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://gist.github.com/superboy-zjc/f2d2b93ae511c445ba97e144b70e534d","tags":["exploit","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2024-52803","tags":["advisory"],"sources":["ghsa","pysec"]},{"url":"https://github.com/hiyouga/LLaMA-Factory","tags":["package"],"sources":["ghsa","pysec"]},{"url":"https://pypi.org/project/llamafactory","tags":["package"],"sources":["pysec"]},{"url":"https://github.com/advisories/GHSA-hj3w-wrh4-44vp","tags":["advisory"],"sources":["pysec"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"yes","technicalImpact":"partial","date":"2024-11-21T21:05:38.878Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2024-52803","url":"https://www.cve.org/CVERecord?id=CVE-2024-52803","licence":"CVE Terms of Use","modified":"2024-11-21T21:12:06.172Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-hj3w-wrh4-44vp","url":"https://github.com/advisories/GHSA-hj3w-wrh4-44vp","licence":"CC-BY-4.0","modified":"2026-07-07T17:57:01.974Z"},{"source":"nvd","name":"NVD","id":"CVE-2024-52803","url":"https://nvd.nist.gov/vuln/detail/CVE-2024-52803","licence":"Public domain","modified":"2026-06-17T08:07:39.417Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2026-1575","url":"https://osv.dev/vulnerability/PYSEC-2026-1575","licence":"CC-BY-4.0","modified":"2026-07-07T17:46:54.137Z"}],"updatedAt":"2026-11-25T22:58:49.009Z","epss":{"score":0.02323,"percentile":0.83953,"date":"2026-12-01T12:00:22.000Z"}}