Skip to content
README.md

README.md

github.com • November 25, 2026

A critical command injection vulnerability exists in the KubeSphere terminal v1alpha2 API. The /file download endpoint passes user-controlled input from the path query parameter directly into a sh -c shell command executed inside the target container via the Kubernetes exec API. An authenticated attacker can achieve remote code execution within any accessible container without explicit authorization checks on the download endpoint.

Vendor: KubeSphere Product: KubeSphere Affected Versions: 4.0.0 through 4.1.3-rc.0 CVSS v3.1: 9.9 Severity: Critical

The DownloadFile handler accepts a path query parameter (line 380) and passes it unsanitized into two shell commands constructed via fmt.Sprintf . These commands are executed inside the target container through the Kubernetes exec API using the ks-apiserver's service account.

File: pkg/kapis/terminal/v1alpha2/handler.go

getFileSize (line 284):

initReadFrom (line 330):

The filePath originates from request.QueryParameter("path") at line 380. Since the commands run through sh -c , shell metacharacters like ; , | , $() , $(()) , and redirection operators > allow arbitrary commands to be injected. No input validation, no filepath.Clean() , and no allowlist is applied to the input.

Additionally, the DownloadFile handler (lines 379-399) contains no explicit authorization check — unlike HandleTerminalSession which validates create permissions on pods/exec . The upload and download handlers rely entirely on the global RBAC filter, which defaults to AlwaysAllow in default installations.

Endpoint: GET /kapis/terminal.kubesphere.io/v1alpha2/namespaces/{namespace}/pods/{pod}/file File: pkg/kapis/terminal/v1alpha2/handler.go Functions: DownloadFile (379), getFileSize (284), initReadFrom (330) Parameter: path (query)

Obtain network access to the KubeSphere API server (port 30880 by default, or via port-forward)

Authenticate as a valid KubeSphere user (default admin password P@88w0rd )

Deploy a target pod or use an existing one

Send a crafted GET request with command injection in the path parameter

Verify code execution inside the container

Step 1: Acquire Access

Port-forward to the ks-apiserver service:

Step 2: Deploy Victim Pod and Authenticate

Obtain a KubeSphere JWT token using the default admin credentials:

Step 3: Exploit Command Injection

The injection payload uses stderr redirection to suppress the tar command output while injecting the attacker's command:

The resulting shell command inside getFileSize :

Shell interpretation:

tar cf - /dev/null 1>&2 : tar runs, its archive data is redirected to stderr (discarded as Stderr: false in PodExecOptions)

echo PWNED>/tmp/pwned : writes the string "PWNED" to /tmp/pwned inside the victim container

echo 1024 | wc -c : outputs "5\n" to stdout, satisfying getFileSize 's uint64 parsing requirement

Step 4: Verify Remote Code Execution

Confirm the file was written inside the container:

Execute id and read the result to prove full command execution:

An authenticated attacker with network access to the KubeSphere API server can execute arbitrary commands inside any accessible container. This enables container compromise, mounted Kubernetes secret exfiltration, service account token theft, pod-to-cluster privilege escalation via node hostPath volumes, and lateral movement through the internal network. The command executes as root inside the container (typically the container's default user), and the ks-apiserver's service account is used for the exec call, meaning no additional RBAC bypass is required.

Replace shell-based execution with direct tar argument invocation: Command: [] string { "tar" , "cf" , "-" , filePath }

Validate the filePath with filepath.Clean() and ensure it resolves to an allowed directory

Add explicit authorization checks for pods/exec create permission on the download and upload endpoints

Sanitize and validate all user-controlled inputs in terminal-related handlers