VAITP Dataset

← Back to the dataset

CVE-2012-4406

OpenStack Swift < 1.7.0: Remote code execution via crafted pickle metadata in memcached

  • CVSS 9.8
  • CWE-502
  • Input Validation and Sanitization
  • Remote

OpenStack Object Storage (swift) before 1.7.0 uses the loads function in the pickle Python module unsafely when storing and loading metadata in memcached, which allows remote attackers to execute arbitrary code via a crafted pickle object.

CVSS base score
9.8
Published
2012-10-22
OWASP
A08 Software and Data Integrity Failures
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Input Validation and Sanitization
Subcategory
Insecure Parsing or Deserialization
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Affected component
Python
Fixed by upgrading
Yes

Solution

Update OpenStack Object Storage (swift) to version 1.7.0 or higher.

Vulnerable code sample

import pickle

def load_metadata(metadata):
    # Using pickle.loads unsafely, which can lead to remote code execution
    return pickle.loads(metadata)

def save_metadata(metadata):
    # Using pickle.dumps to serialize the metadata
    return pickle.dumps(metadata)

# Example usage
metadata_to_save = {'key': 'value', 'another_key': 123}
serialized_metadata = save_metadata(metadata_to_save)

# This line is vulnerable to remote code execution if serialized_metadata is crafted
loaded_metadata = load_metadata(serialized_metadata)

print(loaded_metadata)

Patched code sample

import json

def safe_load_metadata(metadata):
    # Instead of using pickle.loads, we use json.loads for safety
    return json.loads(metadata)

def save_metadata(metadata):
    # Use json.dumps to serialize the metadata safely
    return json.dumps(metadata)

# Example usage
metadata_to_save = {'key': 'value', 'another_key': 123}
serialized_metadata = save_metadata(metadata_to_save)
loaded_metadata = safe_load_metadata(serialized_metadata)

print(loaded_metadata)

Published fix

Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.

Cite this entry

@misc{vaitp:cve20124406,
  title        = {{OpenStack Swift < 1.7.0: Remote code execution via crafted pickle metadata in memcached}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2012},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2012-4406},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2012-4406/}}
}

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.