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.
- CWE
- CWE-502
- 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 taggerPatched 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 modelPublished 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.
- Update version to 3.8.2, add release notes (nltk/nltk)
web/conf.py
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/}}
}
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 ::
