CVE-2024-32027
Executive Summary
CVE-2024-32027 is a critical command injection vulnerability in Kohya_ss, a GUI for Kohya's Stable Diffusion trainers. The vulnerability resides in the finetune_gui.py file and allows an unauthenticated attacker to execute arbitrary commands on the server. With a CVSS score of 9.1, this vulnerability poses a severe risk to confidentiality, integrity, and availability. The vendor has released a fix in version 23.1.5, but the patch status for earlier versions remains unpatched. No public proof-of-concept (PoC) or exploit code has been identified at this time.
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 application logic, not a dependency. However, users should verify the integrity of their installation and ensure they are using the latest patched version (23.1.5 or later). The package is not signed, and there is no official checksum verification mechanism, increasing the risk of supply chain attacks if the repository is compromised.
CVSS Breakdown & Threat Level
- CVSS Score: 9.1 (Critical)
- Attack Vector: Network (AV:N)
- Attack Complexity: Low (AC:L)
- Privileges Required: None (PR:N)
- User Interaction: None (UI:N)
- Scope: Unchanged (S:U)
- Confidentiality Impact: High (C:H)
- Integrity Impact: High (I:H)
- Availability Impact: High (A:H)
The vulnerability is remotely exploitable without authentication, making it a prime target for automated scanning and exploitation. The low attack complexity and high impact make this a critical threat.
Deep Dive & Mechanics
The vulnerability exists in the finetune_gui.py script, which handles user input for fine-tuning parameters. The application fails to sanitize or validate user-supplied data before passing it to a system command (e.g., via os.system() or subprocess.Popen() with shell=True). An attacker can inject arbitrary shell commands by crafting malicious input in fields such as dataset paths, model names, or training arguments.
For example, if the application constructs a command like:
python train.py --data_dir {user_input}
An attacker could provide:
; rm -rf / ; echo pwned
This would result in the execution of:
python train.py --data_dir ; rm -rf / ; echo pwned
Leading to arbitrary command execution.
The root cause is the lack of input sanitization and the use of shell execution functions without proper escaping. The fix in version 23.1.5 likely involves using shlex.quote() or switching to subprocess.Popen() with a list of arguments (no shell=True).
Vulnerable vs. Patched Code
Vulnerable Code (v22.6.1):
import os
def run_finetune(user_input):
command = f"python train.py --data_dir {user_input}"
os.system(command)
Patched Code (v23.1.5):
import subprocess
import shlex
def run_finetune(user_input):
safe_input = shlex.quote(user_input)
command = f"python train.py --data_dir {safe_input}"
subprocess.Popen(command, shell=False)
The patched version uses shlex.quote() to escape shell metacharacters and disables shell=True to prevent command injection.
Exploitation & Lab Setup
Red Team
Prerequisites:
- Kohya_ss v22.6.1 or earlier running on a target system.
- Network access to the web interface (default port 7860).
Exploitation Steps:
- Identify the vulnerable endpoint (e.g.,
/finetuneor similar). - Craft a POST request with a malicious payload in the
data_dirparameter. - Execute the request to trigger command injection.
Example Payload:
curl -X POST http://target:7860/finetune \
-d "data_dir=;id > /tmp/pwned.txt;"
Verification:
curl http://target:7860/static/pwned.txt
Blue Team
Detection:
- Monitor for unusual shell commands in process logs (e.g.,
os.system,subprocess.Popenwithshell=True). - Look for requests containing shell metacharacters (
;,|,&,$(),`) in parameters. - Use the detection rules provided below.
Hunting:
- Search for
finetune_gui.pyprocesses with unexpected arguments. - Review web server logs for anomalous POST requests to
/finetune.
Indicators of Compromise (IOCs)
- Network:
- POST requests to
/finetunewith shell metacharacters in parameters. - Outbound connections to attacker-controlled IPs from the Kohya_ss server.
- POST requests to
- File System:
- Unexpected files in
/tmp/or web root (e.g.,pwned.txt). - Modified or deleted files in the Kohya_ss installation directory.
- Unexpected files in
- Process:
- Child processes spawned by
finetune_gui.py(e.g.,id,curl,nc). - Unusual shell processes (e.g.,
/bin/sh -c).
- Child processes spawned by
Detection Engineering
YARA Rule
rule CVE_2024_32027_Command_Injection {
meta:
description = "Detects command injection attempts in Kohya_ss finetune_gui.py"
author = "Valters IT"
date = "2025-04-01"
cve = "CVE-2024-32027"
strings:
$s1 = "os.system" ascii nocase
$s2 = "subprocess.Popen" ascii nocase
$s3 = "shell=True" ascii nocase
$s4 = "finetune_gui.py" ascii nocase
condition:
any of ($s1, $s2) and $s3 and $s4
}
Sigma Rule
title: CVE-2024-32027 Command Injection in Kohya_ss
id: 12345678-1234-1234-1234-123456789012
status: experimental
description: Detects command injection attempts via shell metacharacters in Kohya_ss finetune_gui.py
author: Valters IT
date: 2025-04-01
logsource:
category: webserver
product: apache
detection:
selection:
cs-method: 'POST'
cs-uri-stem: '/finetune'
cs-uri-query|contains:
- ';'
- '|'
- '&'
- '$('
- '`'
condition: selection
falsepositives:
- Legitimate use of special characters in dataset paths (unlikely)
level: critical
Suricata Rule
alert http $HOME_NET any -> $EXTERNAL_NET any (
msg:"CVE-2024-32027 Kohya_ss Command Injection Attempt";
flow:to_server,established;
content:"POST"; http_method;
content:"/finetune"; http_uri;
content:"data_dir"; http_client_body;
pcre:"/(;|\||&|\$\(|`)/Ri";
classtype:attempted-admin;
sid:1000001;
rev:1;
)
Remediation & Mitigation
Immediate Actions:
- Upgrade Kohya_ss to version 23.1.5 or later.
- If upgrade is not possible, restrict network access to the Kohya_ss web interface (e.g., firewall rules, VPN).
- Implement a Web Application Firewall (WAF) rule to block requests containing shell metacharacters.
Long-term Measures:
- Conduct a code review of all user input handling in the application.
- Use parameterized commands or
subprocess.Popen()with a list of arguments (noshell=True). - Implement input validation and sanitization using libraries like
shlex. - Enable logging and monitoring for all system command executions.
Valters IT Signature
This report was generated by Valters IT Cyber Threat Intelligence. For questions or support, contact threatintel@valtersit.com.