VAITP Dataset

← Back to the dataset

CVE-2024-0450

CPython zipfile module vulnerable to quoted-overlap zip-bombs.

  • CVSS 6.2
  • CWE-405
  • Input Validation and Sanitization
  • Remote

An issue was found in the CPython `zipfile` module affecting versions 3.12.1, 3.11.7, 3.10.13, 3.9.18, and 3.8.18 and prior. The zipfile module is vulnerable to “quoted-overlap” zip-bombs which exploit the zip format to create a zip-bomb with a high compression ratio. The fixed versions of CPython makes the zipfile module reject zip archives which overlap entries in the archive.

CVSS base score
6.2
Published
2024-03-19
OWASP
A06 Security Misconfiguration
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Input Validation and Sanitization
Subcategory
Insecure Parsing or Deserialization
Accessibility scope
Remote
Impact
Denial of Service (DoS)
Affected component
Python `zipf
Fixed by upgrading
Yes

Solution

Upgrade to CPython version 3.12.2 or later.

Vulnerable code sample

import zipfile
import io

with zipfile.ZipFile('example.zip', 'w') as zf:
    zf.writestr('file1.txt', b'A' * (10**6)) 
    zf.writestr('file2.txt', b'B' * (10**6)) 

with zipfile.ZipFile('example.zip', 'r') as zf:
    print(zf.namelist())
    zf.extractall('extracted_files')

Patched code sample

import zipfile
import os

with zipfile.ZipFile('example.zip', 'w') as zf:
    zf.writestr('file1.txt', b'A' * (10**6)) 
    zf.writestr('file2.txt', b'B' * (10**6)) 

def extract(zip_file, extract_to):
    with zipfile.ZipFile(zip_file, 'r') as zf:
        for file_name in zf.namelist():
            if os.path.commonprefix([os.path.abspath(file_name), os.path.abspath(extract_to)]) != os.path.abspath(extract_to):
                print(f"Suspicious file detected: {file_name}")
                return
        zf.extractall(extract_to)

extract('example.zip', 'extracted_files')

Payload

import zipfile

# Create a zip bomb payload with overlapping entries
with zipfile.ZipFile('exploit.zip', 'w') as zf:
    zf.writestr('file1.txt', b'A' * (10**6))  # 1 MB file
    zf.writestr('file2.txt', b'B' * (10**6))  # 1 MB file
    # Overlapping entry to exploit the vulnerability
    zf.writestr('file1.txt', b'A' * (10**6))  # Overlapping entry

Cite this entry

@misc{vaitp:cve20240450,
  title        = {{CPython zipfile module vulnerable to quoted-overlap zip-bombs.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2024},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2024-0450},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2024-0450/}}
}
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 ::