GHSA-95fj-3w7g-4r27 Nuclio Shell Runtime Command Injection Leading to Privilege Escalation
SummaryThis vulnerability exists in Nuclio's Shell Runtime component, allowing attackers with function invocation permissions to inject malicious commands via HTTP request headers, execute arbitrary code with root privileges in function containers, steal ServiceAccount Tokens with cluster-admin level permissions, and ultimately achieve complete control over the entire Kubernetes cluster. Recommended CWE classification: CWE-78 (OS Command Injection).Nuclio Shell Runtime processes the `X-Nuclio-Arguments` HTTP header without validation or escaping, directly concatenating user input into shell commands executed via `sh -c`. This allows arbitrary command injection, enabling attackers to read sensitive files (including ServiceAccount tokens) and access the Kubernetes API with cluster-level privileges.DetailsVulnerability DescriptionThe Nuclio Shell Runtime component contains a critical command injection vulnerability in how it processes user-supplied arguments. When a function is invoked via HTTP, the runtime reads the `X-Nuclio-Arguments` header and directly incorporates its value into shell commands without any validation or sanitization.Root Cause Analysis**Vulnerable Code Location 1:** `pkg/processor/runtime/shell/runtime.go:289-297`The function retrieves the `X-Nuclio-Arguments` header value and splits it by spaces without any validation. Shell metacharacters like `;`, `|`, `&&`, backticks, and `$()` are not filtered or escaped.**Vulnerable Code Location 2:** `pkg/processor/runtime/shell/runtime.go:204-213`The runtime joins the command array (which includes user-controlled arguments) into a single string and executes it using `sh -c`. This execution mode interprets shell metacharacters, enabling command injection.Attack FlowAttacker sends HTTP request to Nuclio function with malicious `X-Nuclio-Arguments` headerRuntime extracts header value without validationMalicious payload is concatenated into shell commandCommand is executed via `sh -c` with root privilegesAttacker executes arbitrary commands (e.g., reading ServiceAccount token)Attacker uses stolen token to access Kubernetes API with cluster-admin privilegesPoCEnvironment Setup**Prerequisites:**Docker installedkubectl installedHelm 3.x installed8GB RAM minimum**Step 1: Create Kubernetes Cluster****Step 2: Setup Local Registry****Step 3: Install Nuclio****Step 4: Deploy Vulnerable Function**Exploitation**Test 1: Verify Command Injection****Expected Output:****Test 2: Extract ServiceAccount Token****Expected Output:****Test 3: Validate Token Privileges****Expected Output:**This confirms the token has cluster-admin level permissions.**Test 4: Verify Cluster Access**Alternative Injection Methods**Backtick Injection:****$() Syntax Injection:**Both methods successfully extract the token.ImpactSeverity AssessmentThis vulnerability enables complete cluster compromise through a multi-stage attack:**Stage 1: Command Injection**Attacker injects malicious commands via HTTP headerCommands execute with root privileges in function containerNo authentication or authorization checks on command content**Stage 2: Credential Theft**Attacker reads ServiceAccount token from mounted secretToken belongs to `system:serviceaccount:nuclio:default`Token has cluster-admin level permissions**Stage 3: Privilege Escalation**Attacker uses stolen token to authenticate to Kubernetes APIGains full control over all cluster resourcesCan read all secrets, create/modify/delete any resourceAffected Resources**Confidentiality Impact:** HighAll secrets across all namespaces can be readDatabase credentials, API keys, certificates exposedApplication data and configuration accessible**Integrity Impact:** HighAttacker can modify any cluster resourceCan deploy malicious workloadsCan alter RBAC policies and security controlsCan inject backdoors for persistent access**Availability Impact:** MediumAttacker can delete critical resourcesCan deploy resource-intensive workloads causing DoSCan disrupt cluster operationsReal-World Attack Scenarios**Scenario 1: Data Breach**Attacker gains function invocation access (low privilege)Injects command to extract ServiceAccount tokenUses token to read all secrets in production namespaceExfiltrates database credentials and API keysAccesses production databases and external services**Scenario 2: Supply Chain Compromise**Attacker compromises CI/CD pipelineDeploys malicious Nuclio functionFunction automatically executes on deploymentEstablishes persistent backdoor in clusterPivots to compromise other applications**Scenario 3: Ransomware Attack**Attacker exploits vulnerability to gain cluster accessDeploys crypto-mining or ransomware podsEncrypts persistent volumesDemands ransom for decryption keysSeverity**CVSS v3.1 Vector:** CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:L**CVSS Score:** 9.1 (Critical)**Justification:****Attack Vector (Network):** Exploitable remotely via HTTP**Attack Complexity (Low):** No special conditions required**Privileges Required (Low):** Only function invocation permission needed**User Interaction (None):** Fully automated exploitation**Scope (Changed):** Breaks out of function container to cluster level**Confidentiality (High):** Complete access to all secrets**Integrity (High):** Full control over cluster resources**Availability (Low):** Limited direct availability impactAffected VersionsNuclio: All versions up to and including 1.15.19Component: Shell Runtime (`pkg/processor/runtime/shell`)The vulnerability exists in all versions that include the Shell Runtime component, as the vulnerable code pattern has been present since the feature's introduction.Patched VersionsNo patch is currently available. Users should implement workarounds until an official fix is released.WorkaroundsImmediate Mitigation (Choose One)**Option 1: Disable Shell Runtime**Add to Nuclio platform configuration:This completely disables the vulnerable component but breaks existing Shell Runtime functions.**Option 2: Restrict Function Deployment**Limit who can deploy functions using RBAC:Remove default function deployment permissions from untrusted users.**Option 3: Network Isolation**Restrict egress traffic from function pods:This limits the attacker's ability to exfiltrate data but doesn't prevent the initial exploitation.Long-Term Fixes**Fix 1: Input Validation**Implement strict validation in `getCommandArguments`:**Fix 2: Remove sh -c Execution**Use parameterized command execution:**Fix 3: Limit ServiceAccount Permissions**Create restricted ServiceAccount for function pods:ResourcesNuclio GitHub: https://github.com/nuclio/nuclioCWE-78: OS Command Injection: https://cwe.mitre.org/data/definitions/78.htmlOWASP Command Injection: https://owasp.org/www-community/attacks/Command_InjectionKubernetes Security Best Practices: https://kubernetes.io/docs/concepts/security/Creditscredit for:
@b0b0haha (603571786@qq.com)
@j311yl0v3u (2439839508@qq.com)
CVSS v4.0 score: 8.9