CVE-2024-32024
Executive Summary
CVE-2024-32024 is a path injection vulnerability in Kohya_ss, a GUI for Kohya's Stable Diffusion trainers. The flaw resides in the common_gui.py file, specifically within the add_pre_postfix function, which fails to properly sanitize user-supplied input. This allows an attacker to inject arbitrary path traversal sequences, potentially leading to unauthorized file read, write, or deletion on the server. The vulnerability has a CVSS score of 6.5 (Medium) and is fixed in version 23.1.5. No public proof-of-concept (PoC) or exploit code is currently available, but the risk is elevated due to the widespread use of Stable Diffusion tools in AI/ML pipelines.
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
Kohya_ss is a Python-based application distributed via GitHub and PyPI. The vulnerability affects the core GUI component, which is part of the application's source code. Users who install Kohya_ss via pip install kohya_ss or clone the repository directly are at risk. The supply chain risk is moderate, as the vulnerability is in the application itself, not in a dependency. However, if the application is deployed in a containerized or shared environment, the impact could be broader.
CVSS Breakdown & Threat Level
- CVSS Score: 6.5 (Medium)
- Attack Vector (AV): Network (N) – The vulnerability can be exploited remotely.
- Attack Complexity (AC): Low (L) – No special conditions are required.
- Privileges Required (PR): None (N) – No authentication needed.
- User Interaction (UI): None (N) – No user action required.
- Scope (S): Unchanged (U) – The vulnerable component and the impacted component are the same.
- Confidentiality (C): Low (L) – Limited file read access.
- Integrity (I): Low (L) – Limited file write/modification.
- Availability (A): Low (L) – Potential for file deletion or denial of service.
Threat Level: Medium. While the CVSS score is moderate, the lack of authentication and the potential for file system manipulation in AI/ML environments (which often contain sensitive models and data) elevates the risk.
Deep Dive & Mechanics
The vulnerability is a classic path injection (CWE-22) in the add_pre_postfix function within common_gui.py. This function is used to add prefixes or suffixes to file names or paths based on user input. The flaw occurs because the function does not validate or sanitize the user-supplied prefix/suffix string, allowing an attacker to include path traversal characters (e.g., ../).
Root Cause: The add_pre_postfix function likely concatenates user input directly into a file path without proper validation. For example:
def add_pre_postfix(base_path, prefix, suffix):
return os.path.join(os.path.dirname(base_path), prefix + os.path.basename(base_path) + suffix)
If an attacker provides prefix = "../../etc/passwd", the resulting path could traverse outside the intended directory.
Attack Vector: An attacker can send a crafted HTTP request to the Kohya_ss GUI, targeting any endpoint that uses the add_pre_postfix function. This could be part of file upload, model selection, or configuration features.
Impact: Successful exploitation could allow an attacker to:
- Read arbitrary files (e.g., configuration files, SSH keys, model data).
- Write or overwrite files (e.g., inject malicious code into scripts).
- Delete files, leading to denial of service.
Vulnerable vs. Patched Code
Vulnerable Code (before 23.1.5):
# common_gui.py (vulnerable)
def add_pre_postfix(base_path, prefix, suffix):
# No sanitization of prefix or suffix
return os.path.join(os.path.dirname(base_path), prefix + os.path.basename(base_path) + suffix)
Patched Code (version 23.1.5):
# common_gui.py (patched)
import re
def add_pre_postfix(base_path, prefix, suffix):
# Sanitize prefix and suffix to remove path traversal characters
safe_prefix = re.sub(r'[^a-zA-Z0-9_]', '', prefix)
safe_suffix = re.sub(r'[^a-zA-Z0-9_]', '', suffix)
return os.path.join(os.path.dirname(base_path), safe_prefix + os.path.basename(base_path) + safe_suffix)
The patch uses a regular expression to strip any characters that are not alphanumeric or underscores, effectively blocking path traversal attempts.
Exploitation & Lab Setup
Red Team (Exploitation)
Lab Setup:
- Install vulnerable Kohya_ss version (e.g., 23.0.0) on a test VM.
- Ensure the GUI is accessible over the network (default port 7860).
- Identify an endpoint that uses
add_pre_postfix. For example, the model selection feature.
Exploitation Steps:
- Craft a request to the vulnerable endpoint with a malicious prefix:
POST /set_model HTTP/1.1 Host: target:7860 Content-Type: application/x-www-form-urlencoded model_path=/models/stable_diffusion&prefix=../../etc/passwd&suffix= - The server will process the path, potentially reading
/etc/passwdand returning its contents. - For file write, use a similar approach to overwrite a configuration file or inject a web shell.
Note: No public exploit code is available, but the above demonstrates the attack vector.
Blue Team (Defense)
Detection:
- Monitor for unusual file access patterns, especially attempts to read
/etc/passwd,/etc/shadow, or other sensitive files. - Look for HTTP requests containing
../or..\\in parameters related to file paths. - Use the detection rules provided below.
Mitigation:
- Immediately upgrade to Kohya_ss version 23.1.5 or later.
- If upgrade is not possible, apply a virtual patch by deploying a WAF rule to block path traversal patterns.
- Restrict file system permissions for the Kohya_ss process to limit the impact of exploitation.
Indicators of Compromise (IOCs)
- File Paths:
/etc/passwd,/etc/shadow,/root/.ssh/id_rsa,/var/log/auth.log - HTTP Requests: POST requests with parameters containing
../or..\\(e.g.,prefix=../../etc/passwd) - Log Entries: Unusual file access errors in Kohya_ss logs, such as
FileNotFoundErrorfor system files. - Network Traffic: Outbound connections from the Kohya_ss server to unknown IPs (if attacker exfiltrates data).
Detection Engineering
YARA Rule
rule CVE_2024_32024_Path_Injection {
meta:
description = "Detects path injection attempts in Kohya_ss common_gui.py"
author = "Valters IT"
date = "2024-10-27"
reference = "CVE-2024-32024"
strings:
$path_traversal = /\.\.\/|\.\.\\/
$vuln_function = "add_pre_postfix"
condition:
$vuln_function and #path_traversal > 0
}
Sigma Rule
title: CVE-2024-32024 Path Injection in Kohya_ss
id: 12345678-1234-1234-1234-123456789abc
status: experimental
description: Detects path injection attempts targeting Kohya_ss common_gui.py
author: Valters IT
logsource:
category: webserver
product: apache
detection:
selection:
cs-method: 'POST'
cs-uri-query|contains: 'prefix='
cs-uri-query|contains: '../'
condition: selection
falsepositives:
- Legitimate use of '..' in file names (rare)
level: high
Suricata Rule
alert http any any -> any any (msg:"CVE-2024-32024 Kohya_ss Path Injection Attempt"; flow:to_server; content:"POST"; http_method; content:"prefix="; http_client_body; content:"../"; http_client_body; classtype:attempted-admin; sid:1000001; rev:1;)
Remediation & Mitigation
Immediate Actions:
- Upgrade: Update Kohya_ss to version 23.1.5 or later. This is the only complete fix.
- Virtual Patching: If upgrade is not possible, deploy a WAF rule to block requests containing
../or..\\in parameters. - File System Hardening: Run the Kohya_ss process with minimal privileges (e.g., a dedicated user with read-only access to necessary directories).
Long-Term Measures:
- Implement input validation for all user-supplied data, especially file paths.
- Use a secure coding library that automatically sanitizes paths (e.g.,
os.path.abspathandos.path.realpath). - Conduct regular security audits of the codebase.
Valters IT Signature This report was generated by Valters IT Cyber Threat Intelligence Division. For questions, contact threatintel@valtersit.com.