Looking for the vulnerability index of Invicti's legacy products?
LLM Command Injection - Vulnerability Database

LLM Command Injection

Description

This vulnerability occurs when a Large Language Model (LLM)-powered application accepts user input and passes it to system command execution functions without proper validation or sanitization. Attackers can craft prompts that instruct the LLM to execute arbitrary operating system commands, bypassing intended application logic. This represents a critical flaw in how the application handles the boundary between AI-generated content and system-level operations.

Remediation

Implement multiple layers of defense to prevent command injection:<br/><br/><strong>1. Eliminate Direct Command Execution:</strong> Avoid passing LLM outputs directly to system command interpreters. Use native libraries and APIs instead of shell commands whenever possible.<br/><br/><strong>2. Input Validation and Sanitization:</strong> Apply strict allowlists for acceptable input patterns. Reject any input containing shell metacharacters (e.g., <code>;</code>, <code>|</code>, <code>&</code>, <code>$</code>, <code>`</code>, <code>\n</code>).<br/><br/><strong>3. Use Safe Execution Methods:</strong> If command execution is unavoidable, use parameterized execution methods that prevent injection:<br/><pre>// Python example - SAFE import subprocess subprocess.run(['ls', user_input], shell=False) # Arguments passed as list // Python example - UNSAFE import os os.system(f'ls {user_input}') # Vulnerable to injection</pre><br/><strong>4. Implement Principle of Least Privilege:</strong> Run the application with minimal necessary permissions. Use sandboxing or containerization to limit the impact of successful exploitation.<br/><br/><strong>5. LLM Output Filtering:</strong> Implement post-processing filters to detect and block command-like patterns in LLM responses before they reach execution contexts. Monitor for suspicious command sequences in LLM outputs.<br/><br/><strong>6. Security Monitoring:</strong> Log all command execution attempts and implement alerting for anomalous patterns or unauthorized command usage.

Related Vulnerabilities