CVE-2013-1630
Pyshop <0.7.1 allows code execution via insecure HTTP package downloads
- CVSS 6.8
- CWE-20 Improper Input Validation
- Cryptographic
- Remote
pyshop before 0.7.1 uses HTTP to retrieve packages from the PyPI repository, and does not perform integrity checks on package contents, which allows man-in-the-middle attackers to execute arbitrary code via a crafted response to a download operation.
- CVSS base score
- 6.8
- Published
- 2013-08-06
- OWASP
- A08 Software and Data Integrity Failures
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Cryptographic
- Subcategory
- Improper SSL/TLS Certificate Validation
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Affected component
- pyshop
- Fixed by upgrading
- Yes
Solution
Update pyshop to version 0.7.1 or higher.
Vulnerable code sample
import requests
def download_package(package_name):
url = f"http://pypi.python.org/packages/source/{package_name}/{package_name}.tar.gz"
# Use HTTP to download the package (vulnerable to man-in-the-middle attacks)
response = requests.get(url)
# Save the package without any integrity checks
if response.status_code == 200:
with open(f"{package_name}.tar.gz", "wb") as f:
f.write(response.content)
print(f"{package_name} downloaded successfully.")
else:
print("Failed to download the package.")
# Example usage
download_package('example_package')Patched code sample
import requests
import hashlib
def download_package(package_name, expected_hash):
url = f"https://pypi.python.org/packages/source/{package_name}/{package_name}.tar.gz"
# Use HTTPS to securely download the package
response = requests.get(url, stream=True)
# Check if the request was successful
if response.status_code == 200:
# Calculate the hash of the downloaded content
sha256_hash = hashlib.sha256()
for chunk in response.iter_content(chunk_size=8192):
sha256_hash.update(chunk)
# Verify the integrity of the package
if sha256_hash.hexdigest() == expected_hash:
with open(f"{package_name}.tar.gz", "wb") as f:
f.write(response.content)
print(f"{package_name} downloaded and verified successfully.")
else:
print("Integrity check failed: The package may have been tampered with.")
else:
print("Failed to download the package.")
# Example usage
# Replace 'expected_hash_value' with the actual SHA256 hash of the package
download_package('example_package', 'expected_hash_value')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.
- Improve security when downloading from pypi (mardiros/pyshop)
pyshop/helpers/download.py,pyshop/views/repository.py · get_release_file
Cite this entry
@misc{vaitp:cve20131630,
title = {{Pyshop <0.7.1 allows code execution via insecure HTTP package downloads}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2013},
note = {VAITP Python Vulnerability Dataset, entry CVE-2013-1630},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2013-1630/}}
}
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 ::
