CVE-2015-1326
Python-dbusmock < 0.15.1 allowed malicious code execution via .pyc file in AddTemplate or spawn_server_template
- CVSS 8.8
- CWE-20 Improper Input Validation
- Input Validation and Sanitization
- Local
python-dbusmock before version 0.15.1 AddTemplate() D-Bus method call or DBusTestCase.spawn_server_template() method could be tricked into executing malicious code if an attacker supplies a .pyc file.
- CVSS base score
- 8.8
- Published
- 2019-04-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
- Local
- Impact
- Arbitrary Code Execution
- Affected component
- python-dbusmock
- Fixed by upgrading
- Yes
Solution
Update python-dbusmock to version 0.15.1 or higher.
Vulnerable code sample
import os
class DBusTestCase:
def spawn_server_template(self, template_name):
# This method could be tricked into executing a .pyc file
# by directly executing the compiled Python file.
template_path = f"{template_name}.pyc"
if os.path.exists(template_path):
exec(open(template_path).read())
# Example usage
test_case = DBusTestCase()
test_case.spawn_server_template("malicious_template") # Potentially unsafePatched code sample
import os
import sys
import importlib.util
def safe_import(module_name):
# Ensure that the module name does not contain any illegal characters
if not module_name.isidentifier():
raise ValueError("Invalid module name")
# Define the path to the module
module_path = f"{module_name}.py"
# Load the module safely
if os.path.exists(module_path):
spec = importlib.util.spec_from_file_location(module_name, module_path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
else:
raise FileNotFoundError(f"{module_path} does not exist")
# Example usage
try:
# This should only allow safe modules to be imported
my_module = safe_import("my_safe_module")
except Exception as e:
print(f"Error: {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.
- SECURITY FIX: Prevent code execution through crafted pyc files (martinpitt/python-dbusmock)
dbusmock/mockobject.py,dbusmock/mockobject.py · load_module
Cite this entry
@misc{vaitp:cve20151326,
title = {{Python-dbusmock < 0.15.1 allowed malicious code execution via .pyc file in AddTemplate or spawn_server_template}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2019},
note = {VAITP Python Vulnerability Dataset, entry CVE-2015-1326},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2015-1326/}}
}
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 ::
