Cloudanix VulnDB

CVE-2024-39705

Critical · 9.8

CVSS

9.8

EPSS

1.3%

Published

Jun 27, 2024

CISA due date

—

Cloudanix analysis

Next patch cycle SSVC: Track

A flaw in a popular software component for processing human language could allow an attacker to take complete control of the application if it downloads data from the internet.

Exploitation
Remote Unauthenticated
Attacker needs
None
Complexity
Low
Impact
Remote Code Execution
Component
Library
Class
Deserialization
Remediation
Upgrade
Effort
Medium
Patch risk
Low

What it actually does

The vulnerability allows for arbitrary code execution due to insecure deserialization. The NLTK library uses Python's 'pickle' module to load certain data packages. If an attacker can provide a malicious package (e.g., via a Man-in-the-Middle attack on the download process), the unpickling process will execute any Python code embedded within the malicious package. This code runs with the full permissions of the application process, leading to Remote Code Execution (RCE).

Why it matters to the business

An attacker can gain complete control over any application or server using a vulnerable version of this software component. This could lead to theft of sensitive data, disruption of services, financial loss, and reputational damage. The compromised system could also be used as a pivot point to attack other internal systems, escalating the breach's impact across the organization.

How an attack unfolds

An attacker first identifies an application using a vulnerable version of NLTK that is configured to download data packages from the internet at runtime. The attacker then intercepts the application's download request, typically through a Man-in-the-Middle (MITM) attack or by compromising a data package mirror. They replace the legitimate data package (e.g., 'punkt' or 'averaged_perceptron_tagger') with a malicious one containing a specially crafted pickled object. When the NLTK library in the victim's application loads this malicious package, the embedded code is executed, giving the attacker control over the server.

How to fix it

Upgrade the NLTK library to a version higher than 3.8.1. The vulnerability was addressed in subsequent releases. If an immediate upgrade is not feasible, a temporary mitigation is to prevent the application from downloading NLTK packages at runtime. Instead, pre-download the required packages from a trusted source and bundle them with the application deployment. Additionally, implement strict network egress filtering to block outbound connections from the application server to unknown NLTK data mirrors.

How to confirm the fix worked

To confirm remediation, verify that the NLTK library has been upgraded in all relevant environments. Check dependency files (e.g., `requirements.txt`, `Pipfile.lock`, `poetry.lock`) and the installed packages in your virtual environments to ensure no instances of NLTK version 3.8.1 or older remain. To identify exposure, scan your codebase and deployed applications for usage of the `nltk.download()` function, as this is the primary entry point for the vulnerability.

Typical attack path

  1. An attacker identifies a target application using NLTK version 3.8.1 or earlier.
  2. The attacker positions themselves to intercept the application's network traffic, for example, via DNS or BGP hijacking.
  3. The application makes a call to download an NLTK data package, such as `nltk.download('punkt')`.
  4. The attacker intercepts this download request and serves a malicious data package containing a pickled payload.
  5. The NLTK library deserializes the malicious package, triggering the execution of the attacker's code.
  6. The attacker achieves remote code execution on the server, establishing a foothold for further activities.

How to detect it

Detecting exploitation requires monitoring for post-compromise behavior on the host system. Look for Python processes that spawn unexpected child processes, such as shells (`/bin/sh`, `powershell.exe`) or network utilities (`curl`, `wget`). Monitor for anomalous outbound network connections from application servers to unknown IP addresses or domains. Analyze web server and application logs for requests related to NLTK package downloads that correlate with system alerts or unusual activity. Since the initial exploit vector is often encrypted (HTTPS), network-level detection of the payload itself is unreliable; focus on host-based behavioral indicators.

What your security team should do

  • Prioritize patching all applications using the NLTK library to a version later than 3.8.1, focusing on internet-facing systems first.
  • Conduct a comprehensive scan of all software assets, including source code repositories and container images, to identify all instances of the vulnerable library.
  • If patching is delayed, implement network egress controls to restrict the application's ability to download packages from the internet at runtime.
  • Review application and network logs for any unusual download activities or unexpected processes spawned by Python applications, which could indicate a past compromise.

The record

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.

Affected packages

Ecosystem Package Introduced Fixed
PyPI nltk 0 3.9
Chainguard apache-beam-python-3.11-sdk 0 2.58.1-r0
Chainguard nemo 0 1.23.0-r12
Chainguard py3-nltk 0 3.8.2-r0
Chainguard py3-supported-nltk 0 3.8.2-r0
Chainguard py3.10-nltk 0 3.8.2-r0
Chainguard py3.10-nltk-bin 0 3.8.2-r0
Chainguard py3.11-nltk 0 3.8.2-r0
Chainguard py3.11-nltk-bin 0 3.8.2-r0
Chainguard py3.12-nltk 0 3.8.2-r0
Chainguard py3.12-nltk-bin 0 3.8.2-r0
Chainguard py3.13-nltk 0 3.8.2-r0
Chainguard py3.13-nltk-bin 0 3.8.2-r0
Debian:11 nltk 0 No fix
Debian:12 nltk 0 No fix
Debian:13 nltk 0 No fix
SUSE:Package Hub 15 SP5 python-nltk 0 3.7-bp155.3.3.1
SUSE:Package Hub 15 SP6 python-nltk 0 3.7-bp156.4.3.1
Ubuntu:20.04:LTS nltk 0 No fix
Ubuntu:22.04:LTS nltk 0 No fix
Ubuntu:24.04:LTS nltk 0 No fix
Ubuntu:24.10 nltk 0 No fix
Ubuntu:Pro:14.04:LTS nltk 0 No fix
Ubuntu:Pro:16.04:LTS nltk 0 No fix
Ubuntu:Pro:18.04:LTS nltk 0 No fix
Ubuntu:Pro:20.04:LTS nltk 0 No fix
Wolfi py3-nltk 0 3.8.2-r0
Wolfi py3-supported-nltk 0 3.8.2-r0
Wolfi py3.10-nltk 0 3.8.2-r0
Wolfi py3.10-nltk-bin 0 3.8.2-r0
Wolfi py3.11-nltk 0 3.8.2-r0
Wolfi py3.11-nltk-bin 0 3.8.2-r0
Wolfi py3.12-nltk 0 3.8.2-r0
Wolfi py3.12-nltk-bin 0 3.8.2-r0
Wolfi py3.13-nltk 0 3.8.2-r0
Wolfi py3.13-nltk-bin 0 3.8.2-r0
openSUSE:Leap 15.5 python-nltk 0 3.7-bp155.3.3.1
openSUSE:Leap 15.6 python-nltk 0 3.7-bp156.4.3.1
openSUSE:Tumbleweed python-nltk 0 3.8.1-2.1

Related vulnerabilities