Skip to content
RCE Disclosed report Intermediate

Code Injection via Insecure Yaml.load

The Gubernator configuration loader uses the unsafe yaml.load() function, which can execute arbitrary code when parsing a malicious YAML file. An attacker who can supply or trick a victim into loading a crafted configuration file could run system commands.

r44mb00 Follow

Originally disclosed on HackerOne

Bounty$250incl. $150 bonus Low View original
  • Triaged in 5 days
  • Fixed in 53 days
  • Paid in 53 days
  • Disclosed after 5 months

Report Submission Form

Summary:

The Kubernetes repo and tool, test-infra, uses the insecure yaml.load() function to set or update the Gubernator configuration with a yaml file which allows for code injection. Vulnerable Line of Code: https://github.com/kubernetes/test-infra/blob/master/gubernator/main.py#L36 https://github.com/kubernetes/test-infra/blob/master/gubernator/update_config.py#L35 https://github.com/kubernetes/test-infra/blob/master/gubernator/update_config.py#L48
Vulnerable Files and functions: main.py:get_app_config() update_config.py:main()

Kubernetes Version:

Latest version: Master branch on Github

Component Version:

Latest version: Master branch on Github

Steps To Reproduce:

  1. Install the Gubernator frontend.
  2. save the provided config.yaml file as the configuration file for Guberator, keep the same name.
  3. Once you update the configuration the poc should be executed and a ls should be executed.

To Facilitate the process I have created a poc.py script in which I extracted the vulnerable code blocks from the test-infra repository to simulate the tools behaviour (Only from the main.py to illustrate the concept, same applies to the other occurence).

Steps to run the PoC:

  1. Save the poc.py script.
  2. Save the config.yaml file in the same folder as the script.
  3. Run the script using python3 poc.py.
  4. The command ls should be executed. Note that any other command can be executed.

Important Exploit Conditions:

The extent of the exploitability of this vulnerability is limited by the version of PyYaml that the victim has installed. For versions of PyYaml => 5.1 the only way to achieve command execution is to have Gubernator running embedded in a component that previously imports the subprocess module. For example Flask. For versions of PyYaml < 5.1 the vulnerability is always exploitable and command execution can always be achieved. Note that the former is always the case for the test-infra/Gubernator repo given that the requirements set PyYAML > 5.1. For this reason I have checked the Attack Complexity of the CVSS score as high. Exploitability is difficult but still possible in the worst case scenario.

Solution: As a possible solution I suggest changing the vulnerable and deprecated function for its secure equivalent, safe_load().

Supporting Material/References:

Details on the vulnerability and how to exploit in general can be found in this great article

  • poc.py: Python3 script with the proof of concept.
  • config.yaml: Payload file for the PoC.
  • evidence.png: Screenshot of the script ran on my local machine.

Impact

An attacker can exploit this vulnerability by crafting a malicious YAML file in order to execute system commands. An attacker can either find a way to load a malicious configuration file or entice a victim into loading it. This results in Command Execution. For this reason I have marked the User Interaction of the CVSS score as required.

Attachments

evidence.png
evidence.png From the original on HackerOne

The original report as published on HackerOne, by r44mb00. 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 application used PyYAML's unsafe load() function instead of safe_load(), allowing YAML tags to instantiate arbitrary Python objects and execute code.

Impact

An attacker could execute system commands if they can supply a malicious configuration file or entice a victim into loading one; however, with PyYAML 5.1 or later, command execution only works if the subprocess module was already imported by the host application, and the project requires PyYAML > 5.1, so exploitability is limited.

What the attacker needed

Ability to supply or load a malicious YAML config; PyYAML version and imports affect exploitability

The fix

The vulnerable yaml.load() function should be replaced with the safe equivalent, safe_load().

How it was found

  1. Install the Gubernator frontend.
  2. Save the provided config.yaml file as the configuration file for Gubernator, keeping the same name.
  3. Update the configuration, which should execute the proof-of-concept and run a directory listing command.

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 text format for configuration files. The Python library PyYAML has two ways to read YAML: a safe one and an unsafe one. The unsafe one can be tricked into running code hidden inside the file. This project used the unsafe one, so a malicious config file could run commands on the machine.

What is RCE?

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

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.