VAITP Dataset

← Back to the dataset

CVE-2024-55587

Python-libarchive < 4.2.2 allows directory traversal via ZipFile.extract* in zip.py.

  • CVSS 8.8
  • CWE-22
  • Design Defects
  • Remote

python-libarchive through 4.2.1 allows directory traversal (to create files) in extract in zip.py for ZipFile.extractall and ZipFile.extract.

CVSS base score
8.8
Published
2024-12-11
OWASP
A04 Insecure Design
Orthogonal defect classification
Interface
Code defect classification
Incorrect Functionality
Category
Design Defects
Subcategory
Path Traversal
Accessibility scope
Remote
Impact
Unauthorized Access
Affected component
python-libar
Fixed by upgrading
Yes

Solution

Upgrade to python-libarchive 4.2.2 or later.

Vulnerable code sample

import zipfile
import os

def extract_zip(zip_filepath, extract_dir):
    try:
        with zipfile.ZipFile(zip_filepath, 'r') as zf:
            zf.extractall(extract_dir) 
    except zipfile.BadZipFile:
        print("Invalid zip file.")
    except Exception as e:
        print(f"An error occurred: {e}")

Patched code sample

import os
import zipfile

def extract_zip(zip_file_path, extract_dir):
    
    try:
        with zipfile.ZipFile(zip_file_path, 'r') as zf:
            for member in zf.infolist():
                target_path = os.path.join(extract_dir, os.path.basename(member.filename))
                if not os.path.abspath(target_path).startswith(os.path.abspath(extract_dir)):
                    raise ValueError("Path traversal detected!")

                zf.extract(member, extract_dir) 
    except zipfile.BadZipFile:
        print("Invalid or corrupt zip file.")
    except ValueError as e:
        print(f"Error: {e}")

Payload

import zipfile
from zipfile import ZipFile

z = ZipFile('malicious.zip', 'w')
z.writestr('../etc/passwd', 'test')
z.close()

Cite this entry

@misc{vaitp:cve202455587,
  title        = {{Python-libarchive < 4.2.2 allows directory traversal via ZipFile.extract* in zip.py.
}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2024},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2024-55587},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2024-55587/}}
}
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 ::