VAITP Dataset

← Back to the dataset

CVE-2024-39705

NLTK 3.8.1 RCE via untrusted pickled code in data package downloads.

  • CVSS 9.8
  • CWE-502
  • Input Validation and Sanitization
  • Remote

NLTK through 3.8.1 allows remote code execution if untrusted packages have pickled Python code, and the integrated data package download functionality is used. This affects, for example, averaged_perceptron_tagger and punkt.

CVSS base score
9.8
Published
2024-06-27
OWASP
A01 Broken Access Control
Orthogonal defect classification
Checking
Code defect classification
Incorrect Check
Category
Input Validation and Sanitization
Subcategory
Insecure Parsing or Deserialization
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Affected component
NLTK
Fixed by upgrading
Yes

Solution

Upgrade NLTK to version 3.8.2 or later.

Vulnerable code sample

import nltk

def load_tagger():
    # VULNERABLE: loads untrusted pickled model
    tagger = nltk.data.load('taggers/averaged_perceptron_tagger.pickle')
    return tagger

Patched code sample

import nltk
import io

def load_tagger():
    # FIX: load model as raw bytes and deserialize safely
    raw = nltk.data.load('taggers/averaged_perceptron_tagger.pickle', format='raw')
    # safe deserialization without pickle
    with io.BytesIO(raw) as f:
        import json
        model = json.load(f)
    return model

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.

Payload

import pickle
import os

# Example payload that could execute arbitrary code
payload = pickle.dumps(os.system('echo Vulnerability Exploited!'))

# This payload could be saved and then loaded by the vulnerable NLTK function

Cite this entry

@misc{vaitp:cve202439705,
  title        = {{NLTK 3.8.1 RCE via untrusted pickled code in data package downloads.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2024},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2024-39705},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2024-39705/}}
}

Download this entry as JSON Download the whole dataset

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 ::

Before you use the VAITP AI models

Please read and accept the following disclaimer:

By choosing "I understand and accept", you acknowledge that you understand and agree to these terms.