The vulnerability exists in the mcp-kubernetes-server package, specifically within the command.py file. The ShellProcess class in this file is designed to execute shell commands. The exec method of this class uses subprocess.run with shell=True, which is a known dangerous practice when combined with user-controllable input, as it can lead to OS command injection. The run method is a wrapper that calls the exec method, and is therefore also vulnerable.
The vulnerability is triggered when a user sends a request to the /mcp/kubectl endpoint. The server-side code handling this endpoint uses the ShellProcess class to execute kubectl commands. An attacker can craft a malicious request that includes additional shell commands, which will then be executed by the server. The shell=True parameter in the subprocess.run call allows the shell to interpret and execute these injected commands, leading to a command injection vulnerability.
For a security engineer, this means that any instance of mcp-kubernetes-server up to version 0.1.11 is vulnerable. Exploitation of this vulnerability could allow an attacker to execute arbitrary commands on the server, potentially leading to a full compromise of the system. It is crucial to update to a patched version or apply a workaround that disables or restricts access to the vulnerable endpoint.