VAITP Dataset

← Back to the dataset

CVE-2024-3121

RCE via unsanitized env_name/python_version in create_conda_env (shell=True).

  • CVSS 3.3
  • CWE-78 Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
  • Input Validation and Sanitization
  • Remote

A remote code execution vulnerability exists in the create_conda_env function of the parisneo/lollms repository, version 5.9.0. The vulnerability arises from the use of shell=True in the subprocess.Popen function, which allows an attacker to inject arbitrary commands by manipulating the env_name and python_version parameters. This issue could lead to a serious security breach as demonstrated by the ability to execute the 'whoami' command among potentially other harmful commands.

CVSS base score
3.3
Published
2024-06-24
OWASP
A03 Injection
Orthogonal defect classification
Checking
Code defect classification
Incorrect Functionality
Category
Input Validation and Sanitization
Subcategory
Command Injection
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Affected component
Python

Solution

Upgrade the parisneo/lollms package to version 5.9.1 or later, which removes the shell=True usage in create_conda_env and sanitizes the env_name and python_version parameters.

Vulnerable code sample

import subprocess
import os

def create_conda_env(env_name: str, python_version: str) -> None:
    """
    Create a new conda environment with the given name and Python version.
    """
    # VULNERABLE: shell=True allows command injection via env_name or python_version
    cmd = f"conda create -y -n {env_name} python={python_version}"
    proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    out, err = proc.communicate()
    if proc.returncode != 0:
        raise RuntimeError(f"Conda env creation failed: {err.decode().strip()}")

Patched code sample

import subprocess
import os
import shlex

def create_conda_env(env_name: str, python_version: str) -> None:
    """
    Create a new conda environment with the given name and Python version.
    """
    # FIX: use a list and shlex.quote to avoid command injection
    cmd = ["conda", "create", "-y", "-n", env_name, f"python={python_version}"]
    proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    out, err = proc.communicate()
    if proc.returncode != 0:
        raise RuntimeError(f"Conda env creation failed: {err.decode().strip()}")

Cite this entry

@misc{vaitp:cve20243121,
  title        = {{RCE via unsanitized env_name/python_version in create_conda_env (shell=True).}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2024},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2024-3121},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2024-3121/}}
}

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.