CVE-2022-43305
PyPI d8s-python package v0.1.0 had a backdoor via democritus-grammars
- CVSS 9.8
- CWE-434 Unrestricted Upload of File with Dangerous Type
- Design Defects
- Remote
The d8s-python for python, as distributed on PyPI, included a potential code-execution backdoor inserted by a third party. A potential code execution backdoor inserted by third parties is the democritus-algorithms package. The affected version of d8s-htm is 0.1.0.
- CVSS base score
- 9.8
- Published
- 2022-11-07
- OWASP
- A06 Vulnerable and Outdated Components
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Design Defects
- Subcategory
- Vulnerable and Outdated Components
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Fixed by upgrading
- Yes
Solution
Update d8s-python to version 0.1.1 or higher.
Vulnerable code sample
import os
def read_file(filename):
# VULNERABLE: Direct file access without validation
# Allows path traversal attacks
try:
with open(filename, 'r') as f:
return f.read()
except Exception as e:
return f"Error: {e}"
# Example of vulnerable usage:
# content = read_file("../../../etc/passwd") # Path traversal attack!Patched code sample
import os
from pathlib import Path
def read_file(filename):
# SECURE: Validate file paths and restrict access
# Define allowed directory
ALLOWED_DIR = "/var/app/files"
try:
# Resolve paths to prevent traversal
allowed_path = Path(ALLOWED_DIR).resolve()
requested_path = Path(os.path.join(ALLOWED_DIR, filename)).resolve()
# Ensure the requested path is within allowed directory
if not str(requested_path).startswith(str(allowed_path)):
raise ValueError("Path traversal attempt detected")
# Additional security checks
if not requested_path.exists():
raise FileNotFoundError("File not found")
if not requested_path.is_file():
raise ValueError("Not a regular file")
# Check file permissions
if not os.access(requested_path, os.R_OK):
raise PermissionError("File not readable")
with open(requested_path, 'r', encoding='utf-8') as f:
return f.read()
except (ValueError, FileNotFoundError, PermissionError) as e:
return f"Error: {str(e)}"
# Example of secure usage:
# content = read_file("document.txt") # Safe file access
# content = read_file("data/report.txt") # Within allowed directoryCite this entry
@misc{vaitp:cve202243305,
title = {{PyPI d8s-python package v0.1.0 had a backdoor via democritus-grammars}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2022},
note = {VAITP Python Vulnerability Dataset, entry CVE-2022-43305},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2022-43305/}}
}
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 ::
