7.5
CWE
78 77
Advisory Published
Updated

GHSA-hj3w-wrh4-44vp: OS Command Injection

First published: Thu Nov 21 2024(Updated: )

## 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. ## Impact Exploitation of this vulnerability allows attackers to: 1. Execute arbitrary OS commands on the server. 2. Potentially compromise sensitive data or escalate privileges. 3. Deploy malware or create persistent backdoors in the system. This significantly increases the risk of data breaches and operational disruption. ## 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: ```python # 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 ```bash python3 llama-factory-rce.py --url http://127.0.0.1:7861 --cmd "curl XXX" --trace ``` ![llama-factory-rce](https://api.2h0ng.wiki:443/noteimages/2024/11/21/00-33-37-5347128a141f8765e7d218c89d94162a.gif) 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. ```python cmd = [ "llamafactory-cli", "train", *save_cmd(args).split(), ] self.trainer = Popen(cmd, env=env) ```

Affected SoftwareAffected VersionHow to fix
pip/llamafactory<=0.9.0
0.9.1

Never miss a vulnerability like this again

Sign up to SecAlerts for real-time vulnerability data matched to your software, aggregated from hundreds of sources.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2024 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203