VAITP Dataset

← Back to the dataset

CVE-2018-6012

Python code injection via 'Add new weather data source' upload function in Green Electronics RainMachine Mini-8 (2nd generation)

  • CVSS 9.8
  • CWE-94 Improper Control of Generation of Code ('Code Injection')
  • Input Validation and Sanitization
  • Remote

The 'Weather Service' feature of the Green Electronics RainMachine Mini-8 (2nd generation) allows an attacker to inject arbitrary Python code via the 'Add new weather data source' upload function.

CVSS base score
9.8
Published
2018-11-01
OWASP
A03 Injection
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Input Validation and Sanitization
Subcategory
Command Injection
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Affected component
Python
Fixed by upgrading
Yes

Solution

Update RainMachine Mini-8 (2nd generation) firmware to the latest version with the security patch.

Vulnerable code sample

import json

# Function to handle the upload of a new weather data source
def add_new_weather_data_source(data_source_json):
    # Directly executing the input without validation
    data_source = json.loads(data_source_json)
    
    # Arbitrary code execution vulnerability
    exec(data_source.get('python_code', ''))

    print("Weather data source added successfully.")
    # Here you would add logic to save the data source

# Example usage
data_source_json = '{"python_code": "__import__(\'os\').system(\'ls\')"}'
add_new_weather_data_source(data_source_json)

Patched code sample

import os
import json
import re

# Function to validate and sanitize the uploaded weather data source
def validate_weather_data_source(data_source):
    # Allow only specific keys and types to prevent arbitrary code execution
    allowed_keys = {'name', 'url', 'api_key'}
    if not all(key in allowed_keys for key in data_source.keys()):
        raise ValueError("Invalid data source keys.")

    # Example of validating URL format
    url_pattern = re.compile(r'^(http|https)://[^\s/$.?#].[^\s]*$')
    if not url_pattern.match(data_source['url']):
        raise ValueError("Invalid URL format.")

    # Ensure no executable code is present in the input
    for key, value in data_source.items():
        if isinstance(value, str):
            if re.search(r'[\(\)\{\}\[\];]', value):
                raise ValueError("Invalid characters in input.")

    return True

# Function to handle the upload of a new weather data source
def add_new_weather_data_source(data_source_json):
    try:
        data_source = json.loads(data_source_json)
        if validate_weather_data_source(data_source):
            # Proceed with adding the validated data source
            print("Weather data source added successfully.")
            # Here you would add logic to save the data source
    except ValueError as e:
        print(f"Error: {e}")

# Example usage
data_source_json = '{"

Cite this entry

@misc{vaitp:cve20186012,
  title        = {{Python code injection via 'Add new weather data source' upload function in Green Electronics RainMachine Mini-8 (2nd generation)}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2018},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2018-6012},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2018-6012/}}
}

Download this entry as JSON Download the whole dataset

Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::

Before you use the VAITP AI models

Please read and accept the following disclaimer:

By choosing "I understand and accept", you acknowledge that you understand and agree to these terms.