CVE-2017-2809
Ansible-vault (before 1.0.5) allows arbitrary Python command execution via crafted YAML vaults
- CVSS 7.8
- CWE-94 Improper Control of Generation of Code ('Code Injection')
- Input Validation and Sanitization
- Local
An exploitable vulnerability exists in the yaml loading functionality of ansible-vault before 1.0.5. A specially crafted vault can execute arbitrary python commands resulting in command execution. An attacker can insert python into the vault to trigger this vulnerability.
- CVSS base score
- 7.8
- Published
- 2017-09-14
- OWASP
- A03 Injection
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Input Validation and Sanitization
- Subcategory
- Insecure Parsing or Deserialization
- Accessibility scope
- Local
- Impact
- Arbitrary Code Execution
- Affected component
- ansible-vault
- Fixed by upgrading
- Yes
Solution
Update ansible-vault to version 1.0.5 or higher.
Vulnerable code sample
import yaml
# Vulnerable loader that allows execution of arbitrary Python commands
def vulnerable_load_yaml(vault_content):
return yaml.load(vault_content, Loader=yaml.FullLoader)
# Example usage
vault_content = """
my_secret: !!python/object/apply:os.system ['echo vulnerable']
"""
# Load the vault content unsafely
data = vulnerable_load_yaml(vault_content)
print(data)Patched code sample
import yaml
# Safe loader to prevent execution of arbitrary Python commands
def safe_load_yaml(vault_content):
return yaml.safe_load(vault_content)
# Example usage
vault_content = """
my_secret: !!python/object/apply:os.system ['echo vulnerable']
"""
# Load the vault content safely
try:
data = safe_load_yaml(vault_content)
print(data)
except Exception as e:
print(f"Error loading vault content: {e}")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.
- Fix security issue refs #4 (tomoh1r/ansible-vault)
ansible_vault/api.py · Vault.load,setup.py
Cite this entry
@misc{vaitp:cve20172809,
title = {{Ansible-vault (before 1.0.5) allows arbitrary Python command execution via crafted YAML vaults}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2017},
note = {VAITP Python Vulnerability Dataset, entry CVE-2017-2809},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2017-2809/}}
}
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 ::
